use of org.springframework.test.annotation.DirtiesContext in project opennms by OpenNMS.
the class TrapHandlerITCase method testV1TrapOIDWildCardMatch.
@Test
@DirtiesContext
public void testV1TrapOIDWildCardMatch() throws Exception {
SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
LinkedHashMap<String, SnmpValue> varbinds = new LinkedHashMap<String, SnmpValue>();
varbinds.put(".1.3.6.1.4.1.32473.42.42.42", valueFactory.getInt32(42));
anticipateAndSend(false, true, "uei.opennms.org/IANA/Example/traps/exampleEnterpriseTrap", "v1", ".1.3.6.1.4.1.32473.42", 6, 5, varbinds);
}
use of org.springframework.test.annotation.DirtiesContext in project opennms by OpenNMS.
the class NamespaceHandlerTest method testRegistrationListenerBeanDefinition.
@Test
@DirtiesContext
public void testRegistrationListenerBeanDefinition() {
assertNotNull(m_helloListListener);
MyProvider myProvider = new MyProvider();
int expected = m_helloListListener.getTotalProviders() + 1;
Registration registration = m_defaultServiceRegistry.register(myProvider, Hello.class);
assertEquals(expected, m_helloListListener.getTotalProviders());
expected = m_helloListListener.getTotalProviders() - 1;
registration.unregister();
assertEquals(expected, m_helloListListener.getTotalProviders());
}
use of org.springframework.test.annotation.DirtiesContext in project opennms by OpenNMS.
the class MonolithicDependencyRulesIT method testMultipleDownAndSingleUpCase.
@Test
@DirtiesContext
@Ignore("not yet implemented")
public void testMultipleDownAndSingleUpCase() throws Exception {
// Get engine
DroolsCorrelationEngine engine = findEngineByName("monolithicDependencyRules");
// Anticipate down event
getAnticipator().reset();
anticipate(createComponentImpactedEvent("ServiceElementComponent", "jnxVpnPw-vcid(50)", "NA-SvcElemComp", "9876,jnxVpnPw-vcid(50)", 17));
anticipate(createComponentImpactedEvent("ServiceElement", "PE2,SE1", "NA-ServiceElement", "9876", 17));
anticipate(createComponentImpactedEvent("Service", "CokeP2P", "NA-Service", "123", 17));
// Generate down event
Event event = createVpnPwDownEvent(m_pe2NodeId, "10.1.1.1", "5", "ge-3/1/4.50");
event.setDbid(17);
System.err.println("SENDING VpnPwDown EVENT!!");
engine.correlate(event);
// Check down event
getAnticipator().verifyAnticipated();
// Generate additional down event - nothing should happen
getAnticipator().reset();
event = createVpnPwDownEvent(m_pe2NodeId, "10.1.1.1", "5", "ge-3/1/4.50");
event.setDbid(18);
System.err.println("SENDING VpnPwDown EVENT!!");
engine.correlate(event);
getAnticipator().verifyAnticipated();
// Anticipate up event
getAnticipator().reset();
anticipate(createComponentResolvedEvent("ServiceElementComponent", "jnxVpnPw-vcid(50)", "NA-SvcElemComp", "9876,jnxVpnPw-vcid(50)", 17));
anticipate(createComponentResolvedEvent("ServiceElement", "PE2,SE1", "NA-ServiceElement", "9876", 17));
anticipate(createComponentResolvedEvent("Service", "CokeP2P", "NA-Service", "123", 17));
// Generate up event
event = createVpnPwUpEvent(m_pe2NodeId, "10.1.1.1", "5", "ge-3/1/4.50");
event.setDbid(17);
System.err.println("SENDING VpnPwUp EVENT!!");
engine.correlate(event);
// Check up event
getAnticipator().verifyAnticipated();
}
use of org.springframework.test.annotation.DirtiesContext in project spring-framework by spring-projects.
the class AbstractDirtiesContextTestExecutionListener method beforeOrAfterTestMethod.
/**
* Perform the actual work for {@link #beforeTestMethod} and {@link #afterTestMethod}
* by dirtying the context if appropriate (i.e., according to the required modes).
* @param testContext the test context whose application context should
* potentially be marked as dirty; never {@code null}
* @param requiredMethodMode the method mode required for a context to
* be marked dirty in the current phase; never {@code null}
* @param requiredClassMode the class mode required for a context to
* be marked dirty in the current phase; never {@code null}
* @throws Exception allows any exception to propagate
* @since 4.2
* @see #dirtyContext
*/
protected void beforeOrAfterTestMethod(TestContext testContext, MethodMode requiredMethodMode, ClassMode requiredClassMode) throws Exception {
Assert.notNull(testContext, "TestContext must not be null");
Assert.notNull(requiredMethodMode, "requiredMethodMode must not be null");
Assert.notNull(requiredClassMode, "requiredClassMode must not be null");
Class<?> testClass = testContext.getTestClass();
Method testMethod = testContext.getTestMethod();
Assert.notNull(testClass, "The test class of the supplied TestContext must not be null");
Assert.notNull(testMethod, "The test method of the supplied TestContext must not be null");
DirtiesContext methodAnn = AnnotatedElementUtils.findMergedAnnotation(testMethod, DirtiesContext.class);
DirtiesContext classAnn = AnnotatedElementUtils.findMergedAnnotation(testClass, DirtiesContext.class);
boolean methodAnnotated = (methodAnn != null);
boolean classAnnotated = (classAnn != null);
MethodMode methodMode = (methodAnnotated ? methodAnn.methodMode() : null);
ClassMode classMode = (classAnnotated ? classAnn.classMode() : null);
if (logger.isDebugEnabled()) {
String phase = (requiredClassMode.name().startsWith("BEFORE") ? "Before" : "After");
logger.debug(String.format("%s test method: context %s, class annotated with @DirtiesContext [%s] " + "with mode [%s], method annotated with @DirtiesContext [%s] with mode [%s].", phase, testContext, classAnnotated, classMode, methodAnnotated, methodMode));
}
if ((methodMode == requiredMethodMode) || (classMode == requiredClassMode)) {
HierarchyMode hierarchyMode = (methodAnnotated ? methodAnn.hierarchyMode() : classAnn.hierarchyMode());
dirtyContext(testContext, hierarchyMode);
}
}
use of org.springframework.test.annotation.DirtiesContext in project opennms by OpenNMS.
the class TrapHandlerITCase method testInterfaceReparentedModifiesIpMgr.
@Test
@DirtiesContext
public void testInterfaceReparentedModifiesIpMgr() throws Exception {
final OnmsNode node = new OnmsNode(m_dbPopulator.getMonitoringLocationDao().getDefaultLocation(), "test123");
final OnmsIpInterface iface = new OnmsIpInterface();
iface.setIpAddress(m_ip);
iface.setIsSnmpPrimary(PrimaryType.PRIMARY);
node.addIpInterface(iface);
int nodeId = m_dbPopulator.getNodeDao().save(node);
anticipateEvent("uei.opennms.org/default/trap", m_ip, nodeId);
Event event = anticipateEvent(EventConstants.INTERFACE_REPARENTED_EVENT_UEI, m_ip, nodeId);
event.addParm(new Parm() {
{
this.setParmName(EventConstants.PARM_OLD_NODEID);
this.setValue(new Value(Integer.toString(m_nodeId)));
}
});
event.addParm(new Parm() {
{
this.setParmName(EventConstants.PARM_NEW_NODEID);
this.setValue(new Value(Integer.toString(nodeId)));
}
});
m_eventMgr.sendNow(event);
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// do nothing
}
sendTrap("v1", null, 6, 1);
finishUp();
}
Aggregations