Skip to content
Permalink
Browse files

Reworked mocking

  • Loading branch information...
Alex Stockinger
Alex Stockinger committed Aug 10, 2017
1 parent 7e75549 commit 5df080fbc69426ae913688f76380dbc64a40be3f
Showing with 585 additions and 473 deletions.
  1. +12 −27 common/src/main/java/fi/testee/utils/ReflectionUtils.java
  2. +6 −7 core-spi/src/main/java/fi/testee/spi/{BeanModifierFactory.java → SessionBeanAlternatives.java}
  3. +0 −48 core-spi/src/main/java/fi/testee/spi/base/AbstractBaseBeanReplacer.java
  4. +0 −171 core-spi/src/main/java/fi/testee/spi/base/BeanReplacementManager.java
  5. +19 −6 core/src/main/java/fi/testee/deployment/BeanArchive.java
  6. +0 −4 core/src/main/java/fi/testee/deployment/BeanArchiveDiscovery.java
  7. +3 −0 core/src/main/java/fi/testee/deployment/BeanDeploymentArchiveImpl.java
  8. +0 −58 core/src/main/java/fi/testee/deployment/BeanDeploymentArchiveManagement.java
  9. +9 −8 core/src/main/java/fi/testee/deployment/DeploymentImpl.java
  10. +7 −8 core/src/main/java/fi/testee/ejb/EjbContainer.java
  11. +14 −8 core/src/main/java/fi/testee/runtime/DependencyInjectionRealm.java
  12. +30 −33 core/src/main/java/fi/testee/runtime/TestInstanceRealm.java
  13. +3 −1 core/src/main/java/fi/testee/runtime/TestRuntime.java
  14. +14 −3 core/src/main/java/fi/testee/runtime/TestSetup.java
  15. +45 −12 core/src/main/java/fi/testee/runtime/TransactionalContext.java
  16. +20 −7 core/src/main/java/fi/testee/services/EjbInjectionServicesImpl.java
  17. 0 core/src/main/resources/META-INF/testee.fi
  18. +1 −1 core/src/test/java/fi/testee/DependencyInjectionTest.java
  19. 0 core/src/test/resources/META-INF/testee.fi
  20. 0 cucumber/src/main/resources/META-INF/testee.fi
  21. +1 −0 easymock/build.gradle
  22. +9 −15 easymock/src/main/java/fi/testee/easymock/{EasyMockBeanModifier.java → EasyMockContributor.java}
  23. 0 easymock/src/main/resources/META-INF/testee.fi
  24. 0 eclipselink/src/main/resources/META-INF/testee.fi
  25. 0 flyway/src/main/resources/META-INF/testee.fi
  26. 0 h2/src/main/resources/META-INF/testee.fi
  27. 0 liquibase/src/main/resources/META-INF/testee.fi
  28. +1 −0 mockito/build.gradle
  29. +9 −17 mockito/src/main/java/fi/testee/mockito/{MockitoBeanModifier.java → MockitoMockContributor.java}
  30. 0 mockito/src/main/resources/META-INF/testee.fi
  31. +55 −2 mockito/src/test/java/fi/testee/mockito/InjectMockTest.java
  32. 0 postgres/src/main/resources/META-INF/testee.fi
  33. 0 rest/src/main/resources/META-INF/testee.fi
  34. +2 −1 settings.gradle
  35. +7 −0 util-mockingbase/build.gradle
  36. +45 −0 util-mockingbase/src/main/java/fi/testee/mocking/MockSessionBeanAlternatives.java
  37. +67 −0 util-mockingbase/src/main/java/fi/testee/mocking/MockStore.java
  38. +10 −13 ...k/EasyMockBeanModifierFactory.java → util-mockingbase/src/main/java/fi/testee/mocking/Mocked.java
  39. +124 −0 util-mockingbase/src/main/java/fi/testee/mocking/MockingExtension.java
  40. +12 −11 ...ifierFactory.java → util-mockingbase/src/main/java/fi/testee/mocking/MockingExtensionFactory.java
  41. +54 −0 util-mockingbase/src/main/java/fi/testee/mocking/spi/AbstractBaseMockContributor.java
  42. +5 −11 ...spi/BeanModifier.java → util-mockingbase/src/main/java/fi/testee/mocking/spi/MockContributor.java
  43. 0 util-mockingbase/src/main/resources/META-INF/beans.xml
  44. 0 util-mockingbase/src/main/resources/META-INF/testee.fi
  45. +1 −1 util-nopostconstruct/src/main/java/fi/testee/util/nopostconstruct/ExtensionFactory.java
  46. 0 util-nopostconstruct/src/main/resources/META-INF/testee.fi
  47. 0 util-resourcedef/src/main/resources/META-INF/testee.fi
@@ -19,43 +19,28 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.Set;

import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang3.reflect.FieldUtils.getAllFieldsList;
import java.util.function.Predicate;

public final class ReflectionUtils {
private ReflectionUtils() {
}

public static Collection<Object> valuesOf(final Object instance, final Collection<Field> fields) {
return fields.stream()
.map(it -> {
it.setAccessible(true);
try {
return it.get(instance);
} catch (final IllegalAccessException e) {
throw new TestEEfiException("Could not extract field value from " + instance, e);
}
}).collect(toSet());
}

public static Collection<Object> fieldsValuesAnnotatedWith(
final Object o,
final Class<? extends Annotation>... annotations
) {
final Set<Field> fields = AnnotationUtils.groupByAnnotation(getAllFieldsList(o.getClass()), annotations).values().stream()
.flatMap(Collection::stream)
.collect(toSet());
return valuesOf(o, fields);
}

public static <T> T create(final Class<T> clazz) {
try {
return clazz.newInstance();
} catch (final InstantiationException | IllegalAccessException e) {
throw new TestEEfiException("Failed to instantiate " + clazz);
}
}

public static Predicate<? super Field> hasAnnotation(final Class<? extends Annotation>... annotations) {
return field -> {
for (final Class<? extends Annotation> annotation : annotations) {
if (field.getAnnotation(annotation) != null) {
return true;
}
}
return false;
};
}
}
@@ -15,11 +15,10 @@
*/
package fi.testee.spi;

/**
* Factory for {@link BeanModifier}.
*
* @author Alex Stockinger, IT-Stockinger
*/
public interface BeanModifierFactory {
BeanModifier createBeanModifier(Object testClassInstance);
import org.jboss.weld.injection.spi.ResourceReferenceFactory;

import java.lang.reflect.Type;

public interface SessionBeanAlternatives {
ResourceReferenceFactory<Object> alternativeFor(Type type);
}

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.
@@ -66,20 +66,33 @@ public JavaArchive getClasspathEntry() {
}

public boolean isRelevant() {
return hasBeansXml() || hasCdiExtension() || isEjbArchive() || hasAdditionalQualification();
return hasBeansXml() || isEjbArchive() || hasAdditionalQualification() || isWeldCore();
}

private boolean isWeldCore() {
// TODO not very pretty
return has("org/jboss/weld/bootstrap/WeldExtension.class");
}

public boolean isFrameworkRelevant() {
return hasTesteefiMarker() || isWeldCore();
}

private boolean hasTesteefiMarker() {
return has("META-INF/testee.fi");
}

private boolean has(String filename) {
return getClasspathEntry().findResource(filename) != null;
}

@SuppressWarnings("unchecked")
private boolean hasAdditionalQualification() {
return !classpathEntry.annotatedWith(qualifyingAnnotations.toArray(new Class[]{})).isEmpty();
}

private boolean hasCdiExtension() {
return getClasspathEntry().findResource("META-INF/services/javax.enterprise.inject.spi.CDIProvider") != null;
}

private boolean hasBeansXml() {
return getClasspathEntry().findResource("META-INF/beans.xml") != null;
return has("META-INF/beans.xml");
}

@Override
@@ -73,10 +73,6 @@ public BeanArchiveDiscovery() {
return ret;
}

public Set<EjbDescriptorImpl<?>> getSessionBeans() {
return beanArchives.stream().map(BeanArchive::getEjbs).flatMap(Collection::stream).collect(toSet());
}

public Collection<Class<?>> getClassesWith(final Class<? extends Annotation> annotation) {
return beanArchives.stream()
.map(it -> it.getClassesWith(annotation))
@@ -139,4 +139,7 @@ public String getId() {
return beanArchive.getClasspathEntry().getURL().toExternalForm();
}

public BeanArchive getBeanArchive() {
return beanArchive;
}
}
Oops, something went wrong.

0 comments on commit 5df080f

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