@Test public void testDoPostHttpError() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri, POST_CONTENT)).andReturn(HttpResponse.notFound()); expect(request.getMethod()).andReturn(POST_METHOD); expect(request.getInputStream()).andReturn(postContentStream); replay(); servlet.doPost(request, recorder); verify(); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoPostHttpError() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri, POST_CONTENT)).andReturn(HttpResponse.notFound()); expect(request.getMethod()).andReturn(POST_METHOD); expect(request.getInputStream()).andReturn(postContentStream); replay(); servlet.doPost(request, recorder); verify(); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoGetHttpError() throws Exception { setupGet(); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoGetHttpError() throws Exception { setupGet(); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoGetHttpError() throws Exception { setupGet(); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoPostHttpError() throws Exception { setupPost(); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoPostHttpError() throws Exception { setupPost(); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoPostHttpError() throws Exception { setupPost(); expect(pipeline.execute(internalRequest)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoGetHttpError() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); verify(); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoGetHttpError() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); verify(); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void testDoGetHttpError() throws Exception { setupRequest(BASIC_SYNTAX_URL); expect(proxyHandler.fetch(proxyUri)).andReturn(HttpResponse.notFound()); replay(); servlet.doGet(request, recorder); verify(); assertResponseOk(HttpResponse.SC_NOT_FOUND, ""); }
@Test public void staleSpecReturnedFromCacheOnError() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpRequest retriedRequest = createCacheableRequest(); HttpResponse expiredResponse = new HttpResponseBuilder() .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8")) .addHeader("Pragma", "no-cache") .create(); expect(pipeline.execute(request)).andReturn(expiredResponse); expect(pipeline.execute(retriedRequest)).andReturn(HttpResponse.notFound()).once(); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL); specFactory.cache.addElement(SPEC_URL, inCache.obj, -1); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false)); assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void staleSpecReturnedFromCacheOnError() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpRequest retriedRequest = createCacheableRequest(); HttpResponse expiredResponse = new HttpResponseBuilder() .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8")) .addHeader("Pragma", "no-cache") .create(); expect(pipeline.execute(request)).andReturn(expiredResponse); expect(pipeline.execute(retriedRequest)).andReturn(HttpResponse.notFound()).once(); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString()); specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false)); assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void staleSpecReturnedFromCacheOnError() throws Exception { HttpRequest request = createIgnoreCacheRequest(); HttpRequest retriedRequest = createCacheableRequest(); HttpResponse expiredResponse = new HttpResponseBuilder() .setResponse(LOCAL_SPEC_XML.getBytes("UTF-8")) .addHeader("Pragma", "no-cache") .create(); expect(pipeline.execute(request)).andReturn(expiredResponse); expect(pipeline.execute(retriedRequest)).andReturn(HttpResponse.notFound()).once(); replay(pipeline); specFactory.getGadgetSpec(createContext(SPEC_URL, true)); SoftExpiringCache.CachedObject<Object> inCache = specFactory.cache.getElement(SPEC_URL.toString()); specFactory.cache.addElement(SPEC_URL.toString(), inCache.obj, -1); GadgetSpec spec = specFactory.getGadgetSpec(createContext(SPEC_URL, false)); assertEquals(ALT_LOCAL_CONTENT, spec.getView(GadgetSpec.DEFAULT_VIEW).getContent()); }
@Test public void testNegativeCaching() { assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.error().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.notFound().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.timeout().getCacheExpiration() > timeSource.currentTimeMillis()); long ttl = HttpResponse.error().getCacheTtl(); assertTrue(ttl <= HttpResponse.DEFAULT_TTL && ttl > 0); }
@Test public void testNegativeCaching() { assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.error().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.notFound().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.timeout().getCacheExpiration() > timeSource.currentTimeMillis()); long ttl = HttpResponse.error().getCacheTtl(); assertTrue(ttl <= HttpResponse.DEFAULT_TTL && ttl > 0); }
@Test public void testNegativeCaching() { assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.error().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.notFound().getCacheExpiration() > timeSource.currentTimeMillis()); assertTrue("Bad HTTP responses must be cacheable!", HttpResponse.timeout().getCacheExpiration() > timeSource.currentTimeMillis()); long ttl = HttpResponse.error().getCacheTtl(); assertTrue(ttl <= HttpResponse.DEFAULT_TTL && ttl > 0); }