Search in sources :

Example 6 with BinaryResourceHolder

use of org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder in project scout.rt by eclipse.

the class DownloadHandlerStorageTest method testRemove.

@Test
public void testRemove() {
    DownloadHandlerStorage storage = new DownloadHandlerStorage() {

        @Override
        protected long getRemovalTimeoutAfterFirstRequest() {
            return 100L;
        }
    };
    BinaryResource res = new BinaryResource("bar.txt", null);
    BinaryResourceHolder holder = new BinaryResourceHolder(res);
    storage.put(KEY, holder, OpenUriAction.DOWNLOAD);
    assertEquals(1, storage.futureMap().size());
    BinaryResourceHolderWithAction holderWithAction = storage.get(KEY);
    assertEquals(OpenUriAction.DOWNLOAD, holderWithAction.getOpenUriAction());
    assertEquals(res, holderWithAction.getHolder().get());
    assertEquals("future should still be in futureMap", 1, storage.futureMap().size());
    assertEquals(res, holderWithAction.getHolder().get());
    SleepUtil.sleepElseLog(150, TimeUnit.MILLISECONDS);
    assertEquals("futureMap must be cleared after timeout", 0, storage.futureMap().size());
    assertNull(storage.get(KEY));
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) BinaryResourceHolderWithAction(org.eclipse.scout.rt.ui.html.json.desktop.DownloadHandlerStorage.BinaryResourceHolderWithAction) BinaryResourceHolder(org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder) Test(org.junit.Test)

Example 7 with BinaryResourceHolder

use of org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder in project scout.rt by eclipse.

the class DownloadHandlerStorageTest method testRemove_AfterTimeout.

@Test
public void testRemove_AfterTimeout() {
    DownloadHandlerStorage storage = new DownloadHandlerStorage() {

        @Override
        protected long getTTLForResource(BinaryResource res) {
            return 10L;
        }
    };
    BinaryResource res = new BinaryResource("bar.txt", null);
    BinaryResourceHolder holder = new BinaryResourceHolder(res);
    storage.put(KEY, holder, OpenUriAction.NEW_WINDOW);
    SleepUtil.sleepElseLog(100, TimeUnit.MILLISECONDS);
    assertNull(storage.get(KEY));
    assertEquals("futureMap must be cleared after timeout", 0, storage.futureMap().size());
}
Also used : BinaryResource(org.eclipse.scout.rt.platform.resource.BinaryResource) BinaryResourceHolder(org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder) Test(org.junit.Test)

Aggregations

BinaryResourceHolder (org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder)7 BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)5 Test (org.junit.Test)3 DownloadHttpResponseInterceptor (org.eclipse.scout.rt.server.commons.servlet.cache.DownloadHttpResponseInterceptor)2 BinaryResourceHolderWithAction (org.eclipse.scout.rt.ui.html.json.desktop.DownloadHandlerStorage.BinaryResourceHolderWithAction)2 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 HttpCacheObject (org.eclipse.scout.rt.server.commons.servlet.cache.HttpCacheObject)1 IHttpResponseInterceptor (org.eclipse.scout.rt.server.commons.servlet.cache.IHttpResponseInterceptor)1 IBinaryResourceProvider (org.eclipse.scout.rt.ui.html.res.IBinaryResourceProvider)1