@Test
  public final void givenNewHometown_whenUpdate_thenNewHometownPersisted() {
    // create and insert person document
    JsonDocument doc = insertRandomPersonDocument();

    // update person
    Person expected = converter.fromDocument(doc);
    String updatedHomeTown = RandomStringUtils.randomAlphabetic(12);
    expected.setHomeTown(updatedHomeTown);
    personService.update(expected);

    // check results
    JsonDocument actual = bucket.get(expected.getId());
    assertNotNull(actual);
    assertNotNull(actual.content());
    assertEquals(expected.getHomeTown(), actual.content().getString("homeTown"));

    // cleanup
    bucket.remove(expected.getId());
  }
  @Test
  public final void givenPersons_whenUpdateBulk_thenPersonsAreUpdated() {

    List<String> ids = new ArrayList<>();

    // add some person documents
    for (int i = 0; i < 5; i++) {
      ids.add(insertRandomPersonDocument().id());
    }

    // load persons from Couchbase
    List<Person> persons = new ArrayList<>();
    for (String id : ids) {
      persons.add(converter.fromDocument(bucket.get(id)));
    }

    // modify persons
    for (Person person : persons) {
      person.setHomeTown(RandomStringUtils.randomAlphabetic(10));
    }

    // perform bulk update
    personService.updateBulk(persons);

    // check results
    for (Person person : persons) {
      JsonDocument doc = bucket.get(person.getId());
      assertEquals(person.getName(), doc.content().getString("name"));
      assertEquals(person.getHomeTown(), doc.content().getString("homeTown"));
    }

    // cleanup
    for (String id : ids) {
      bucket.remove(id);
    }
  }
 private JsonDocument insertRandomPersonDocument() {
   Person expected = randomPersonWithId();
   JsonDocument doc = converter.toDocument(expected);
   return bucket.insert(doc);
 }