private void expectPutAndReturnBody(AuthType authType, String putData, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("PUT") .setPostBody(putData.getBytes("UTF-8")) .setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("PUT"); expect(request.getParameter(MakeRequestHandler.POST_DATA_PARAM)) .andReturn(putData); }
private void expectPutAndReturnBody(AuthType authType, String putData, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("PUT") .setPostBody(putData.getBytes("UTF-8")) .setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("PUT"); expect(request.getParameter(MakeRequestHandler.POST_DATA_PARAM)) .andReturn(putData); }
private void expectDeleteAndReturnBody(AuthType authType, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("DELETE").setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("DELETE"); }
private void expectDeleteAndReturnBody(AuthType authType, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("DELETE").setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("DELETE"); }
private void expectHead(AuthType authType) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("HEAD").setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse("")); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("HEAD"); }
private void expectPatchAndReturnBody(AuthType authType, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("PATCH").setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("PATCH"); }
private void expectHead(AuthType authType) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("HEAD").setAuthType(authType); expect(pipeline.execute(req)).andReturn(new HttpResponse("")); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("HEAD"); }
private void expectPostAndReturnBody(AuthType authType, String postData, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("POST") .setPostBody(postData.getBytes("UTF-8")) .setAuthType(authType) .addHeader("Content-Type", "application/x-www-form-urlencoded"); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("POST"); expect(request.getParameter(MakeRequestHandler.POST_DATA_PARAM)) .andReturn(postData); }
private void expectPostAndReturnBody(AuthType authType, String postData, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("POST") .setPostBody(REQUEST_BODY.getBytes("UTF-8")) .setAuthType(authType) .addHeader("Content-Type", "application/x-www-form-urlencoded"); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("POST"); expect(request.getParameter(MakeRequestHandler.POST_DATA_PARAM)) .andReturn(REQUEST_BODY); }
private void expectPostAndReturnBody(AuthType authType, String postData, String response) throws Exception { HttpRequest req = new HttpRequest(REQUEST_URL).setMethod("POST") .setPostBody(postData.getBytes("UTF-8")) .setAuthType(authType) .addHeader("Content-Type", "application/x-www-form-urlencoded"); expect(pipeline.execute(req)).andReturn(new HttpResponse(response)); expect(request.getParameter(MakeRequestHandler.METHOD_PARAM)).andReturn("POST"); expect(request.getParameter(MakeRequestHandler.POST_DATA_PARAM)) .andReturn(postData); }
@Test(expected = IllegalArgumentException.class) public void createKeyWithoutSecurityToken() throws Exception { RequestAuthenticationInfo authInfo = newMockAuthInfo( true /* isSignOwner */, false /* isSignViewer */, ImmutableMap.<String, String>of()); replay(authInfo); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)); cache.createKey(request); }
@Test(expected = IllegalArgumentException.class) public void createKeyWithoutSecurityToken() throws Exception { RequestAuthenticationInfo authInfo = newMockAuthInfo( true /* isSignOwner */, false /* isSignViewer */, ImmutableMap.<String, String>of()); replay(authInfo); HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.SIGNED) .setOAuthArguments(new OAuthArguments(authInfo)); cache.createKey(request); }
@Test public void authTypeNoneWasCached() throws Exception { HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE); HttpResponse cached = new HttpResponse("cached"); cache.data.put(DEFAULT_URI, cached); HttpResponse response = pipeline.execute(request); assertEquals(cached, response); assertEquals(1, cache.readCount); assertEquals(0, cache.writeCount); assertEquals(0, fetcher.fetchCount); }
@Test public void authTypeNoneWasCached() throws Exception { HttpRequest request = new HttpRequest(DEFAULT_URI) .setAuthType(AuthType.NONE); HttpResponse cached = new HttpResponse("cached"); cache.data.put(DEFAULT_URI, cached); HttpResponse response = pipeline.execute(request); assertEquals(cached, response); assertEquals(1, cache.readCount); assertEquals(0, cache.writeCount); assertEquals(0, fetcher.fetchCount); }
public static HttpRequest newHttpRequest(GadgetContext context, RequestAuthenticationInfo authenticationInfo) throws GadgetException { return new HttpRequest(authenticationInfo.getHref()) .setSecurityToken(context.getToken()) .setOAuthArguments(new OAuthArguments(authenticationInfo)) .setAuthType(authenticationInfo.getAuthType()) .setContainer(context.getContainer()) .setGadget(context.getUrl()) .setIgnoreCache(context.getIgnoreCache()); }
public static HttpRequest newHttpRequest(GadgetContext context, RequestAuthenticationInfo authenticationInfo) throws GadgetException { return new HttpRequest(authenticationInfo.getHref()) .setSecurityToken(context.getToken()) .setOAuthArguments(new OAuthArguments(authenticationInfo)) .setAuthType(authenticationInfo.getAuthType()) .setContainer(context.getContainer()) .setGadget(context.getUrl()) .setIgnoreCache(context.getIgnoreCache()); }
public static HttpRequest newHttpRequest(GadgetContext context, RequestAuthenticationInfo authenticationInfo) throws GadgetException { return new HttpRequest(authenticationInfo.getHref()) .setSecurityToken(context.getToken()) .setOAuthArguments(new OAuthArguments(authenticationInfo)) .setOAuth2Arguments(new OAuth2Arguments(authenticationInfo)) .setAuthType(authenticationInfo.getAuthType()) .setContainer(context.getContainer()) .setGadget(context.getUrl()) .setIgnoreCache(context.getIgnoreCache()); }
@Test public void authTypeOAuthNotCached() throws Exception { HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.OAUTH); oauth.httpResponse = new HttpResponse("oauth result"); HttpResponse response = pipeline.execute(request); assertEquals(oauth.httpResponse, response); assertEquals(request, oauth.httpRequest); assertEquals(response, cache.data.get(DEFAULT_URI)); assertEquals(1, oauth.fetchCount); assertEquals(0, fetcher.fetchCount); assertEquals(1, cache.readCount); assertEquals(1, cache.writeCount); }
@Test public void createKeySimple() { HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI).setLegacyParam(1, AuthType.NONE); assertEquals(key.build(), cache.createKey(request)); }
@Test public void createKeySimple() { HttpRequest request = new HttpRequest(DEFAULT_URI).setAuthType(AuthType.NONE); CacheKeyBuilder key = new CacheKeyBuilder() .setLegacyParam(0, DEFAULT_URI).setLegacyParam(1, AuthType.NONE); assertEquals(key.build(), cache.createKey(request)); }