Skip to content
Permalink
Browse files

Fixed issue when injecting EJBs with @ejb via one of theis interfaces

  • Loading branch information...
Alex Stockinger
Alex Stockinger committed Aug 11, 2017
1 parent 9d6431c commit dea919582aab6a1dcd52005f03b2227674427ea4
@@ -2,6 +2,7 @@ Version 0.5.0
- Fixed issue with mocks for interfaces that are not in bean archives
- Fixed issue when @Injecting session beans via non-annotated interfaces
- Fixed injection of EJBs in base classes of EJBs
- Fixed issue when injecting EJBs with @EJB via one of theis interfaces
- Vastly improved mocking

Version 0.4.3
@@ -19,6 +19,7 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Type;
import java.util.function.Predicate;

public final class ReflectionUtils {
@@ -48,6 +48,7 @@
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toMap;
import static java.util.stream.Collectors.toSet;
import static org.jboss.weld.resolution.CovariantTypes.isAssignableFrom;

/**
* Bridge between CDI and EJB dependency injection.
@@ -200,7 +201,12 @@ private void inject(final Object o, final Field field, final Object instanceToIn
}

public EjbDescriptor<?> lookupDescriptor(final Type type) {
return ejbDescriptors.get(type);
for (final Map.Entry<Type, EjbDescriptorImpl<?>> e : ejbDescriptors.entrySet()) {
if(isAssignableFrom(type, e.getKey())) {
return e.getValue();
}
}
return null;
}

@SuppressWarnings("unchecked")
@@ -98,10 +98,6 @@
private DependencyInjectionRealm realm;
private EjbContainer ejbContainer;

public TransactionalContext() {
LOG.info("New transactional context");
}

public void initialize(
final Collection<Metadata<Extension>> extensions,
final BeansXmlModifier beansXmlModifier,
@@ -92,7 +92,17 @@ public void ejbIface_in_root_via_inject() {
}, () -> {
ensureInterception(ExampleBean1.class, null, PRE_DESTROY);
});
}

@Test
public void ejbIface_in_root_via_ejb() {
runTest(() -> {
assertEquals("Hello, world", root.ejbIfaceViaInject.test());
ensureInterception(ExampleBean1.class, null, POST_CONSTRUCT); // TODO can't this happen lazily?
ensureInterception(SessionBean1.class, "test", AROUND_INVOKE);
}, () -> {
ensureInterception(ExampleBean1.class, null, PRE_DESTROY);
});
}

@Test
@@ -248,6 +258,8 @@ public DataSource getResourceInRoot() {
private BeanArchiveDiscovery beanFromDifferentArchive;
@Inject
private SessionBeanInterface ejbIfaceViaInject;
@EJB
private SessionBeanInterface ejbIfaceViaEjb;

public ExampleBean1 getCdiInRootViaInject() {
return cdiInRootViaInject;
@@ -31,6 +31,7 @@
import java.util.function.BiConsumer;

import static java.util.stream.Collectors.toSet;
import static org.jboss.weld.resolution.CovariantTypes.isAssignableFrom;

@Singleton
public class MockStore {
@@ -56,14 +57,9 @@ public void forEachType(final Collection<Type> types, final BiConsumer<? super F
}

private Map.Entry<Field, Object> findEntryFor(final Type type) {
if (!(type instanceof Class)) {
// TODO handle more cases
return null;
}
final Class<?> clazz = (Class<?>) type;
for (final Map.Entry<Field, Object> e : mocks.entrySet()) {
// TODO handle ambiguous mocks
if (clazz.isAssignableFrom(e.getValue().getClass())) {
if (isAssignableFrom(type, e.getValue().getClass())) {
return e;
}
}

0 comments on commit dea9195

Please sign in to comment.
You can’t perform that action at this time.