@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<DocumentResult> 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.getResult().getId(), save.getResult().getRev());
            }
            exchange.getIn().setHeader(CouchDbConstants.HEADER_DOC_REV, save.getResult().getRev());
            exchange.getIn().setHeader(CouchDbConstants.HEADER_DOC_ID, save.getResult().getId());
        } else {
            if (operation.equalsIgnoreCase(CouchDbOperations.DELETE.toString())) {
                Response<DocumentResult> 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.getResult().getId(), delete.getResult().getRev());
                }
                exchange.getIn().setHeader(CouchDbConstants.HEADER_DOC_REV, delete.getResult().getRev());
                exchange.getIn().setHeader(CouchDbConstants.HEADER_DOC_ID, delete.getResult().getId());
            }
            if (operation.equalsIgnoreCase(CouchDbOperations.GET.toString())) {
                String docId = exchange.getIn().getHeader(CouchDbConstants.HEADER_DOC_ID, String.class);
                if (docId == null) {
                    throw new CouchDbException("Could not get document, document id is missing", exchange);
                }
                Object response = getElement(docId);

                if (LOG.isTraceEnabled()) {
                    LOG.trace("Document retrieved [_id={}]", docId);
                }

                exchange.getIn().setBody(response);
            }
        }
    }
@Test
    void testDeleteResponse() throws Exception {
        String id = UUID.randomUUID().toString();
        String rev = UUID.randomUUID().toString();

        Document doc = new Document.Builder()
                .id(id)
                .add("_rev", rev)
                .build();

        DocumentResult documentResult = mock(DocumentResult.class, Answers.RETURNS_DEEP_STUBS);
        when(msg.getHeader(CouchDbConstants.HEADER_METHOD, String.class)).thenReturn("DELETE");
        when(msg.getMandatoryBody()).thenReturn(doc);
        when(client.removeByIdAndRev(id, rev)).thenReturn(response);
        when(response.getResult()).thenReturn(documentResult);
        when(response.getResult().getId()).thenReturn(id);
        when(response.getResult().getRev()).thenReturn(rev);

        producer.process(exchange);
        verify(msg).setHeader(CouchDbConstants.HEADER_DOC_ID, id);
        verify(msg).setHeader(CouchDbConstants.HEADER_DOC_REV, rev);
    }