Search in sources :

Example 46 with BinaryResource

use of org.eclipse.scout.rt.platform.resource.BinaryResource in project scout.rt by eclipse.

the class HttpCacheControlTest method testCheckAndSet_EnableCaching.

@Test
public void testCheckAndSet_EnableCaching() throws Exception {
    Mockito.when(req.getPathInfo()).thenReturn("/");
    Mockito.when(req.getHeader(HttpCacheControl.ETAG)).thenReturn(null);
    Mockito.when(req.getHeader(HttpCacheControl.IF_NONE_MATCH)).thenReturn(null);
    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).withLastModified(0L).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(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).setHeader(HttpCacheControl.ETAG, obj.createETag());
}
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)

Aggregations

BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)46 Test (org.junit.Test)26 HttpCacheObject (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)19 HttpCacheKey (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheKey)15 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)4 BinaryResourceHolder (org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder)4 InputStream (java.io.InputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 JSONObject (org.json.JSONObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Field (java.lang.reflect.Field)1