private void expectRequestWithUris(List<Uri> uris) { expectRequestWithUris(uris, null); }
private void expectRequestWithUris(List<Uri> uris) { expectRequestWithUris(uris, null); }
private void expectRequestWithUris(List<Uri> uris) { expectRequestWithUris(uris, null); }
@Test public void testBadJsonVarConcat() throws Exception { expectRequestWithUris(Lists.<Uri>newArrayList(), "bad code;"); servlet.doGet(request, recorder); verify(); String results = "/* ---- Error 400, Bad json variable name bad code; ---- */\r\n"; assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testBadJsonVarConcat() throws Exception { expectRequestWithUris(Lists.<Uri>newArrayList(), "bad code;"); servlet.doGet(request, recorder); verify(); String results = "/* ---- Error 400, Bad json variable name bad code; ---- */\r\n"; assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testBadJsonVarConcat() throws Exception { expectRequestWithUris(Lists.<Uri>newArrayList(), "bad code;"); servlet.doGet(request, recorder); verify(); String results = "/* ---- Error 400, Bad json variable name bad code; ---- */\r\n"; assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testDefaultCacheTtlCacheHeaderMissing() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); final Uri URL5 = Uri.parse("http://example.org/5.js"); expectGetAndReturnData(URL4, ""); expectGetAndReturnData(URL5, ""); expectRequestWithUris(Lists.newArrayList(URL4, URL5)); servlet.doGet(request, recorder); verify(); int cacheValue = getCacheControlMaxAge(recorder); // HttpResponse.defaultTtl is in msec, division by 1000 is required to convert into sec. assertEquals((int) (HttpResponse.defaultTtl / 1000), cacheValue, 10); }
@Test public void testDefaultCacheTtlCacheHeaderMissing() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); final Uri URL5 = Uri.parse("http://example.org/5.js"); expectGetAndReturnData(URL4, ""); expectGetAndReturnData(URL5, ""); expectRequestWithUris(Lists.newArrayList(URL4, URL5)); servlet.doGet(request, recorder); verify(); int cacheValue = getCacheControlMaxAge(recorder); // HttpResponse.defaultTtl is in msec, division by 1000 is required to convert into sec. assertEquals((int) (HttpResponse.defaultTtl / 1000), cacheValue, 10); }
@Test public void testConcat404() throws Exception { String url = "http://nobodyhome.com/"; HttpRequest req = new HttpRequest(Uri.parse(url)); HttpResponse resp = new HttpResponseBuilder().setHttpStatusCode(404).create(); expect(pipeline.execute(req)).andReturn(resp).anyTimes(); expectRequestWithUris(Lists.newArrayList(URL1, Uri.parse(url))); servlet.doGet(request, recorder); verify(); String results = addComment(SCRT1, URL1.toString()) + addErrComment(url,404); assertEquals(results, recorder.getResponseAsString()); assertEquals(200, recorder.getHttpStatusCode()); }
@Test public void testConcat404() throws Exception { String url = "http://nobodyhome.com/"; HttpRequest req = new HttpRequest(Uri.parse(url)); HttpResponse resp = new HttpResponseBuilder().setHttpStatusCode(404).create(); expect(pipeline.execute(req)).andReturn(resp).anyTimes(); expectRequestWithUris(Lists.newArrayList(URL1, Uri.parse(url))); servlet.doGet(request, recorder); verify(); String results = addComment(SCRT1, URL1.toString()) + addErrComment(url,404); assertEquals(results, recorder.getResponseAsString()); assertEquals(200, recorder.getHttpStatusCode()); }
@Test public void testConcat404() throws Exception { String url = "http://nobodyhome.com/"; HttpRequest req = new HttpRequest(Uri.parse(url)); HttpResponse resp = new HttpResponseBuilder().setHttpStatusCode(404).create(); expect(pipeline.execute(req)).andReturn(resp).anyTimes(); expectRequestWithUris(Lists.newArrayList(URL1, Uri.parse(url))); servlet.doGet(request, recorder); verify(); String results = addComment(SCRT1, URL1.toString()) + addErrComment(url,404); assertEquals(results, recorder.getResponseAsString()); assertEquals(200, recorder.getHttpStatusCode()); }
@Test public void testAsJsonConcatBadException() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); HttpRequest req = new HttpRequest(URL4); expect(pipeline.execute(req)).andThrow( new GadgetException(GadgetException.Code.HTML_PARSE_ERROR)).anyTimes(); String results = "_js={\r\n" + addVar(URL1.toString(), SCRT1_ESCAPED) + "HTML_PARSE_ERROR concat(http://example.org/4.js) null};\r\n"; expectRequestWithUris(Lists.newArrayList(URL1, URL4), "_js"); // Run the servlet servlet.doGet(request, recorder); verify(); assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testConcatBadException() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); HttpRequest req = new HttpRequest(URL4); expect(pipeline.execute(req)).andThrow( new GadgetException(GadgetException.Code.HTML_PARSE_ERROR)).anyTimes(); expectRequestWithUris(Lists.newArrayList(URL1, URL4)); // Run the servlet servlet.doGet(request, recorder); verify(); String results = addComment(SCRT1, URL1.toString()) + "HTML_PARSE_ERROR concat(http://example.org/4.js) null"; assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testAsJsonConcatException() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); HttpRequest req = new HttpRequest(URL4); expect(pipeline.execute(req)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT)).anyTimes(); expectRequestWithUris(Lists.newArrayList(URL1, URL4), "_js"); servlet.doGet(request, recorder); verify(); String results = "_js={\r\n" + addVar(URL1.toString(), SCRT1_ESCAPED) + "FAILED_TO_RETRIEVE_CONTENT concat(http://example.org/4.js) null};\r\n"; assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testConcatBadException() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); HttpRequest req = new HttpRequest(URL4); expect(pipeline.execute(req)).andThrow( new GadgetException(GadgetException.Code.HTML_PARSE_ERROR)).anyTimes(); expectRequestWithUris(Lists.newArrayList(URL1, URL4)); // Run the servlet servlet.doGet(request, recorder); verify(); String results = addComment(SCRT1, URL1.toString()) + addConcatErrComment(GadgetException.Code.HTML_PARSE_ERROR, URL4.toString()); assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testConcatBadException() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); HttpRequest req = new HttpRequest(URL4); expect(pipeline.execute(req)).andThrow( new GadgetException(GadgetException.Code.HTML_PARSE_ERROR)).anyTimes(); expectRequestWithUris(Lists.newArrayList(URL1, URL4)); // Run the servlet servlet.doGet(request, recorder); verify(); String results = addComment(SCRT1, URL1.toString()) + addConcatErrComment(GadgetException.Code.HTML_PARSE_ERROR, URL4.toString()); assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testAsJsonConcatBadException() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); HttpRequest req = new HttpRequest(URL4); expect(pipeline.execute(req)).andThrow( new GadgetException(GadgetException.Code.HTML_PARSE_ERROR)).anyTimes(); String results = "_js={\r\n" + addLastVar(URL1.toString(), SCRT1_ESCAPED) + addConcatErrComment(GadgetException.Code.HTML_PARSE_ERROR, URL4.toString()) + "};\r\n"; expectRequestWithUris(Lists.newArrayList(URL1, URL4), "_js"); // Run the servlet servlet.doGet(request, recorder); verify(); assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testAsJsonConcatException() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); HttpRequest req = new HttpRequest(URL4); expect(pipeline.execute(req)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT)).anyTimes(); expectRequestWithUris(Lists.newArrayList(URL1, URL4), "_js"); servlet.doGet(request, recorder); verify(); String results = "_js={\r\n" + addLastVar(URL1.toString(), SCRT1_ESCAPED) + addConcatErrComment(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, URL4.toString()) + "};\r\n"; assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testAsJsonConcatException() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); HttpRequest req = new HttpRequest(URL4); expect(pipeline.execute(req)).andThrow( new GadgetException(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT)).anyTimes(); expectRequestWithUris(Lists.newArrayList(URL1, URL4), "_js"); servlet.doGet(request, recorder); verify(); String results = "_js={\r\n" + addLastVar(URL1.toString(), SCRT1_ESCAPED) + addConcatErrComment(GadgetException.Code.FAILED_TO_RETRIEVE_CONTENT, URL4.toString()) + "};\r\n"; assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }
@Test public void testAsJsonConcatBadException() throws Exception { final Uri URL4 = Uri.parse("http://example.org/4.js"); HttpRequest req = new HttpRequest(URL4); expect(pipeline.execute(req)).andThrow( new GadgetException(GadgetException.Code.HTML_PARSE_ERROR)).anyTimes(); String results = "_js={\r\n" + addLastVar(URL1.toString(), SCRT1_ESCAPED) + addConcatErrComment(GadgetException.Code.HTML_PARSE_ERROR, URL4.toString()) + "};\r\n"; expectRequestWithUris(Lists.newArrayList(URL1, URL4), "_js"); // Run the servlet servlet.doGet(request, recorder); verify(); assertEquals(results, recorder.getResponseAsString()); assertEquals(400, recorder.getHttpStatusCode()); }