assertEquals(putResponse.getDocumentId(), documentThreeId);
assertNotNull(putResponse.getDocumentRevision());
String initialVersionThree = putResponse.getDocumentRevision();
// Perform a count, ensure we have three.
CouchViewQuery couchViewQuery = CouchViewQuery
.builder("entity", "countEntityType")
.key("person")
.includeDocs(false)
.build();
GetDocumentResponse countResponse = couchDatabase
.get()
.document(couchViewQuery)
.execute();
assertTrue(countResponse.isOk(), countResponse.getErrorReason());
assertEquals(countResponse.getFirstContentAsLong(), new Long(3));
// GET one by id
GetEntityResponse<PersonEntity> getResponse = couchDatabase
.get()
.entity(PersonEntity.class, documentOneId)
.execute();
assertEquals(getResponse.getHttpStatus(), CouchHttpStatus.OK);
assertEquals(getResponse.getContentType(), CouchMediaType.APPLICATION_JSON);
EntityDocument<PersonEntity> entityDocument = getResponse.getFirstDocument();
assertEquals(entityDocument.getDocumentId(), documentOneId);
assertEquals(entityDocument.getDocumentRevision(), initialVersionOne);
assertEquals(entityDocument.getEntityType(), "person");
assertEquals(entityDocument.getEntity(), personEntityOne);
assertNotNull(entityDocument.getDocumentRevision());
assertNotNull(entityDocument.getEntity().getVersion());
assertEquals(entityDocument.getDocumentRevision(), entityDocument.getEntity().getVersion());
// Validate that the 3rd-party objects were injected.
PersonEntity personEntity = entityDocument.getEntity();
assertSame(personEntity.getLogger(), logger);
assertSame(personEntity.getEventBus(), eventBus);
// GET two by id
getResponse = couchDatabase.get().entity(PersonEntity.class, documentTwoId).execute();
assertEquals(getResponse.getHttpStatus(), CouchHttpStatus.OK);
assertEquals(getResponse.getContentType(), CouchMediaType.APPLICATION_JSON);
entityDocument = getResponse.getFirstDocument();
assertEquals(entityDocument.getDocumentId(), documentTwoId);
assertEquals(entityDocument.getDocumentRevision(), initialVersionTwo);
assertEquals(entityDocument.getEntityType(), "person");
assertEquals(entityDocument.getEntity(), personEntityTwo);
// GET as a Document
GetDocumentResponse stringEntityResponse = couchDatabase.get().document(documentTwoId).execute();
assertEquals(stringEntityResponse.getHttpStatus(), CouchHttpStatus.OK);
assertEquals(stringEntityResponse.getContentType(), CouchMediaType.APPLICATION_JSON);
TextDocument stringEntityDoc = stringEntityResponse.getFirstDocument();
assertEquals(stringEntityDoc.getDocumentId(), documentTwoId);
assertEquals(stringEntityDoc.getDocumentRevision(), initialVersionTwo);
// GET one by key
CouchViewQuery viewQuery = CouchViewQuery.builder("person", "byName").limit(10).key("Farmer Fish").build();
getResponse = couchDatabase.get().entity(PersonEntity.class, viewQuery).execute();
assertEquals(getResponse.getHttpStatus(), CouchHttpStatus.OK);
assertEquals(getResponse.getContentType(), CouchMediaType.APPLICATION_JSON);
assertEquals(getResponse.getSize(), 1);
assertEquals(getResponse.getEntityClass(), PersonEntity.class);