Examples of FakeHttpServletRequest


Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

    mockControl.reset();
  }

  private void setupRequest(String pathInfo, String actualMethod, String overrideMethod)
      throws IOException {
    FakeHttpServletRequest fakeReq = new FakeHttpServletRequest("/social/rest", pathInfo, "");
    fakeReq.setPathInfo(pathInfo);
    fakeReq.setParameter(DataServiceServlet.X_HTTP_METHOD_OVERRIDE, overrideMethod);
    fakeReq.setCharacterEncoding("UTF-8");
    if (!("GET").equals(actualMethod) && !("HEAD").equals(actualMethod)) {
      fakeReq.setPostData("", "UTF-8");
    }
    fakeReq.setMethod(actualMethod);
    fakeReq.setAttribute(AuthInfo.Attribute.SECURITY_TOKEN.getId(), FAKE_GADGET_TOKEN);
    fakeReq.setContentType(ContentTypes.OUTPUT_JSON_CONTENT_TYPE);
    req = fakeReq;
  }
View Full Code Here

Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

  }

  protected String getResponse(String path, String method,
      Map<String, String> extraParams, String postData, String format,
      String contentType) throws Exception {
    FakeHttpServletRequest req = new FakeHttpServletRequest();
    req.setCharacterEncoding("UTF-8");
    req.setPathInfo(path);
    req.setParameter("format",format);
    req.setParameter("X-HTTP-Method-Override", method);
    req.setAttribute(AuthInfo.Attribute.SECURITY_TOKEN.getId(), FAKE_GADGET_TOKEN);
    req.setContentType(contentType);
    for (Map.Entry<String,String> entry : extraParams.entrySet()) {
      req.setParameter(entry.getKey(), entry.getValue());
    }

    if (!("GET").equals(method) && !("HEAD").equals(method)) {
      if (postData == null) {
        postData = "";
      }
      req.setPostData(postData.getBytes());
    }
    req.setMethod(method);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(outputStream);
    EasyMock.expect(res.getWriter()).andReturn(writer);
    res.setCharacterEncoding("UTF-8");
View Full Code Here

Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

  }

  @Test
  public void testInvalidRequests() throws Exception {
    // Empty request
    req = new FakeHttpServletRequest();
    Assert.assertNull(authHandler.getSecurityTokenFromRequest(req));

    // Old behavior, no longer supported
    req = new FakeHttpServletRequest().setHeader("Authorization", "Token token=\"1234\"");
    Assert.assertNull(authHandler.getSecurityTokenFromRequest(req));

    req = new FakeHttpServletRequest().setHeader("Authorization", "OAuth 1234");
    Assert.assertNull(authHandler.getSecurityTokenFromRequest(req));
  }
View Full Code Here

Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

  }

  @Test
  public void testSecurityToken() throws Exception {
    // security token in request
    req = new FakeHttpServletRequest("http://example.org/rpc?st=1234");
    Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req));
  }
View Full Code Here

Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

  }

  @Test
  public void testOAuth1() throws Exception {
    // An OAuth 1.0 request, we should not process this.
    req = new FakeHttpServletRequest()
        .setHeader("Authorization", "OAuth oauth_signature_method=\"RSA-SHA1\"");
    SecurityToken token = authHandler.getSecurityTokenFromRequest(req);
    Assert.assertNull(token);
  }
View Full Code Here

Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

    Assert.assertNull(token);
  }

  @Test
  public void testOAuth2Header() throws Exception {
    req = new FakeHttpServletRequest("https://www.example.org/")
        .setHeader("Authorization", "OAuth2  1234");
    Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req));

    req = new FakeHttpServletRequest("https://www.example.org/")
        .setHeader("Authorization", "   OAuth2    1234 ");
    Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req));

    req = new FakeHttpServletRequest("https://www.example.org/")
        .setHeader("Authorization", "OAuth2 1234 x=1,y=\"2 2 2\"");
    Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req));

    req = new FakeHttpServletRequest("http://www.example.org/")
        .setHeader("Authorization", "OAuth2 1234");
    Assert.assertNull(authHandler.getSecurityTokenFromRequest(req));
  }
View Full Code Here

Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

  }

  @Test
  public void testOAuth2Param() throws Exception
  {
    req = new FakeHttpServletRequest("https://www.example.com?oauth_token=1234");
    Assert.assertEquals(expectedToken, authHandler.getSecurityTokenFromRequest(req));

    req = new FakeHttpServletRequest("https://www.example.com?oauth_token=1234&oauth_signature_method=RSA-SHA1");
    Assert.assertNull(authHandler.getSecurityTokenFromRequest(req));
  }
View Full Code Here

Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

  @Test
  public void testJsonFromRequest() throws Exception {
    HttpServletRequest fakeRequest;
    for (String badParms : ImmutableList.of("x=1", "x=1&callback=")) {
      fakeRequest = new FakeHttpServletRequest("http://foo.com/gadgets/rpc?" + badParms);
      assertNull(JsonConversionUtil.fromRequest(fakeRequest));
    }
   }
View Full Code Here

Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

    mockControl.reset();
  }

  private void setupRequest(String pathInfo, String actualMethod, String overrideMethod)
      throws IOException {
    FakeHttpServletRequest fakeReq = new FakeHttpServletRequest("/social/rest", pathInfo, "");
    fakeReq.setPathInfo(pathInfo);
    fakeReq.setParameter(DataServiceServlet.X_HTTP_METHOD_OVERRIDE, overrideMethod);
    fakeReq.setCharacterEncoding("UTF-8");
    if (!("GET").equals(actualMethod) && !("HEAD").equals(actualMethod)) {
      fakeReq.setPostData("", "UTF-8");
    }
    fakeReq.setMethod(actualMethod);
    fakeReq.setAttribute(AuthInfoUtil.Attribute.SECURITY_TOKEN.getId(), FAKE_GADGET_TOKEN);
    fakeReq.setContentType(ContentTypes.OUTPUT_JSON_CONTENT_TYPE);
    req = fakeReq;
  }
View Full Code Here

Examples of org.apache.shindig.common.testing.FakeHttpServletRequest

   * Test that requests must be both POST and have a multipart
   * content type.
   */
  @Test
  public void testIsMultipartContent() {
    FakeHttpServletRequest request = new FakeHttpServletRequest();

    request.setMethod("GET");
    assertFalse(multipartFormParser.isMultipartContent(request));

    request.setMethod("POST");
    assertFalse(multipartFormParser.isMultipartContent(request));

    request.setContentType("multipart/form-data");
    assertTrue(multipartFormParser.isMultipartContent(request));

    request.setMethod("GET");
    assertFalse(multipartFormParser.isMultipartContent(request));
}
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.