use of org.lightcouch.Response in project camel by apache.
the class CouchDbConsumerIntegrationTest method testInsertsOnly.
@Test
public void testInsertsOnly() throws InterruptedException {
to.expectedHeaderReceived(CouchDbConstants.HEADER_METHOD, "UPDATE");
to.expectedMessageCount(1);
JsonElement obj = new Gson().toJsonTree("{ \"randomString\" : \"" + UUID.randomUUID() + "\" }");
Response resp = client.save(obj);
client.remove(resp.getId(), resp.getRev());
to.assertIsSatisfied();
}
use of org.lightcouch.Response 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.lightcouch.Response in project camel by apache.
the class CouchDbProducer method deleteJsonElement.
private Response deleteJsonElement(JsonElement json) {
Response delete;
if (json instanceof JsonObject) {
JsonObject obj = (JsonObject) json;
delete = couchClient.remove(obj);
} else {
delete = couchClient.remove(json);
}
return delete;
}
use of org.lightcouch.Response in project camel by apache.
the class CouchDbProducer method process.
@Override
public void process(Exchange exchange) throws Exception {
JsonElement json = getBodyAsJsonElement(exchange);
String operation = exchange.getIn().getHeader(CouchDbConstants.HEADER_METHOD, String.class);
if (ObjectHelper.isEmpty(operation)) {
Response save = saveJsonElement(json);
if (save == null) {
throw new CouchDbException("Could not save document [unknown reason]", exchange);
}
if (log.isTraceEnabled()) {
log.trace("Document saved [_id={}, _rev={}]", save.getId(), save.getRev());
}
exchange.getIn().setHeader(CouchDbConstants.HEADER_DOC_REV, save.getRev());
exchange.getIn().setHeader(CouchDbConstants.HEADER_DOC_ID, save.getId());
} else {
if (operation.equalsIgnoreCase("DELETE")) {
Response delete = deleteJsonElement(json);
if (delete == null) {
throw new CouchDbException("Could not delete document [unknown reason]", exchange);
}
if (log.isTraceEnabled()) {
log.trace("Document saved [_id={}, _rev={}]", delete.getId(), delete.getRev());
}
exchange.getIn().setHeader(CouchDbConstants.HEADER_DOC_REV, delete.getRev());
exchange.getIn().setHeader(CouchDbConstants.HEADER_DOC_ID, delete.getId());
}
}
}
use of org.lightcouch.Response in project camel by apache.
the class CouchDbConsumerDeletesIntegrationTest method testDeletesOnly.
@Test
public void testDeletesOnly() throws InterruptedException {
to.expectedHeaderReceived(CouchDbConstants.HEADER_METHOD, "DELETE");
to.expectedMessageCount(1);
JsonElement obj = new Gson().toJsonTree("{ \"randomString\" : \"" + UUID.randomUUID() + "\" }");
Response resp = client.save(obj);
client.remove(resp.getId(), resp.getRev());
to.assertIsSatisfied();
}
Aggregations