@Test public void create_should_post_if_id_is_missing() throws IOException { final ByteArrayOutputStream output = new ByteArrayOutputStream(); doAnswer(new MarshallEntityAndReturnAnswer(output, HttpResponseStub.valueOf(201, OK_RESPONSE_WITH_ID_AND_REV))).when(httpClient).post(anyString(), any(HttpEntity.class)); dbCon.create(td); ArgumentCaptor<HttpEntity> ac = ArgumentCaptor.forClass(HttpEntity.class); verify(httpClient).post(eq(TEST_DB_PATH), ac.capture()); assertEquals("some_id", td.getId()); assertEquals("123D123", td.getRevision()); assertEqualJson("create_with_no_id.json", Charset.forName("UTF-8"), output.toByteArray()); }
@Override public void create(final Object o) { Assert.notNull(o, "Document may not be null"); Assert.isTrue(Documents.isNew(o), "Object must be new"); HttpEntity entity = createHttpEntity(o); String id = Documents.getId(o); DocumentOperationResult result; if (id != null && id.length() != 0) { result = restTemplate.put(URIWithDocId(id), entity, revisionHandler); } else { result = restTemplate.post(dbURI.toString(), entity, revisionHandler); Documents.setId(o, result.getId()); } Documents.setRevision(o, result.getRevision()); }
StreamedCouchDbConnector extends StdCouchDbConnector { @Override public void create(final Object o) { Assert.notNull(o, "Document may not be null"); Assert.isTrue(Documents.isNew(o), "Object must be new"); HttpEntity entity = createHttpEntity(o); String id = Documents.getId(o); DocumentOperationResult result; if (id != null && id.length() != 0) { result = restTemplate.put(URIWithDocId(id), entity, revisionHandler); } else { result = restTemplate.post(dbURI.toString(), entity, revisionHandler); Documents.setId(o, result.getId()); } Documents.setRevision(o, result.getRevision()); } }
StreamedCouchDbConnector extends StdCouchDbConnector { @Override public void create(final Object o) { Assert.notNull(o, "Document may not be null"); Assert.isTrue(Documents.isNew(o), "Object must be new"); HttpEntity entity = createHttpEntity(o); String id = Documents.getId(o); DocumentOperationResult result; if (id != null && id.length() != 0) { result = restTemplate.put(URIWithDocId(id), entity, revisionHandler); } else { result = restTemplate.post(dbURI.toString(), entity, revisionHandler); Documents.setId(o, result.getId()); } Documents.setRevision(o, result.getRevision()); } StreamedCouchDbConnector(String databaseName, CouchDbInstance dbInstance);  StreamedCouchDbConnector(String databaseName, CouchDbInstance dbi, ObjectMapperFactory om); }
StreamedCouchDbConnector extends StdCouchDbConnector { @Override public void create(final Object o) { Assert.notNull(o, "Document may not be null"); Assert.isTrue(Documents.isNew(o), "Object must be new"); HttpEntity entity = createHttpEntity(o); String id = Documents.getId(o); DocumentOperationResult result; if (id != null && id.length() != 0) { result = restTemplate.put(URIWithDocId(id), entity, revisionHandler); } else { result = restTemplate.post(dbURI.toString(), entity, revisionHandler); Documents.setId(o, result.getId()); } Documents.setRevision(o, result.getRevision()); } 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 create(final Object o) { Assert.notNull(o, "Document may not be null"); Assert.isTrue(Documents.isNew(o), "Object must be new"); HttpEntity entity = createHttpEntity(o); String id = Documents.getId(o); DocumentOperationResult result; if (id != null && id.length() != 0) { result = restTemplate.put(URIWithDocId(id), entity, revisionHandler); } else { result = restTemplate.post(dbURI.toString(), entity, revisionHandler); Documents.setId(o, result.getId()); } Documents.setRevision(o, result.getRevision()); } 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);  }