Search in sources :

Example 6 with ClassRule

use of org.junit.ClassRule in project grails-core by grails.

the class TestMixinTransformation method addJunitRuleFields.

protected void addJunitRuleFields(ClassNode classNode) {
    if (classNode.getField(JUNIT_ADAPTER_FIELD_NAME) != null) {
        return;
    }
    ClassNode junitAdapterType = ClassHelper.make(TestRuntimeJunitAdapter.class);
    FieldNode junitAdapterFieldNode = classNode.addField(JUNIT_ADAPTER_FIELD_NAME, Modifier.STATIC, junitAdapterType, new ConstructorCallExpression(junitAdapterType, MethodCallExpression.NO_ARGUMENTS));
    boolean spockTest = isSpockTest(classNode);
    FieldNode staticRuleFieldNode = classNode.addField(RULE_FIELD_NAME_BASE + "StaticClassRule", Modifier.PRIVATE | Modifier.STATIC, ClassHelper.make(TestRule.class), new MethodCallExpression(new FieldExpression(junitAdapterFieldNode), "newClassRule", new ClassExpression(classNode)));
    AnnotationNode classRuleAnnotation = new AnnotationNode(ClassHelper.make(ClassRule.class));
    if (spockTest) {
        // @ClassRule must be added to @Shared field in spock
        FieldNode spockSharedRuleFieldNode = classNode.addField(RULE_FIELD_NAME_BASE + "SharedClassRule", Modifier.PUBLIC, ClassHelper.make(TestRule.class), new FieldExpression(staticRuleFieldNode));
        spockSharedRuleFieldNode.addAnnotation(classRuleAnnotation);
        spockSharedRuleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Shared.class)));
        addSpockFieldMetadata(spockSharedRuleFieldNode, 0);
    } else {
        staticRuleFieldNode.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
        staticRuleFieldNode.addAnnotation(classRuleAnnotation);
    }
    FieldNode ruleFieldNode = classNode.addField(RULE_FIELD_NAME_BASE + "Rule", Modifier.PUBLIC, ClassHelper.make(TestRule.class), new MethodCallExpression(new FieldExpression(junitAdapterFieldNode), "newRule", new VariableExpression("this")));
    ruleFieldNode.addAnnotation(new AnnotationNode(ClassHelper.make(Rule.class)));
    if (spockTest) {
        addSpockFieldMetadata(ruleFieldNode, 0);
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) TestRule(org.junit.rules.TestRule) FieldNode(org.codehaus.groovy.ast.FieldNode) MethodCallExpression(org.codehaus.groovy.ast.expr.MethodCallExpression) AnnotationNode(org.codehaus.groovy.ast.AnnotationNode) ConstructorCallExpression(org.codehaus.groovy.ast.expr.ConstructorCallExpression) ClassRule(org.junit.ClassRule) ClassExpression(org.codehaus.groovy.ast.expr.ClassExpression) VariableExpression(org.codehaus.groovy.ast.expr.VariableExpression) FieldExpression(org.codehaus.groovy.ast.expr.FieldExpression)

Example 7 with ClassRule

use of org.junit.ClassRule in project opennms by OpenNMS.

the class JmxRemoteAdminIT method getTestEnvironment.

@ClassRule
public static final TestEnvironment getTestEnvironment() {
    LOG.warn("Setting up Docker test environment.");
    try {
        final TestEnvironmentBuilder builder = TestEnvironment.builder().opennms();
        builder.skipTearDown(Boolean.getBoolean("org.opennms.smoketest.docker.skipTearDown"));
        builder.useExisting(Boolean.getBoolean("org.opennms.smoketest.docker.useExisting"));
        builder.withOpenNMSEnvironment().optIn(false).addFile(OpenNMSSeleniumTestCase.class.getResource("etc/monitoring-locations.xml"), "etc/monitoring-locations.xml").addFiles(Paths.get("src/test/resources/org/opennms/smoketest/etc"), "etc");
        m_testEnvironment = builder.build();
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
    return m_testEnvironment;
}
Also used : TestEnvironmentBuilder(org.opennms.test.system.api.TestEnvironmentBuilder) ClassRule(org.junit.ClassRule)

Example 8 with ClassRule

use of org.junit.ClassRule in project opennms by OpenNMS.

the class DiscoveryIT method getTestEnvironment.

@ClassRule
public static final TestEnvironment getTestEnvironment() {
    if (!OpenNMSSeleniumTestCase.isDockerEnabled()) {
        return new NullTestEnvironment();
    }
    try {
        final TestEnvironmentBuilder builder = TestEnvironment.builder().all();
        OpenNMSSeleniumTestCase.configureTestEnvironment(builder);
        minionSystem = builder.build();
        return minionSystem;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
Also used : TestEnvironmentBuilder(org.opennms.test.system.api.TestEnvironmentBuilder) NullTestEnvironment(org.opennms.smoketest.NullTestEnvironment) ClassRule(org.junit.ClassRule)

Example 9 with ClassRule

use of org.junit.ClassRule in project opennms by OpenNMS.

the class MonitorsListCommandIT method getTestEnvironment.

@ClassRule
public static final TestEnvironment getTestEnvironment() {
    if (!OpenNMSSeleniumTestCase.isDockerEnabled()) {
        return new NullTestEnvironment();
    }
    try {
        final TestEnvironmentBuilder builder = TestEnvironment.builder().all();
        OpenNMSSeleniumTestCase.configureTestEnvironment(builder);
        m_testEnvironment = builder.build();
        return m_testEnvironment;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
Also used : TestEnvironmentBuilder(org.opennms.test.system.api.TestEnvironmentBuilder) NullTestEnvironment(org.opennms.smoketest.NullTestEnvironment) ClassRule(org.junit.ClassRule)

Example 10 with ClassRule

use of org.junit.ClassRule in project opennms by OpenNMS.

the class DetectorsCommandIT method getTestEnvironment.

@ClassRule
public static final TestEnvironment getTestEnvironment() {
    if (!OpenNMSSeleniumTestCase.isDockerEnabled()) {
        return new NullTestEnvironment();
    }
    try {
        final TestEnvironmentBuilder builder = TestEnvironment.builder().all();
        OpenNMSSeleniumTestCase.configureTestEnvironment(builder);
        m_testEnvironment = builder.build();
        return m_testEnvironment;
    } catch (final Throwable t) {
        throw new RuntimeException(t);
    }
}
Also used : TestEnvironmentBuilder(org.opennms.test.system.api.TestEnvironmentBuilder) NullTestEnvironment(org.opennms.smoketest.NullTestEnvironment) ClassRule(org.junit.ClassRule)

Aggregations

ClassRule (org.junit.ClassRule)10 TestEnvironmentBuilder (org.opennms.test.system.api.TestEnvironmentBuilder)8 NullTestEnvironment (org.opennms.smoketest.NullTestEnvironment)7 Field (java.lang.reflect.Field)1 AnnotationNode (org.codehaus.groovy.ast.AnnotationNode)1 ClassNode (org.codehaus.groovy.ast.ClassNode)1 FieldNode (org.codehaus.groovy.ast.FieldNode)1 ClassExpression (org.codehaus.groovy.ast.expr.ClassExpression)1 ConstructorCallExpression (org.codehaus.groovy.ast.expr.ConstructorCallExpression)1 FieldExpression (org.codehaus.groovy.ast.expr.FieldExpression)1 MethodCallExpression (org.codehaus.groovy.ast.expr.MethodCallExpression)1 VariableExpression (org.codehaus.groovy.ast.expr.VariableExpression)1 TestRule (org.junit.rules.TestRule)1