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