public void testUpdateExpectedAppData() throws Exception {
    // Delete the data
    db.updatePersonData(
        CANON_USER,
        SELF_GROUP,
        APP_ID,
        null,
        ImmutableMap.of("count", "10", "newvalue", "20"),
        new FakeGadgetToken());

    // Fetch the remaining and test
    DataCollection responseItem =
        db.getPersonData(
                ImmutableSet.of(CANON_USER),
                SELF_GROUP,
                APP_ID,
                Collections.<String>emptySet(),
                new FakeGadgetToken())
            .get();

    assertFalse(responseItem.getEntry().isEmpty());
    assertFalse(responseItem.getEntry().get(CANONICAL_USER_ID).isEmpty());

    assertSame(3, responseItem.getEntry().get(CANONICAL_USER_ID).size());
    assertTrue(responseItem.getEntry().get(CANONICAL_USER_ID).containsKey("count"));
    assertEquals("10", responseItem.getEntry().get(CANONICAL_USER_ID).get("count"));
    assertTrue(responseItem.getEntry().get(CANONICAL_USER_ID).containsKey("newvalue"));
    assertEquals("20", responseItem.getEntry().get(CANONICAL_USER_ID).get("newvalue"));
  }
  public void testGetPersonOneAppDataField() throws Exception {
    Person person = db.getPerson(CANON_USER, ImmutableSet.of("id", "appData.size"), token).get();

    assertNotNull("Canonical user not found", person);
    assertEquals("Canonical user has wrong id", "canonical", person.getId());
    assertEquals(
        "Canonical user has wrong app data", ImmutableMap.of("size", "100"), person.getAppData());
  }
  public void testGetPersonDefaultFields() throws Exception {
    Person person = db.getPerson(CANON_USER, Person.Field.DEFAULT_FIELDS, token).get();

    assertNotNull("Canonical user not found", person);
    assertNotNull("Canonical user has no id", person.getId());
    assertNotNull("Canonical user has no name", person.getName());
    assertNotNull("Canonical user has no thumbnail", person.getThumbnailUrl());
  }
  public void testDeleteExpectedActivity() throws Exception {
    db.deleteActivities(
        CANON_USER, SELF_GROUP, APP_ID, ImmutableSet.of(APP_ID), new FakeGadgetToken());

    // Try to fetch the activity
    try {
      db.getActivity(
              CANON_USER,
              SELF_GROUP,
              APP_ID,
              ImmutableSet.of("appId", "body", "mediaItems"),
              APP_ID,
              new FakeGadgetToken())
          .get();
      fail();
    } catch (ProtocolException sse) {
      assertEquals(HttpServletResponse.SC_BAD_REQUEST, sse.getCode());
    }
  }
 public void testGetExpectedActivitiesForPlural() throws Exception {
   RestfulCollection<Activity> responseItem =
       db.getActivities(
               ImmutableSet.of(CANON_USER, JOHN_DOE),
               SELF_GROUP,
               APP_ID,
               Collections.<String>emptySet(),
               null,
               new FakeGadgetToken())
           .get();
   assertSame(3, responseItem.getTotalResults());
 }
 public void testGetExpectedActivity() throws Exception {
   Activity activity =
       db.getActivity(
               CANON_USER,
               SELF_GROUP,
               APP_ID,
               ImmutableSet.of("appId", "body", "mediaItems"),
               APP_ID,
               new FakeGadgetToken())
           .get();
   assertNotNull(activity);
   // Check that some fields are fetched and others are not
   assertNotNull(activity.getBody());
   assertNull(activity.getBodyId());
 }
  public void testGetExpectedAppData() throws Exception {
    DataCollection responseItem =
        db.getPersonData(
                ImmutableSet.of(CANON_USER),
                SELF_GROUP,
                APP_ID,
                Collections.<String>emptySet(),
                new FakeGadgetToken())
            .get();
    assertFalse(responseItem.getEntry().isEmpty());
    assertFalse(responseItem.getEntry().get(CANONICAL_USER_ID).isEmpty());

    assertSame(2, responseItem.getEntry().get(CANONICAL_USER_ID).size());
    assertTrue(responseItem.getEntry().get(CANONICAL_USER_ID).containsKey("count"));
    assertTrue(responseItem.getEntry().get(CANONICAL_USER_ID).containsKey("size"));
  }
  public void testGetExpectedUsersForPlural() throws Exception {
    CollectionOptions options = new CollectionOptions();
    options.setSortBy(PersonService.TOP_FRIENDS_SORT);
    options.setSortOrder(SortOrder.ascending);
    options.setFilter(null);
    options.setFilterOperation(FilterOperation.contains);
    options.setFilterValue("");
    options.setFirst(0);
    options.setMax(20);

    RestfulCollection<Person> responseItem =
        db.getPeople(
                ImmutableSet.of(JOHN_DOE, JANE_DOE),
                new GroupId(GroupId.Type.friends, null),
                options,
                Collections.<String>emptySet(),
                token)
            .get();
    assertNotNull(responseItem);
    assertEquals(4, responseItem.getTotalResults());
    // Test a couple of users
    assertEquals("john.doe", responseItem.getEntry().get(0).getId());
    assertEquals("jane.doe", responseItem.getEntry().get(1).getId());
  }
 public void testGetPersonAllFields() throws Exception {
   Person person = db.getPerson(CANON_USER, Person.Field.ALL_FIELDS, token).get();
   assertNotNull("Canonical user not found", person);
 }