.getFirstContentAsLong();
// Add a vehicle
String firebirdId = "99";
VehicleEntity firebird = VehicleEntity.newVehicle(firebirdId, VehicleType.CAR, "Pontiac", "Firebird", "1969", "Black");
WriteResponse putResponse = couchDatabase
.put()
.entity(firebird)
.execute();
assertEquals(putResponse.getDocumentId(), firebirdId);
assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
assertNotNull(putResponse.getDocumentRevision());
// Check count
long newVehicleCount = couchDatabase
.get()
.document(couchViewQuery)
.execute()
.getFirstContentAsLong();
assertEquals(newVehicleCount, initialVehicleCount + 1);
// Retrieve the vehicle we just added.
VehicleEntity foundFirebird = couchDatabase
.get()
.entity(VehicleEntity.class, firebirdId)
.execute()
.getFirstEntity();
assertEquals(foundFirebird.getId(), firebird.getId());
assertEquals(foundFirebird.getRevision(), putResponse.getDocumentRevision());
assertEquals(foundFirebird.getVehicleType(), firebird.getVehicleType());
assertEquals(foundFirebird.getMake(), firebird.getMake());
assertEquals(foundFirebird.getModel(), firebird.getModel());
assertEquals(foundFirebird.getYear(), firebird.getYear());
assertEquals(foundFirebird.getColor(), firebird.getColor());
// Retrieve the raw document and ensure the id is not part of the entity body.
GetDocumentResponse response = couchDatabase
.get()
.document(firebirdId)
.execute();
TextDocument textDocument = response.getFirstDocument();
String content = textDocument.getContent();
ObjectMapper objectMapper = new ObjectMapper();
Map map = objectMapper.readValue(content, Map.class);
Map entity = (Map) map.get("entity");
assertFalse(entity.containsKey("id"), "The entity body stored in couch contains the id.");
// Change color to blue and update
foundFirebird.setColor("Green");
putResponse = couchDatabase
.put()
.entity(foundFirebird)
.execute();
assertEquals(putResponse.getDocumentId(), firebirdId);
assertEquals(putResponse.getHttpStatus(), CouchHttpStatus.CREATED);
assertNotNull(putResponse.getDocumentRevision());
// Get and ensure color was updated.
foundFirebird = couchDatabase
.get()
.entity(VehicleEntity.class, firebirdId)
.execute()
.getFirstEntity();
assertEquals(foundFirebird.getColor(), "Green");
assertEquals(foundFirebird.getRevision(), putResponse.getDocumentRevision());
}