Search in sources :

Example 1 with ClassRule

use of org.junit.ClassRule in project spring-framework by spring-projects.

the class SpringMethodRule method validateSpringClassRuleConfiguration.

/**
	 * Throw an {@link IllegalStateException} if the supplied {@code testClass}
	 * does not declare a {@code public static final SpringClassRule} field
	 * that is annotated with {@code @ClassRule}.
	 */
private static SpringClassRule validateSpringClassRuleConfiguration(Class<?> testClass) {
    Field ruleField = findSpringClassRuleField(testClass).orElseThrow(() -> new IllegalStateException(String.format("Failed to find 'public static final SpringClassRule' field in test class [%s]. " + "Consult the javadoc for SpringClassRule for details.", testClass.getName())));
    Assert.state(ruleField.isAnnotationPresent(ClassRule.class), () -> String.format("SpringClassRule field [%s] must be annotated with JUnit's @ClassRule annotation. " + "Consult the javadoc for SpringClassRule for details.", ruleField));
    return (SpringClassRule) ReflectionUtils.getField(ruleField, null);
}
Also used : Field(java.lang.reflect.Field) ClassRule(org.junit.ClassRule)

Example 2 with ClassRule

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

the class TrapIT method getTestEnvironment.

@ClassRule
public static final TestEnvironment getTestEnvironment() {
    if (!OpenNMSSeleniumTestCase.isDockerEnabled()) {
        return new NullTestEnvironment();
    }
    try {
        final TestEnvironmentBuilder builder = TestEnvironment.builder().all();
        builder.withOpenNMSEnvironment().addFile(AbstractSyslogTestCase.class.getResource("/eventconf.xml"), "etc/eventconf.xml").addFile(AbstractSyslogTestCase.class.getResource("/events/Cisco.syslog.events.xml"), "etc/events/Cisco.syslog.events.xml").addFile(AbstractSyslogTestCase.class.getResource("/syslogd-configuration.xml"), "etc/syslogd-configuration.xml").addFile(AbstractSyslogTestCase.class.getResource("/syslog/Cisco.syslog.xml"), "etc/syslog/Cisco.syslog.xml");
        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 3 with ClassRule

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

the class DetectorsOnMinionIT 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 4 with ClassRule

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

the class MinionHeartBeatIT 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 5 with ClassRule

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

the class CollectorListIT 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