예제 #1
0
  @Test
  public void canSaveWithAnEmptyObjectIdAsString() throws Exception {

    ExposableFriend john = new ExposableFriend("Robert");

    collection.save(john);

    ExposableFriend result = collection.findOne().as(ExposableFriend.class);
    assertThat(result).isNotNull();
    assertThat(result.getId()).isNotNull();
  }
예제 #2
0
  @Test
  public void canSaveWithObjectIdAsString() throws Exception {

    String id = ObjectId.get().toString();
    ExposableFriend john = new ExposableFriend(id, "Robert");

    collection.save(john);

    ExposableFriend result = collection.findOne().as(ExposableFriend.class);
    assertThat(result).isNotNull();
    assertThat(result.getId()).isEqualTo(id);
  }
예제 #3
0
  @Test
  public void canFindWithStringAsObjectId() {
    /* given */
    String id = ObjectId.get().toString();
    ExposableFriend friend = new ExposableFriend(id, "John");
    collection.save(friend);

    /* when */
    Iterator<ExposableFriend> friends =
        collection.find(withOid(friend.getId())).as(ExposableFriend.class).iterator();

    /* then */
    ExposableFriend john = friends.next();
    assertThat(john.getId()).isEqualTo(id);
    assertThat(john.getName()).isEqualTo("John");
    assertThat(friends.hasNext()).isFalse();
  }
예제 #4
0
  @Test
  public void canUpdateWithObjectIdAsString() throws Exception {
    String id = ObjectId.get().toString();
    ExposableFriend robert = new ExposableFriend(id, "Robert");

    collection.save(robert);
    String johnId = robert.getId();

    robert.setName("Hue"); // <-- "famous" french Robert
    collection.save(robert);

    ExposableFriend robertHue = collection.findOne("{_id:#}", johnId).as(ExposableFriend.class);
    assertThat(robertHue.getId()).isEqualTo(johnId);
    assertThat(robertHue.getName()).isEqualTo("Hue");
  }