@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(); } }
@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(); }
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; }
@Test public void testFallbackUrl() throws Exception { ProxyUri uri = new ProxyUri(null, false, false, "open", "http://example.com/gadget", Uri.parse("http://example.com/resource")); uri.setFallbackUrl("http://example.com/fallback"); assertEquals("http://example.com/fallback", uri.getFallbackUri().toString()); }
@Test(expected = GadgetException.class) public void testBadFallbackUrl() throws Exception { ProxyUri uri = new ProxyUri(null, false, false, "open", "http://example.com/gadget", Uri.parse("http://example.com/resource")); uri.setFallbackUrl("bad url"); uri.getFallbackUri(); // throws exception! }
@Test public void testFallbackUrl() throws Exception { ProxyUri uri = new ProxyUri(null, false, false, "open", "http://example.com/gadget", Uri.parse("http://example.com/resource")); uri.setFallbackUrl("http://example.com/fallback"); assertEquals("http://example.com/fallback", uri.getFallbackUri().toString()); }
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); }
@Test(expected = GadgetException.class) public void testBadFallbackUrl() throws Exception { ProxyUri uri = new ProxyUri(null, false, false, "open", "http://example.com/gadget", Uri.parse("http://example.com/resource")); uri.setFallbackUrl("bad url"); uri.getFallbackUri(); // throws exception! }
@Test public void testFallbackUrl() throws Exception { ProxyUri uri = new ProxyUri(null, false, false, "open", "http://example.com/gadget", Uri.parse("http://example.com/resource")); uri.setFallbackUrl("http://example.com/fallback"); assertEquals("http://example.com/fallback", uri.getFallbackUri().toString()); }
@Test(expected = GadgetException.class) public void testBadFallbackUrl() throws Exception { ProxyUri uri = new ProxyUri(null, false, false, "open", "http://example.com/gadget", Uri.parse("http://example.com/resource")); uri.setFallbackUrl("bad url"); uri.getFallbackUri(); // throws exception! }
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); }