Search in sources :

Example 36 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class ServiceNowImportSetTest method testIncidentImport.

@Test
public void testIncidentImport() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:servicenow");
    mock.reset();
    mock.expectedMessageCount(1);
    IncidentImportRequest incident = new IncidentImportRequest();
    incident.shortDescription = "test";
    template().sendBodyAndHeaders("direct:servicenow", incident, kvBuilder().put(ServiceNowConstants.RESOURCE, ServiceNowConstants.RESOURCE_IMPORT).put(ServiceNowConstants.ACTION, ServiceNowConstants.ACTION_CREATE).put(ServiceNowConstants.REQUEST_MODEL, IncidentImportRequest.class).put(ServiceNowConstants.RESPONSE_MODEL, IncidentImportResponse.class).put(ServiceNowParams.PARAM_TABLE_NAME, "u_imp_incident").build());
    mock.assertIsSatisfied();
    Message in = mock.getExchanges().get(0).getIn();
    // Meta data
    Map<String, String> meta = in.getHeader(ServiceNowConstants.RESPONSE_META, Map.class);
    assertNotNull(meta);
    assertEquals("u_imp_incident", meta.get("staging_table"));
    // Incidents
    List<IncidentImportResponse> responses = in.getBody(List.class);
    assertNotNull(responses);
    assertEquals(1, responses.size());
    assertEquals("inserted", responses.get(0).status);
    assertEquals("imp_incidents", responses.get(0).transformMap);
    assertEquals("incident", responses.get(0).table);
}
Also used : Message(org.apache.camel.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 37 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class JavaScriptExpressionTest method testSendMatchingMessage.

@Test
public void testSendMatchingMessage() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    getMockEndpoint("mock:unmatched").expectedMessageCount(0);
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("foo", "bar");
    sendBody("direct:start", "hello", headers);
    assertEquals("Should get the message header here", mock.getExchanges().get(0).getIn().getHeader("foo"), "bar");
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 38 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class JavaScriptPropertiesFunctionTest method testSendMatchingMessage.

@Test
public void testSendMatchingMessage() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    mock.expectedHeaderReceived("myHeader", "Kong");
    template.sendBodyAndHeader("direct:start", "Hello World", "foo", "bar");
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 39 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class SpringSecurityAuthorizationPolicyTest method testAuthenticationFailed.

@Test
public void testAuthenticationFailed() throws Exception {
    MockEndpoint end = getMockEndpoint("mock:end");
    end.expectedMessageCount(0);
    try {
        sendMessageWithAuthentication("bob", "jimspassword");
        fail("we should get the access deny exception here");
    } catch (Exception exception) {
        // the exception should be caused by CamelAuthorizationException
        assertTrue("Expect CamelAuthorizationException here", exception.getCause() instanceof CamelAuthorizationException);
        assertEquals("admin", ((CamelAuthorizationException) exception.getCause()).getPolicyId());
    }
    end.assertIsSatisfied();
}
Also used : CamelAuthorizationException(org.apache.camel.CamelAuthorizationException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CamelAuthorizationException(org.apache.camel.CamelAuthorizationException) Test(org.junit.Test)

Example 40 with MockEndpoint

use of org.apache.camel.component.mock.MockEndpoint in project camel by apache.

the class SpringLdapComponentTest method testSearch.

@Test
public void testSearch() throws Exception {
    String dnToSearch = "some dn to bind";
    initializeTest(dnToSearch);
    String filter = "some ldap filter";
    body.put(SpringLdapProducer.FILTER, filter);
    ArgumentCaptor<String> dnCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<String> filterCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<Integer> scopeCaptor = ArgumentCaptor.forClass(Integer.class);
    ArgumentCaptor<AttributesMapper> mapperCaptor = ArgumentCaptor.forClass(AttributesMapper.class);
    List<String> searchResult = Collections.singletonList("some search result");
    when(ldapTemplate.search(any(String.class), any(String.class), any(Integer.class), any(AttributesMapper.class))).thenReturn(searchResult);
    MockEndpoint resultEndpoint = (MockEndpoint) context.getEndpoint("mock:result");
    resultEndpoint.expectedBodiesReceived(Collections.singletonList(searchResult));
    producer.sendBody("direct:start", body);
    Mockito.verify(ldapTemplate).search(dnCaptor.capture(), filterCaptor.capture(), scopeCaptor.capture(), mapperCaptor.capture());
    assertEquals(dnToSearch, dnCaptor.getValue());
    assertEquals((Integer) SearchControls.ONELEVEL_SCOPE, scopeCaptor.getValue());
    assertEquals(filter, filterCaptor.getValue());
    resultEndpoint.assertIsSatisfied();
}
Also used : AttributesMapper(org.springframework.ldap.core.AttributesMapper) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Aggregations

MockEndpoint (org.apache.camel.component.mock.MockEndpoint)3401 Test (org.junit.Test)2024 Exchange (org.apache.camel.Exchange)511 RouteBuilder (org.apache.camel.builder.RouteBuilder)302 Processor (org.apache.camel.Processor)148 File (java.io.File)144 HashMap (java.util.HashMap)130 ObjectName (javax.management.ObjectName)90 MBeanServer (javax.management.MBeanServer)85 Message (org.apache.camel.Message)85 InputStream (java.io.InputStream)73 ArrayList (java.util.ArrayList)63 CamelExecutionException (org.apache.camel.CamelExecutionException)63 List (java.util.List)57 CamelContext (org.apache.camel.CamelContext)57 ProducerTemplate (org.apache.camel.ProducerTemplate)51 Tx (org.nhindirect.common.tx.model.Tx)49 ByteArrayInputStream (java.io.ByteArrayInputStream)47 Map (java.util.Map)43 RuntimeCamelException (org.apache.camel.RuntimeCamelException)38