use of org.mockito.invocation.InvocationOnMock in project camel by apache.
the class CouchDbProducerTest method testStringBodyIsConvertedToJsonTree.
@Test
public void testStringBodyIsConvertedToJsonTree() throws Exception {
when(msg.getMandatoryBody()).thenReturn("{ \"name\" : \"coldplay\" }");
when(client.save(anyObject())).thenAnswer(new Answer<Response>() {
@Override
public Response answer(InvocationOnMock invocation) throws Throwable {
assertTrue(invocation.getArguments()[0].getClass() + " but wanted " + JsonElement.class, invocation.getArguments()[0] instanceof JsonElement);
return new Response();
}
});
producer.process(exchange);
verify(client).save(any(JsonObject.class));
}
use of org.mockito.invocation.InvocationOnMock in project camel by apache.
the class CouchbaseProducerTest method testTimeOutRetryThenSuccess.
@Test
public void testTimeOutRetryThenSuccess() throws Exception {
OperationFuture of = mock(OperationFuture.class);
when(of.get()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
throw new RuntimeException("Timed out waiting for operation");
}
}).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
return true;
}
});
when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class), org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
when(endpoint.getId()).thenReturn("123");
when(endpoint.getOperation()).thenReturn("CCB_PUT");
when(exchange.getOut()).thenReturn(msg);
producer.process(exchange);
verify(of, times(2)).get();
verify(msg).setBody(true);
}
use of org.mockito.invocation.InvocationOnMock in project camel by apache.
the class CouchbaseProducerTest method testTimeOutRetryTwiceThenSuccess.
@Test
public void testTimeOutRetryTwiceThenSuccess() throws Exception {
OperationFuture of = mock(OperationFuture.class);
when(of.get()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
throw new RuntimeException("Timed out waiting for operation");
}
}).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
throw new RuntimeException("Timed out waiting for operation");
}
}).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
return true;
}
});
when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class), org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
when(endpoint.getId()).thenReturn("123");
when(endpoint.getOperation()).thenReturn("CCB_PUT");
when(exchange.getOut()).thenReturn(msg);
producer.process(exchange);
verify(of, times(3)).get();
verify(msg).setBody(true);
}
use of org.mockito.invocation.InvocationOnMock in project camel by apache.
the class CouchbaseProducerTest method testExpiryTimeIsSet.
@Test
public void testExpiryTimeIsSet() throws Exception {
OperationFuture of = mock(OperationFuture.class);
when(of.get()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Exception {
return true;
}
});
when(client.set(org.mockito.Matchers.anyString(), org.mockito.Matchers.anyInt(), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class), org.mockito.Matchers.any(ReplicateTo.class))).thenReturn(of);
// Mock out some headers so we can set an expiry
int expiry = 5000;
Map<String, Object> testHeaders = new HashMap<String, Object>();
testHeaders.put("CCB_TTL", Integer.toString(expiry));
when(msg.getHeaders()).thenReturn(testHeaders);
when(msg.getHeader(HEADER_TTL, String.class)).thenReturn(Integer.toString(expiry));
when(endpoint.getId()).thenReturn("123");
when(endpoint.getOperation()).thenReturn("CCB_PUT");
Message outmsg = mock(Message.class);
when(exchange.getOut()).thenReturn(msg);
producer.process(exchange);
verify(client).set(org.mockito.Matchers.anyString(), Mockito.eq(expiry), org.mockito.Matchers.anyObject(), org.mockito.Matchers.any(PersistTo.class), org.mockito.Matchers.any(ReplicateTo.class));
}
use of org.mockito.invocation.InvocationOnMock in project camel by apache.
the class HipchatComponentMultipleUsersTest method sendInOnlyMultipleUsers.
@Test
public void sendInOnlyMultipleUsers() throws Exception {
result.expectedMessageCount(2);
result.expectedHeaderValuesReceivedInAnyOrder(HipchatConstants.FROM_USER, Arrays.asList(new String[] { "@AUser", "@BUser" }));
final String expectedResponse = "{\n" + " \"items\" : [\n" + " {\n" + " \"date\" : \"2015-01-19T22:07:11.030740+00:00\",\n" + " \"from\" : {\n" + " \"id\" : 1647095,\n" + " \"links\" : {\n" + " \"self\" : \"https://api.hipchat.com/v2/user/1647095\"\n" + " },\n" + " \"mention_name\" : \"notifier\",\n" + " \"name\" : \"Message Notifier\"\n" + " },\n" + " \"id\" : \"6567c6f7-7c1b-43cf-bed0-792b1d092919\",\n" + " \"mentions\" : [ ],\n" + " \"message\" : \"Unit test Alert\",\n" + " \"type\" : \"message\"\n" + " }\n" + " ],\n" + " \"links\" : {\n" + " \"self\" : \"https://api.hipchat.com/v2/user/%40ShreyasPurohit/history/latest\"\n" + " },\n" + " \"maxResults\" : 1,\n" + " \"startIndex\" : 0\n" + "}";
HttpEntity mockHttpEntity = mock(HttpEntity.class);
when(mockHttpEntity.getContent()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
return new ByteArrayInputStream(expectedResponse.getBytes(StandardCharsets.UTF_8));
}
});
when(closeableHttpResponse.getEntity()).thenReturn(mockHttpEntity);
when(closeableHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, ""));
assertMockEndpointsSatisfied();
}
Aggregations