Package org.apache.shindig.protocol

Examples of org.apache.shindig.protocol.RestHandler


  @Test
  public void testHandleDelete() throws Exception {
    Map<String, String[]> params = Maps.newHashMap();
    params.put("fields", new String[]{"pandas"});
    String path = "/appdata/john.doe/@self/appId";
    RestHandler operation = registry.getRestHandler(path, "DELETE");

    EasyMock.expect(appDataService.deletePersonData(eq(JOHN_DOE.iterator().next()),
        eq(new GroupId(GroupId.Type.self, null)),
        eq("appId"), eq(ImmutableSet.of("pandas")), eq(token)))
        .andReturn(ImmediateFuture.newInstance((Void) null));

    replay();
    assertNull(operation.execute(params, null, token, converter).get());
    verify();
  }
View Full Code Here


  }

  @Test
  public void testSupportedFields() throws Exception {
    String path = "/albums/@supportedFields";
    RestHandler operation = registry.getRestHandler(path, "GET");

    replay();
    @SuppressWarnings("unchecked")
    List<Object> received = (List<Object>) operation.execute(Maps.<String, String[]>newHashMap(),
        null, token, converter).get();
    assertEquals(3, received.size());
    assertEquals("id", received.get(0).toString());
    assertEquals("title", received.get(1).toString());
    assertEquals("location", received.get(2).toString());
View Full Code Here

  }

  /* Helper for retrieving groups. */
  private void assertHandleGetForGroup(GroupId.Type group) throws Exception {
    String path = "/activitystreams/john.doe/@" + group.toString();
    RestHandler operation = registry.getRestHandler(path, "GET");

    List<ActivityEntry> entries = ImmutableList.of();
    RestfulCollection<ActivityEntry> data = new RestfulCollection<ActivityEntry>(entries);
    org.easymock.EasyMock.expect(service.getActivityEntries(eq(JOHN_DOE),
       eq(new GroupId(group, null)), (String)isNull(), eq(ImmutableSet.<String>of()),
        org.easymock.EasyMock.isA(CollectionOptions.class), eq(token))).
        andReturn(ImmediateFuture.newInstance(data));

    replay();
    assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(),
        null, token, converter).get());
    verify();
    reset();
  }
View Full Code Here

  }

  @Test
  public void testHandleGetPlural() throws Exception {
    String path = "/activitystreams/john.doe,jane.doe/@self/@app";
    RestHandler operation = registry.getRestHandler(path, "GET");

    List<ActivityEntry> entries = ImmutableList.of();
    RestfulCollection<ActivityEntry> data = new RestfulCollection<ActivityEntry>(entries);
    Set<UserId> userIdSet = Sets.newLinkedHashSet(JOHN_DOE);
    userIdSet.add(new UserId(UserId.Type.userId, "jane.doe"));
    org.easymock.EasyMock.expect(service.getActivityEntries(eq(userIdSet),
        eq(new GroupId(GroupId.Type.self, null)), eq("appId"),eq(ImmutableSet.<String>of()),
        org.easymock.EasyMock.isA((CollectionOptions.class)), eq(token))).andReturn(
          ImmediateFuture.newInstance(data));

    replay();
    assertEquals(data, operation.execute(Maps.<String, String[]>newHashMap(),
        null, token, converter).get());
    verify();
    reset();
  }
View Full Code Here

  }

  @Test
  public void testHandleGetActivityEntryById() throws Exception {
    String path = "/activitystreams/john.doe/@friends/@app/myObjectId123"// TODO: change id=1 in DB for consistency
    RestHandler operation = registry.getRestHandler(path, "GET");

    ActivityEntry entry = new ActivityEntryImpl();
    org.easymock.EasyMock.expect(service.getActivityEntry(eq(JOHN_DOE.iterator().next()),
        eq(new GroupId(GroupId.Type.friends, null)),
        eq("appId"), eq(ImmutableSet.<String>of()), eq("myObjectId123"), eq(token))).andReturn(
        ImmediateFuture.newInstance(entry));

    replay();
    assertEquals(entry, operation.execute(Maps.<String, String[]>newHashMap(),
        null, token, converter).get());
    verify();
    reset();
  }
View Full Code Here

  /* Helper for testing PUT and POST */
  private Future<?> setupBodyRequest(String method) throws ProtocolException {
    String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}";

    String path = "/activitystreams/john.doe/@self/@app";
    RestHandler operation = registry.getRestHandler(path, method);

    ActivityEntry entry = new ActivityEntryImpl();
    org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class)))
        .andReturn(entry);

    org.easymock.EasyMock.expect(service.createActivityEntry(eq(JOHN_DOE.iterator().next()),
        eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()),
        eq(entry), eq(token))).andReturn(ImmediateFuture.newInstance((ActivityEntry) null));
    replay();

    return operation.execute(Maps.<String, String[]>newHashMap(),
        new StringReader(jsonActivityEntry), token, converter);
  }
View Full Code Here

  @Test
  public void testHandlePost() throws Exception {
    String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}";

    String path = "/activitystreams/john.doe/@self/@app";
    RestHandler operation = registry.getRestHandler(path, "POST");

    ActivityEntry entry = new ActivityEntryImpl();
    org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class)))
        .andReturn(entry);

    org.easymock.EasyMock.expect(service.createActivityEntry(eq(JOHN_DOE.iterator().next()),
        eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()),
        eq(entry), eq(token))).andReturn(ImmediateFuture.newInstance((ActivityEntry) null));
    replay();

    Future<?> future = operation.execute(Maps.<String, String[]>newHashMap(),
        new StringReader(jsonActivityEntry), token, converter);
    assertNull(future.get());
    verify();
    reset();
  }
View Full Code Here

  @Test
  public void testHandlePut() throws Exception {
    String jsonActivityEntry = "{title: 'hi mom!', object: {id: 'testObject'}}";

    String path = "/activitystreams/john.doe/@self/@app/testObject";
    RestHandler operation = registry.getRestHandler(path, "PUT");

    ActivityEntry entry = new ActivityEntryImpl();
    org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonActivityEntry), eq(ActivityEntry.class)))
        .andReturn(entry);

    org.easymock.EasyMock.expect(service.updateActivityEntry(eq(JOHN_DOE.iterator().next()),
        eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.<String>of()),
        eq(entry), eq("testObject"), eq(token))).andReturn(ImmediateFuture.newInstance((ActivityEntry) null));
    replay();

    Future<?> future = operation.execute(Maps.<String, String[]>newHashMap(),
        new StringReader(jsonActivityEntry), token, converter);
    assertNull(future.get());
    verify();
    reset();
  }
View Full Code Here

  }

  @Test
  public void testHandleDelete() throws Exception {
    String path = "/activitystreams/john.doe/@self/@app/myObjectId123";
    RestHandler operation = registry.getRestHandler(path, "DELETE");

    org.easymock.EasyMock.expect(service.deleteActivityEntries(eq(JOHN_DOE.iterator().next()),
        eq(new GroupId(GroupId.Type.self, null)), eq("appId"), eq(ImmutableSet.of("myObjectId123")),
        eq(token))).andReturn(ImmediateFuture.newInstance((Void) null));

    replay();
    assertNull(operation.execute(Maps.<String, String[]>newHashMap(), null,
        token, converter).get());
    verify();
    reset();
  }
View Full Code Here

  }

  @Test
  public void testHandleGetSupportedFields() throws Exception {
    String path = "/activitystreams/@supportedFields";
    RestHandler operation = registry.getRestHandler(path, "GET");

    replay();
    @SuppressWarnings("unchecked")
    List<Object> received = (List<Object>) operation.execute(Maps.<String, String[]>newHashMap(),
        null, token, converter).get();
    assertEquals(2, received.size());
    assertEquals("id", received.get(0).toString());
    assertEquals("title", received.get(1).toString());
View Full Code Here

TOP

Related Classes of org.apache.shindig.protocol.RestHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.