Search in sources :

Example 6 with HttpCacheKey

use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.

the class HttpCacheControlTest method testCheckAndSet_DisableCaching.

@Test
public void testCheckAndSet_DisableCaching() throws Exception {
    Mockito.when(req.getPathInfo()).thenReturn("/");
    BinaryResource res = BinaryResources.create().withFilename("a.html").withContent("<html></html>".getBytes("UTF-8")).withCachingAllowed(false).build();
    HttpCacheObject obj = new HttpCacheObject(new HttpCacheKey("/"), res);
    boolean b = cc.checkAndSetCacheHeaders(req, resp, obj);
    Assert.assertFalse(b);
    Mockito.verify(req, ANY_TIMES).getPathInfo();
    Mockito.verify(req, ANY_TIMES).getAttribute("javax.servlet.forward.path_info");
    Mockito.verify(resp, ONCE).setHeader(HttpCacheControl.CACHE_CONTROL, "private, no-store, no-cache, max-age=0");
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) HttpCacheKey(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey) HttpCacheObject(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject) Test(org.junit.Test)

Example 7 with HttpCacheKey

use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.

the class HttpCacheKeyTest method testAttributeWithNullValue.

@Test
public void testAttributeWithNullValue() throws Exception {
    Map<String, String> atts = Collections.singletonMap("a", (String) null);
    HttpCacheKey key = new HttpCacheKey("/", atts);
    Assert.assertNull(key.getAttribute(null));
    Assert.assertNull(key.getAttribute("a"));
    Assert.assertEquals("/".hashCode() + atts.hashCode(), key.hashCode());
}
Also used : HttpCacheKey(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey) Test(org.junit.Test)

Example 8 with HttpCacheKey

use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.

the class HttpCacheKeyTest method testAttributeWithNullKey.

@Test
public void testAttributeWithNullKey() throws Exception {
    Map<String, String> atts = Collections.singletonMap((String) null, "v");
    HttpCacheKey key = new HttpCacheKey("/", atts);
    Assert.assertEquals("v", key.getAttribute(null));
    Assert.assertNull(key.getAttribute("a"));
    Assert.assertEquals("/".hashCode() + atts.hashCode(), key.hashCode());
}
Also used : HttpCacheKey(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey) Test(org.junit.Test)

Example 9 with HttpCacheKey

use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.

the class HttpCacheKeyTest method testNoAttributes.

@Test
public void testNoAttributes() throws Exception {
    HttpCacheKey key = new HttpCacheKey("/");
    Assert.assertNull(key.getAttribute("a"));
}
Also used : HttpCacheKey(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey) Test(org.junit.Test)

Example 10 with HttpCacheKey

use of org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey in project scout.rt by eclipse.

the class HttpCacheKeyTest method testAttribute.

@Test
public void testAttribute() throws Exception {
    Map<String, String> atts = Collections.singletonMap("a", "v");
    HttpCacheKey key = new HttpCacheKey("/", atts);
    Assert.assertNull(key.getAttribute(null));
    Assert.assertEquals("v", key.getAttribute("a"));
    Assert.assertNull(key.getAttribute("b"));
    Assert.assertEquals("/".hashCode() + atts.hashCode(), key.hashCode());
}
Also used : HttpCacheKey(org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey) Test(org.junit.Test)

Aggregations

HttpCacheKey (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey)31 Test (org.junit.Test)24 HttpCacheObject (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)20 BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)15 HttpCacheControl (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheControl)2 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 ServletContext (javax.servlet.ServletContext)1 NlsLocale (org.eclipse.scout.rt.platform.nls.NlsLocale)1 ImmutablePair (org.eclipse.scout.rt.platform.util.ImmutablePair)1 IHttpResourceCache (org.eclipse.scout.rt.server.commons.servlet.cache.IHttpResourceCache)1 IRemoteFileService (org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService)1 RemoteFile (org.eclipse.scout.rt.shared.services.common.file.RemoteFile)1 HtmlFileLoader (org.eclipse.scout.rt.ui.html.res.loader.HtmlFileLoader)1