io.micronaut.test.annotation.MicronautTest Java Examples

The following examples show how to use io.micronaut.test.annotation.MicronautTest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MicronautSpockExtension.java    From micronaut-test with Apache License 2.0 5 votes vote down vote up
@Override
protected void resolveTestProperties(IMethodInvocation context, MicronautTest testAnnotation, Map<String, Object> testProperties) {
    Object sharedInstance = context.getSharedInstance();
    if (sharedInstance instanceof TestPropertyProvider) {
        Map<String, String> properties = ((TestPropertyProvider) sharedInstance).getProperties();
        if (CollectionUtils.isNotEmpty(properties)) {
            testProperties.putAll(properties);
        }
    }
}
 
Example #2
Source File: MicronautJunit5Extension.java    From micronaut-test with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeAll(ExtensionContext extensionContext) throws Exception {
    final Class<?> testClass = extensionContext.getRequiredTestClass();
    final MicronautTest micronautTest = AnnotationSupport.findAnnotation(testClass, MicronautTest.class).orElse(null);
    beforeClass(extensionContext, testClass, micronautTest);
    getStore(extensionContext).put(ApplicationContext.class, applicationContext);
    if (specDefinition != null) {
        TestInstance ti = AnnotationSupport.findAnnotation(testClass, TestInstance.class).orElse(null);
        if (ti != null && ti.value() == TestInstance.Lifecycle.PER_CLASS) {
            Object testInstance = extensionContext.getRequiredTestInstance();
            applicationContext.inject(testInstance);
        }
    }
    beforeTestClass(buildContext(extensionContext));
}
 
Example #3
Source File: MicronautJunit5Extension.java    From micronaut-test with Apache License 2.0 5 votes vote down vote up
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
    final Optional<Object> testInstance = extensionContext.getTestInstance();
    if (testInstance.isPresent()) {

        final Class<?> requiredTestClass = extensionContext.getRequiredTestClass();
        if (applicationContext.containsBean(requiredTestClass)) {
            return ConditionEvaluationResult.enabled("Test bean active");
        } else {

            final boolean hasBeanDefinition = isTestSuiteBeanPresent(requiredTestClass);
            if (!hasBeanDefinition) {
                throw new TestInstantiationException(MISCONFIGURED_MESSAGE);
            } else {
                return ConditionEvaluationResult.disabled(DISABLED_MESSAGE);
            }

        }
    } else {
        final Class<?> testClass = extensionContext.getRequiredTestClass();
        if (AnnotationSupport.isAnnotated(testClass, MicronautTest.class)) {
            return ConditionEvaluationResult.enabled("Test bean active");
        } else {
            return ConditionEvaluationResult.disabled(DISABLED_MESSAGE);
        }
    }
}
 
Example #4
Source File: MicronautJunit5Extension.java    From micronaut-test with Apache License 2.0 5 votes vote down vote up
@Override
protected void resolveTestProperties(ExtensionContext context, MicronautTest testAnnotation, Map<String, Object> testProperties) {
    Object o = context.getTestInstance().orElse(null);
    if (o instanceof TestPropertyProvider) {
        Map<String, String> properties = ((TestPropertyProvider) o).getProperties();
        if (CollectionUtils.isNotEmpty(properties)) {
            testProperties.putAll(properties);
        }
    }
}
 
Example #5
Source File: MicronautSpockExtension.java    From micronaut-test with Apache License 2.0 4 votes vote down vote up
@Override
public void visitFeatureAnnotation(MicronautTest annotation, FeatureInfo feature) {
    throw new InvalidSpecException("@%s may not be applied to feature methods")
            .withArgs(annotation.annotationType().getSimpleName());
}
 
Example #6
Source File: MicronautSpockExtension.java    From micronaut-test with Apache License 2.0 4 votes vote down vote up
@Override
public void visitFixtureAnnotation(MicronautTest annotation, MethodInfo fixtureMethod) {
    throw new InvalidSpecException("@%s may not be applied to fixture methods")
            .withArgs(annotation.annotationType().getSimpleName());

}
 
Example #7
Source File: MicronautSpockExtension.java    From micronaut-test with Apache License 2.0 4 votes vote down vote up
@Override
public void visitFieldAnnotation(MicronautTest annotation, FieldInfo field) {
    throw new InvalidSpecException("@%s may not be applied to fields")
            .withArgs(annotation.annotationType().getSimpleName());

}
 
Example #8
Source File: AbstractMicronautExtension.java    From micronaut-test with Apache License 2.0 2 votes vote down vote up
/**
 * Resolves any test properties.
 *
 * @param context The test context
 * @param testAnnotation The test annotation
 * @param testProperties The test properties
 */
protected abstract void resolveTestProperties(C context, MicronautTest testAnnotation, Map<String, Object> testProperties);