@Test public void makeSingleExpectedMime() throws Exception { Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); Capture<Integer> intCapture = new Capture<Integer>(); List<ProxyUri> input = Lists.newArrayList(proxyUri); List<Uri> output = Lists.newArrayList(uri); Integer refresh = new Integer(0); String mime = "my/mime"; expect(uriManager.make(capture(uriCapture), capture(intCapture))) .andReturn(output).once(); replay(uriManager); expect(proxyUri.setSanitizeContent(true)).andReturn(proxyUri).once(); expect(proxyUri.setRewriteMimeType(mime)).andReturn(proxyUri).once(); replay(proxyUri); SanitizingProxyUriManager rewriter = makeRewriter(mime); List<Uri> returned = rewriter.make(input, refresh); verify(uriManager); assertSame(uriCapture.getValue(), input); assertSame(intCapture.getValue(), refresh); assertEquals(1, returned.size()); verify(proxyUri); }
@Test public void makeSingleExpectedMime() throws Exception { Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); Capture<Integer> intCapture = new Capture<Integer>(); List<ProxyUri> input = Lists.newArrayList(proxyUri); List<Uri> output = Lists.newArrayList(uri); Integer refresh = new Integer(0); String mime = "my/mime"; expect(uriManager.make(capture(uriCapture), capture(intCapture))) .andReturn(output).once(); replay(uriManager); expect(proxyUri.setSanitizeContent(true)).andReturn(proxyUri).once(); expect(proxyUri.setRewriteMimeType(mime)).andReturn(proxyUri).once(); replay(proxyUri); SanitizingProxyUriManager rewriter = makeRewriter(mime); List<Uri> returned = rewriter.make(input, refresh); verify(uriManager); assertSame(uriCapture.getValue(), input); assertSame(intCapture.getValue(), refresh); assertEquals(1, returned.size()); verify(proxyUri); }
@Test public void makeList() throws Exception { Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); Capture<Integer> intCapture = new Capture<Integer>(); ProxyUri proxyUri2 = createMock(ProxyUri.class); List<ProxyUri> input = Lists.newArrayList(proxyUri, proxyUri2); Uri uri2 = new UriBuilder().toUri(); List<Uri> output = Lists.newArrayList(uri, uri2); Integer refresh = new Integer(0); String mime = "my/mime"; expect(uriManager.make(capture(uriCapture), capture(intCapture))) .andReturn(output).once(); replay(uriManager); expect(proxyUri.setSanitizeContent(true)).andReturn(proxyUri).once(); expect(proxyUri.setRewriteMimeType(mime)).andReturn(proxyUri).once(); expect(proxyUri2.setSanitizeContent(true)).andReturn(proxyUri2).once(); expect(proxyUri2.setRewriteMimeType(mime)).andReturn(proxyUri2).once(); replay(proxyUri, proxyUri2); SanitizingProxyUriManager rewriter = makeRewriter(mime); List<Uri> returned = rewriter.make(input, refresh); verify(uriManager); assertSame(uriCapture.getValue(), input); assertSame(intCapture.getValue(), refresh); assertEquals(2, returned.size()); verify(proxyUri, proxyUri2); }
@Test public void testCreateProxyUri() throws Exception { GadgetsHandlerApi.ImageParams image = mock(GadgetsHandlerApi.ImageParams.class); expect(image.getDoNotExpand()).andStubReturn(true); expect(image.getHeight()).andStubReturn(120); expect(image.getWidth()).andStubReturn(210); expect(image.getQuality()).andStubReturn(77); GadgetsHandlerApi.ProxyRequest request = mock(GadgetsHandlerApi.ProxyRequest.class); expect(request.getContainer()).andStubReturn(CONTAINER); expect(request.getUrl()).andStubReturn(RESOURCE); expect(request.getRefresh()).andStubReturn(new Integer(333)); expect(request.getDebug()).andStubReturn(true); expect(request.getFallbackUrl()).andStubReturn(FALLBACK); expect(request.getGadget()).andStubReturn(FakeProcessor.SPEC_URL.toString()); expect(request.getIgnoreCache()).andStubReturn(true); expect(request.getImageParams()).andStubReturn(image); expect(request.getRewriteMimeType()).andStubReturn("image/png"); expect(request.getSanitize()).andStubReturn(true); replay(); ProxyUri pUri = gadgetHandler.createProxyUri(request); ProxyUri expectedUri = new ProxyUri(333, true, true, CONTAINER, FakeProcessor.SPEC_URL.toString(), RESOURCE); expectedUri.setRewriteMimeType("image/png").setSanitizeContent(true); expectedUri.setResize(210, 120, 77, true).setFallbackUrl(FALLBACK); assertEquals(pUri, expectedUri); verify(); }
@Test public void testCreateProxyUri() throws Exception { GadgetsHandlerApi.ImageParams image = mock(GadgetsHandlerApi.ImageParams.class); expect(image.getDoNotExpand()).andStubReturn(true); expect(image.getHeight()).andStubReturn(120); expect(image.getWidth()).andStubReturn(210); expect(image.getQuality()).andStubReturn(77); GadgetsHandlerApi.ProxyRequest request = mock(GadgetsHandlerApi.ProxyRequest.class); expect(request.getContainer()).andStubReturn(CONTAINER); expect(request.getUrl()).andStubReturn(RESOURCE); expect(request.getRefresh()).andStubReturn(new Integer(333)); expect(request.getDebug()).andStubReturn(true); expect(request.getFallbackUrl()).andStubReturn(FALLBACK); expect(request.getGadget()).andStubReturn(FakeProcessor.SPEC_URL.toString()); expect(request.getIgnoreCache()).andStubReturn(true); expect(request.getImageParams()).andStubReturn(image); expect(request.getRewriteMimeType()).andStubReturn("image/png"); expect(request.getSanitize()).andStubReturn(true); replay(); ProxyUri pUri = gadgetHandler.createProxyUri(request); ProxyUri expectedUri = new ProxyUri(333, true, true, CONTAINER, FakeProcessor.SPEC_URL.toString(), RESOURCE); expectedUri.setRewriteMimeType("image/png").setSanitizeContent(true); expectedUri.setResize(210, 120, 77, true).setFallbackUrl(FALLBACK); assertEquals(pUri, expectedUri); verify(); }
@Test public void makeList() throws Exception { Capture<List<ProxyUri>> uriCapture = new Capture<List<ProxyUri>>(); Capture<Integer> intCapture = new Capture<Integer>(); ProxyUri proxyUri2 = createMock(ProxyUri.class); List<ProxyUri> input = Lists.newArrayList(proxyUri, proxyUri2); Uri uri2 = new UriBuilder().toUri(); List<Uri> output = Lists.newArrayList(uri, uri2); Integer refresh = new Integer(0); String mime = "my/mime"; expect(uriManager.make(capture(uriCapture), capture(intCapture))) .andReturn(output).once(); replay(uriManager); expect(proxyUri.setSanitizeContent(true)).andReturn(proxyUri).once(); expect(proxyUri.setRewriteMimeType(mime)).andReturn(proxyUri).once(); expect(proxyUri2.setSanitizeContent(true)).andReturn(proxyUri2).once(); expect(proxyUri2.setRewriteMimeType(mime)).andReturn(proxyUri2).once(); replay(proxyUri, proxyUri2); SanitizingProxyUriManager rewriter = makeRewriter(mime); List<Uri> returned = rewriter.make(input, refresh); verify(uriManager); assertSame(uriCapture.getValue(), input); assertSame(intCapture.getValue(), refresh); assertEquals(2, returned.size()); verify(proxyUri, proxyUri2); }
@Test public void testComplexProxy() throws Exception { registerGadgetsHandler(null); String resUri = "http://example.com/data"; String proxyUri = "http://shindig.com/gadgets/proxy?url=" + resUri; JSONObject request = makeComplexProxyRequest(resUri); Capture<List<ProxyUri>> captureProxyUri = new Capture<List<ProxyUri>>(); EasyMock.expect( proxyUriManager.make(EasyMock.capture(captureProxyUri), EasyMock.isNull(Integer.class))) .andReturn(ImmutableList.<Uri> of(Uri.parse(proxyUri))); replay(); RpcHandler operation = registry.getRpcHandler(request); Object responseObj = operation.execute(emptyFormItems, authContext, converter).get(); JSONObject response = new JSONObject(converter.convertToString(responseObj)); JSONObject gadget1 = response.getJSONObject(resUri); assertEquals(proxyUri, gadget1.getString("proxyUrl")); ProxyUri pUri = captureProxyUri.getValue().get(0); ProxyUri expectedUri = new ProxyUri(333, true, true, CONTAINER, GADGET1_URL, Uri.parse(resUri)); expectedUri.setRewriteMimeType("text/xml").setSanitizeContent(true); expectedUri.setFallbackUrl(resUri).setResize(555, 444, 88, true); assertTrue(expectedUri.equals(pUri)); assertFalse(gadget1.has("error")); verify(); } }
@Test public void testComplexProxy() throws Exception { registerGadgetsHandler(null); String resUri = "http://example.com/data"; String proxyUri = "http://shindig.com/gadgets/proxy?url=" + resUri; JSONObject request = makeComplexProxyRequest(resUri); Capture<List<ProxyUri>> captureProxyUri = new Capture<List<ProxyUri>>(); EasyMock.expect( proxyUriManager.make(EasyMock.capture(captureProxyUri), EasyMock.isNull(Integer.class))) .andReturn(ImmutableList.<Uri> of(Uri.parse(proxyUri))); replay(); RpcHandler operation = registry.getRpcHandler(request); Object responseObj = operation.execute(emptyFormItems, authContext, converter).get(); JSONObject response = new JSONObject(converter.convertToString(responseObj)); JSONObject gadget1 = response.getJSONObject(resUri); assertEquals(proxyUri, gadget1.getString("proxyUrl")); ProxyUri pUri = captureProxyUri.getValue().get(0); ProxyUri expectedUri = new ProxyUri(333, true, true, CONTAINER, GADGET1_URL, Uri.parse(resUri)); expectedUri.setRewriteMimeType("text/xml").setSanitizeContent(true); expectedUri.setFallbackUrl(resUri).setResize(555, 444, 88, true); assertTrue(expectedUri.equals(pUri)); assertFalse(gadget1.has("error")); verify(); } }
protected ProxyUri createProxyUri(GadgetsHandlerApi.ProxyRequest request) { ProxyUriManager.ProxyUri proxyUri = new ProxyUriManager.ProxyUri(request.getRefresh(), request.getDebug(), request.getIgnoreCache(), request.getContainer(), request.getGadget(), request.getUrl()); proxyUri.setFallbackUrl(request.getFallbackUrl()) .setRewriteMimeType(request.getRewriteMimeType()) .setSanitizeContent(request.getSanitize()); GadgetsHandlerApi.ImageParams image = request.getImageParams(); if (image != null) { proxyUri.setResize( image.getWidth(), image.getHeight(), image.getQuality(), image.getDoNotExpand()); } return proxyUri; }
public List<Uri> make(List<ProxyUri> ctx, Integer forcedRefresh) { // Just wraps the original ProxyUriManager and adds a few query params. for (ProxyUri proxyUri : ctx) { proxyUri.setSanitizeContent(true); if (expectedMime != null) { proxyUri.setRewriteMimeType(expectedMime); } } return wrapped.make(ctx, forcedRefresh); } }
private void setupProxyRequestMock(String host, String url, boolean noCache, int refresh, String rewriteMime, String fallbackUrl) throws Exception { request = new ProxyUriManager.ProxyUri( refresh, false, noCache, ContainerConfig.DEFAULT_CONTAINER, GADGET, Uri.parse(url)); request.setFallbackUrl(fallbackUrl); request.setRewriteMimeType(rewriteMime); }
private void setupProxyRequestMock(String host, String url, boolean noCache, int refresh, String rewriteMime, String fallbackUrl) throws Exception { request = new ProxyUriManager.ProxyUri( refresh, false, noCache, ContainerConfig.DEFAULT_CONTAINER, null, Uri.parse(url)); request.setFallbackUrl(fallbackUrl); request.setRewriteMimeType(rewriteMime); }
private void setupProxyRequestMock(String host, String url, boolean noCache, int refresh, String rewriteMime, String fallbackUrl) throws Exception { request = new ProxyUriManager.ProxyUri( refresh, false, noCache, ContainerConfig.DEFAULT_CONTAINER, GADGET, Uri.parse(url)); request.setFallbackUrl(fallbackUrl); request.setRewriteMimeType(rewriteMime); }