@Test(expected = UpdateConflictException.class) public void throw_exception_when_in_conflict() { td.setId("some_id"); td.setRevision("123D123"); final ByteArrayOutputStream output = new ByteArrayOutputStream(); doAnswer(new MarshallEntityAndReturnAnswer(output, ResponseOnFileStub.newInstance(409, "update_conflict.json"))).when(httpClient).put(anyString(), any(HttpEntity.class)); dbCon.update(td); }
@Override public void update(final Object o) { Assert.notNull(o, "Document cannot be null"); final String id = Documents.getId(o); assertDocIdHasValue(id); HttpEntity entity = createHttpEntity(o); restTemplate.put(dbURI.append(id).toString(), entity, new StdResponseHandler<Void>() { @Override public Void success(HttpResponse hr) throws Exception { JsonNode n = objectMapper.readValue(hr.getContent(), JsonNode.class); Documents.setRevision(o, n.get("rev").textValue()); return null; } @Override public Void error(HttpResponse hr) { if (hr.getCode() == HttpStatus.CONFLICT) { throw new UpdateConflictException(id, Documents .getRevision(o)); } return super.error(hr); } }); }
StreamedCouchDbConnector extends StdCouchDbConnector { @Override public void update(final Object o) { Assert.notNull(o, "Document cannot be null"); final String id = Documents.getId(o); assertDocIdHasValue(id); HttpEntity entity = createHttpEntity(o); restTemplate.put(dbURI.append(id).toString(), entity, new StdResponseHandler<Void>() { @Override public Void success(HttpResponse hr) throws Exception { JsonNode n = objectMapper.readValue(hr.getContent(), JsonNode.class); Documents.setRevision(o, n.get("rev").textValue()); return null; } @Override public Void error(HttpResponse hr) { if (hr.getCode() == HttpStatus.CONFLICT) { throw new UpdateConflictException(id, Documents .getRevision(o)); } return super.error(hr); } }); } }
StreamedCouchDbConnector extends StdCouchDbConnector { @Override public void update(final Object o) { Assert.notNull(o, "Document cannot be null"); final String id = Documents.getId(o); assertDocIdHasValue(id); HttpEntity entity = createHttpEntity(o); restTemplate.put(dbURI.append(id).toString(), entity, new StdResponseHandler<Void>() { @Override public Void success(HttpResponse hr) throws Exception { JsonNode n = objectMapper.readValue(hr.getContent(), JsonNode.class); Documents.setRevision(o, n.get("rev").textValue()); return null; } @Override public Void error(HttpResponse hr) { if (hr.getCode() == HttpStatus.CONFLICT) { throw new UpdateConflictException(id, Documents .getRevision(o)); } return super.error(hr); } }); } StreamedCouchDbConnector(String databaseName, CouchDbInstance dbInstance);  StreamedCouchDbConnector(String databaseName, CouchDbInstance dbi, ObjectMapperFactory om); }
StreamedCouchDbConnector extends StdCouchDbConnector { @Override public void update(final Object o) { Assert.notNull(o, "Document cannot be null"); final String id = Documents.getId(o); assertDocIdHasValue(id); HttpEntity entity = createHttpEntity(o); restTemplate.put(dbURI.append(id).toString(), entity, new StdResponseHandler<Void>() { @Override public Void success(HttpResponse hr) throws Exception { JsonNode n = objectMapper.readValue(hr.getContent(), JsonNode.class); Documents.setRevision(o, n.get("rev").textValue()); return null; } @Override public Void error(HttpResponse hr) { if (hr.getCode() == HttpStatus.CONFLICT) { throw new UpdateConflictException(id, Documents .getRevision(o)); } return super.error(hr); } }); } StreamedCouchDbConnector(String databaseName, CouchDbInstance dbInstance);  StreamedCouchDbConnector(String databaseName, CouchDbInstance dbi, ObjectMapperFactory om); @Override void create(final Object o); @Override void create(String id, Object node); @Override PurgeResult purge(Map<String, List<String>> revisionsToPurge); @Override void update(final Object o); }
StreamedCouchDbConnector extends StdCouchDbConnector { @Override public void update(final Object o) { Assert.notNull(o, "Document cannot be null"); final String id = Documents.getId(o); assertDocIdHasValue(id); HttpEntity entity = createHttpEntity(o); restTemplate.put(dbURI.append(id).toString(), entity, new StdResponseHandler<Void>() { @Override public Void success(HttpResponse hr) throws Exception { JsonNode n = objectMapper.readValue(hr.getContent(), JsonNode.class); Documents.setRevision(o, n.get("rev").textValue()); return null; } @Override public Void error(HttpResponse hr) { if (hr.getCode() == HttpStatus.CONFLICT) { throw new UpdateConflictException(id, Documents .getRevision(o)); } return super.error(hr); } }); } StreamedCouchDbConnector(String databaseName, CouchDbInstance dbInstance);  StreamedCouchDbConnector(String databaseName, CouchDbInstance dbi, ObjectMapperFactory om); @Override void create(final Object o); @Override void create(String id, Object node); @Override PurgeResult purge(Map<String, List<String>> revisionsToPurge); @Override void update(final Object o);  }