Package org.apache.shindig.protocol

Examples of org.apache.shindig.protocol.RestHandler


  }

  @Test
  public void testHandleGetSuportedFields() throws Exception {
    String path = "/activities/@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


  }

  @Test
  public void testHandleSimpleGetInvalidateViewer() throws Exception {
    String path = "/cache/invalidate";
    RestHandler operation = registry.getRestHandler(path, "GET");

    invalidationService.invalidateUserResources(
        eq(ImmutableSet.of("userX")),
        eq(token));
    expectLastCall();

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

  }

  @Test
  public void testAllowConsumerAuthInvalidateAppResource() throws Exception {
    String path = "/cache/invalidate";
    RestHandler operation = registry.getRestHandler(path, "POST");
    params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"});
    token.setAuthenticationMode(AuthenticationMode.OAUTH_CONSUMER_REQUEST.name());
    invalidationService.invalidateApplicationResources(
        eq(ImmutableSet.of(Uri.parse("http://www.example.org/gadget.xml"))),
        eq(token));
    expectLastCall();

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

  }

  @Test
  public void testFailTokenAuthInvalidateAppResource() throws Exception {
    String path = "/cache/invalidate";
    RestHandler operation = registry.getRestHandler(path, "POST");
    params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"});

    try {
      operation.execute(params, null, token, converter).get();
      fail("Expected error");
    } catch (ExecutionException ee) {
      assertTrue(ee.getCause() instanceof ProtocolException);
    }
  }
View Full Code Here

  }

  @Test
  public void testFailInvalidateNoApp() throws Exception {
    String path = "/cache/invalidate";
    RestHandler operation = registry.getRestHandler(path, "POST");
    params.put(InvalidationHandler.KEYS_PARAM, new String[]{"http://www.example.org/gadget.xml"});

    try {
      token.setAppId("");
      token.setAppUrl("");
      operation.execute(params, null, token, converter).get();
      fail("Expected error");
    } catch (ExecutionException ee) {
      assertTrue(ee.getCause() instanceof ProtocolException);
    }
  }
View Full Code Here

  }

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

    DataCollection data = new DataCollection(null);
    Set<UserId> userIdSet = Sets.newLinkedHashSet(JOHN_DOE);
    userIdSet.add(new UserId(UserId.Type.userId, "jane.doe"));
    org.easymock.EasyMock.expect(appDataService.getPersonData(eq(userIdSet),
        eq(new GroupId(GroupId.Type.self, null)),
        eq("appId"), eq(ImmutableSet.<String>of()), eq(token)))
        .andReturn(ImmediateFuture.newInstance(data));

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

  }

  @Test
  public void testHandleGetWithoutFields() throws Exception {
    String path = "/appdata/john.doe/@friends/appId";
    RestHandler operation = registry.getRestHandler(path, "GET");

    Map<String, String[]> params = Maps.newHashMap();
    params.put("fields", new String[]{"pandas"});

    DataCollection data = new DataCollection(null);
    org.easymock.EasyMock.expect(appDataService.getPersonData(eq(JOHN_DOE),
        eq(new GroupId(GroupId.Type.friends, null)),
        eq("appId"), eq(ImmutableSet.of("pandas")), eq(token)))
        .andReturn(ImmediateFuture.newInstance(data));

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

    verify();
  }

  private Future<?> setupPostData(String method) throws ProtocolException {
    String path = "/appdata/john.doe/@self/appId";
    RestHandler operation = registry.getRestHandler(path, method);

    String jsonAppData = "{pandas: 'are fuzzy'}";

    Map<String, String[]> params = Maps.newHashMap();
    params.put("fields", new String[]{"pandas"});

    HashMap<String, String> values = Maps.newHashMap();
    org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonAppData), eq(Map.class)))
        .andReturn(values);

    org.easymock.EasyMock.expect(appDataService.updatePersonData(eq(JOHN_DOE.iterator().next()),
        eq(new GroupId(GroupId.Type.self, null)),
        eq("appId"), eq(ImmutableSet.of("pandas")), eq(values), eq(token)))
        .andReturn(ImmediateFuture.newInstance((Void) null));
    replay();
    return operation.execute(params, new StringReader(jsonAppData), token, converter);
  }
View Full Code Here

   * @throws Exception if the test fails
   */
  @Test
  public void testHandleNullPostDataKeys() throws Exception {
    String path = "/appdata/john.doe/@self/appId";
    RestHandler operation = registry.getRestHandler(path, "POST");
    String jsonAppData = "{pandas: 'are fuzzy'}";

    Map<String, String[]> params = Maps.newHashMap();
    params.put("fields", new String[]{"pandas"});

    HashMap<String, String> values = Maps.newHashMap();
    // create an invalid set of app data and inject
    values.put("Aokkey", "an ok key");
    values.put("", "an empty value");
    org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonAppData), eq(Map.class)))
        .andReturn(values);

    replay();
    try {
      operation.execute(params, new StringReader(jsonAppData), token, converter).get();
      fail();
    } catch (ExecutionException ee) {
      assertEquals(HttpServletResponse.SC_BAD_REQUEST,
          ((ProtocolException) ee.getCause()).getCode());
      // was expecting an Exception
View Full Code Here

   * @throws Exception if the test fails
   */
  @Test
  public void testHandleInvalidPostDataKeys() throws Exception {
    String path = "/appdata/john.doe/@self/appId";
    RestHandler operation = registry.getRestHandler(path, "POST");
    String jsonAppData = "{pandas: 'are fuzzy'}";

    Map<String, String[]> params = Maps.newHashMap();
    params.put("fields", new String[]{"pandas"});

    HashMap<String, String> values = Maps.newHashMap();
    // create an invalid set of app data and inject
    values.put("Aokkey", "an ok key");
    values.put("a bad key", "a good value");
    org.easymock.EasyMock.expect(converter.convertToObject(eq(jsonAppData), eq(Map.class)))
        .andReturn(values);

    replay();
    try {
      operation.execute(params, new StringReader(jsonAppData), token, converter).get();
      fail();
    } catch (ExecutionException ee) {
      assertEquals(HttpServletResponse.SC_BAD_REQUEST,
          ((ProtocolException) ee.getCause()).getCode());
    }
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.