Search in sources :

Example 61 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext in project camel by apache.

the class JmsConsumerShutdownTest method testJmsConsumerShutdownWithMessageInFlight.

@Test
@DirtiesContext
public void testJmsConsumerShutdownWithMessageInFlight() throws InterruptedException {
    end.expectedMessageCount(0);
    end.setResultWaitTime(2000);
    // direct:dir route always fails
    exception.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            throw new Exception("Kaboom!");
        }
    });
    activemq.sendBody("activemq:start", "Hello");
    end.assertIsSatisfied();
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 62 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext in project spring-framework by spring-projects.

the class AbstractDirtiesContextTestExecutionListener method beforeOrAfterTestClass.

/**
	 * Perform the actual work for {@link #beforeTestClass} and {@link #afterTestClass}
	 * by dirtying the context if appropriate (i.e., according to the required mode).
	 * @param testContext the test context whose application context should
	 * potentially be marked as dirty; 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 beforeOrAfterTestClass(TestContext testContext, ClassMode requiredClassMode) throws Exception {
    Assert.notNull(testContext, "TestContext must not be null");
    Assert.notNull(requiredClassMode, "requiredClassMode must not be null");
    Class<?> testClass = testContext.getTestClass();
    Assert.notNull(testClass, "The test class of the supplied TestContext must not be null");
    DirtiesContext dirtiesContext = AnnotatedElementUtils.findMergedAnnotation(testClass, DirtiesContext.class);
    boolean classAnnotated = (dirtiesContext != null);
    ClassMode classMode = (classAnnotated ? dirtiesContext.classMode() : null);
    if (logger.isDebugEnabled()) {
        String phase = (requiredClassMode.name().startsWith("BEFORE") ? "Before" : "After");
        logger.debug(String.format("%s test class: context %s, class annotated with @DirtiesContext [%s] with mode [%s].", phase, testContext, classAnnotated, classMode));
    }
    if (classMode == requiredClassMode) {
        dirtyContext(testContext, dirtiesContext.hierarchyMode());
    }
}
Also used : ClassMode(org.springframework.test.annotation.DirtiesContext.ClassMode) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 63 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext in project spring-security by spring-projects.

the class DelegatingAuthenticationEntryPointContextTests method testFirstAEP.

@Test
@DirtiesContext
public void testFirstAEP() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("192.168.1.10");
    request.addHeader("User-Agent", "Mozilla/5.0");
    daep.commence(request, null, null);
    verify(firstAEP).commence(request, null, null);
    verify(defaultAEP, never()).commence(any(HttpServletRequest.class), any(HttpServletResponse.class), any(AuthenticationException.class));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationException(org.springframework.security.core.AuthenticationException) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 64 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext in project opennms by OpenNMS.

the class TrapHandlerITCase method testV1EnterpriseIdAndGenericAndSpecificAndMatchWithVarbindsAndTC.

// These exist to provide testing for the new Textual Convention feature
// See EventConfDataTest for the other part of this testing
@Test
@DirtiesContext
public void testV1EnterpriseIdAndGenericAndSpecificAndMatchWithVarbindsAndTC() throws Exception {
    SnmpValueFactory valueFactory = SnmpUtils.getValueFactory();
    LinkedHashMap<String, SnmpValue> varbinds = new LinkedHashMap<String, SnmpValue>();
    varbinds.put(".1.3.6.1.4.1.14179.2.6.2.20.0", valueFactory.getOctetString(new byte[] { (byte) 0x00, (byte) 0x14, (byte) 0xf1, (byte) 0xad, (byte) 0xa7, (byte) 0x50 }));
    Collection<Event> events = anticipateAndSend(false, true, "uei.opennms.org/vendor/cisco/bsnAPNoiseProfileUpdatedToPass", "v1", ".1.3.6.1.4.1.14179.2.6.3", 6, 38, varbinds);
    boolean foundMacAddress = false;
    // Assert that the MAC address varbind has been formatted into a colon-separated octet string
    for (Event event : events) {
        for (Parm parm : event.getParmCollection()) {
            if (".1.3.6.1.4.1.14179.2.6.2.20.0".equals(parm.getParmName())) {
                assertEquals("MAC address does not match", "00:14:F1:AD:A7:50", parm.getValue().getContent());
                foundMacAddress = true;
            }
        }
    }
    assertTrue("Did not find expected MAC address parm", foundMacAddress);
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Event(org.opennms.netmgt.xml.event.Event) Parm(org.opennms.netmgt.xml.event.Parm) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 65 with DirtiesContext

use of org.springframework.test.annotation.DirtiesContext in project opennms by OpenNMS.

the class EventMappingRulesIT method testMapIfUp.

@Test
@DirtiesContext
public void testMapIfUp() throws Exception {
    Event event = createVpnIfUpEvent(17, m_pe1NodeId, "10.1.1.1", "5", "ge-1/0/2.50");
    testEventMapping(event, ComponentUpEvent.class, "ServiceElementComponent", "NA-SvcElemComp", "8765,jnxVpnIf");
}
Also used : Event(org.opennms.netmgt.xml.event.Event) 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