Search in sources :

Example 36 with DirtiesContext

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);
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 37 with DirtiesContext

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());
}
Also used : MyProvider(org.opennms.core.soa.support.MyProvider) Registration(org.opennms.core.soa.Registration) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 38 with DirtiesContext

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();
}
Also used : Event(org.opennms.netmgt.xml.event.Event) DroolsCorrelationEngine(org.opennms.netmgt.correlation.drools.DroolsCorrelationEngine) Ignore(org.junit.Ignore) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 39 with DirtiesContext

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);
    }
}
Also used : HierarchyMode(org.springframework.test.annotation.DirtiesContext.HierarchyMode) ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) MethodMode(org.springframework.test.annotation.DirtiesContext.MethodMode) DirtiesContext(org.springframework.test.annotation.DirtiesContext) Method(java.lang.reflect.Method)

Example 40 with DirtiesContext

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();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Value(org.opennms.netmgt.xml.event.Value) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Event(org.opennms.netmgt.xml.event.Event) Parm(org.opennms.netmgt.xml.event.Parm) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

DirtiesContext (org.springframework.test.annotation.DirtiesContext)86 Test (org.junit.Test)83 Exchange (org.apache.camel.Exchange)21 Event (org.opennms.netmgt.xml.event.Event)19 Processor (org.apache.camel.Processor)11 DroolsCorrelationEngine (org.opennms.netmgt.correlation.drools.DroolsCorrelationEngine)10 IOException (java.io.IOException)9 NCSComponent (org.opennms.netmgt.model.ncs.NCSComponent)9 ProducerTemplate (org.apache.camel.ProducerTemplate)7 Ignore (org.junit.Ignore)7 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 LinkedHashMap (java.util.LinkedHashMap)5 CommonBindyTest (org.apache.camel.dataformat.bindy.CommonBindyTest)5 FactHandle (org.kie.api.runtime.rule.FactHandle)5 SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)5 Message (org.apache.camel.Message)4 BigDecimal (java.math.BigDecimal)3 Registration (org.opennms.core.soa.Registration)3