use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class HttpCacheControlTest method testCheckAndSet_EnableCaching_IfNoneMatch_true.
@Test
public void testCheckAndSet_EnableCaching_IfNoneMatch_true() throws Exception {
Mockito.when(req.getPathInfo()).thenReturn("/");
Mockito.when(req.getHeader(HttpCacheControl.ETAG)).thenReturn(null);
// matching E-Tag
Mockito.when(req.getHeader(HttpCacheControl.IF_NONE_MATCH)).thenReturn("W/\"FooBar\", W/\"13-535168142\"");
Mockito.when(req.getDateHeader(HttpCacheControl.IF_MODIFIED_SINCE)).thenReturn(0L);
BinaryResource res = BinaryResources.create().withFilename("a.html").withContent("<html></html>".getBytes("UTF-8")).withCachingAllowed(true).withLastModifiedNow().build();
HttpCacheObject obj = new HttpCacheObject(new HttpCacheKey("/"), res);
boolean b = cc.checkAndSetCacheHeaders(req, resp, obj);
Assert.assertTrue(b);
Mockito.verify(req, ANY_TIMES).getPathInfo();
Mockito.verify(req, ANY_TIMES).getAttribute("javax.servlet.forward.path_info");
Mockito.verify(req, ANY_TIMES).getHeader(HttpCacheControl.ETAG);
Mockito.verify(req, ANY_TIMES).getHeader(HttpCacheControl.IF_NONE_MATCH);
Mockito.verify(req, ANY_TIMES).getDateHeader(HttpCacheControl.IF_MODIFIED_SINCE);
Mockito.verify(resp, ONCE).setHeader(HttpCacheControl.CACHE_CONTROL, "private, max-age=0, must-revalidate");
Mockito.verify(resp, ONCE).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class HttpCacheKeyTest method testNullPath.
@Test
public void testNullPath() throws Exception {
HttpCacheKey key = new HttpCacheKey(null);
Assert.assertNull(key.getResourcePath());
Assert.assertEquals(0, key.hashCode());
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class HttpCacheKeyTest method testEquals.
@Test
public void testEquals() throws Exception {
Assert.assertEquals(new HttpCacheKey(null), new HttpCacheKey(null));
Assert.assertEquals(new HttpCacheKey(null), new HttpCacheKey(null, Collections.<String, String>emptyMap()));
Assert.assertEquals(new HttpCacheKey("/"), new HttpCacheKey("/"));
Assert.assertEquals(new HttpCacheKey("/", null), new HttpCacheKey("/", null));
Assert.assertEquals(new HttpCacheKey(null, Collections.singletonMap((String) null, (String) null)), new HttpCacheKey(null, Collections.singletonMap((String) null, (String) null)));
Assert.assertEquals(new HttpCacheKey(null, Collections.singletonMap("a", "v")), new HttpCacheKey(null, Collections.singletonMap("a", "v")));
Assert.assertNotEquals(new HttpCacheKey(null), new HttpCacheKey(null, Collections.singletonMap((String) null, (String) null)));
Assert.assertNotEquals(new HttpCacheKey(null), new HttpCacheKey(null, Collections.singletonMap("a", "v")));
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class HttpCacheKeyTest method testSimplePath.
@Test
public void testSimplePath() throws Exception {
String path = "/test.html";
HttpCacheKey key = new HttpCacheKey(path);
Assert.assertEquals(path, key.getResourcePath());
Assert.assertEquals(path.hashCode(), key.hashCode());
}
use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.
the class HttpCacheKeyTest method testAttributeWithNullKeyAndValue.
@Test
public void testAttributeWithNullKeyAndValue() throws Exception {
Map<String, String> atts = Collections.singletonMap((String) null, (String) null);
HttpCacheKey key = new HttpCacheKey("/", atts);
Assert.assertNull(key.getAttribute(null));
Assert.assertNull(key.getAttribute("a"));
Assert.assertEquals("/".hashCode() + atts.hashCode(), key.hashCode());
}
Aggregations