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);
}
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations