Search in sources :

Example 1 with BinaryResourceHolderWithAction

use of org.eclipse.scout.rt.ui.html.json.desktop.DownloadHandlerStorage.BinaryResourceHolderWithAction in project scout.rt by eclipse.

the class DownloadHandlerStorageTest method testGet.

@Test
public void testGet() {
    final CountDownLatch secondGet = new CountDownLatch(1);
    final CountDownLatch elementRemoved = new CountDownLatch(1);
    DownloadHandlerStorage storage = new DownloadHandlerStorage() {

        @Override
        protected long getTTLForResource(BinaryResource res) {
            return 50L;
        }

        @Override
        protected void removeOnTimeout(String key) {
            waitFor(secondGet);
            super.removeOnTimeout(key);
            elementRemoved.countDown();
        }
    };
    BinaryResource res = new BinaryResource("bar.txt", null);
    BinaryResourceHolder holder = new BinaryResourceHolder(res);
    storage.put(KEY, holder, OpenUriAction.NEW_WINDOW);
    assertEquals(1, storage.futureMap().size());
    BinaryResourceHolderWithAction holderWithAction = storage.get(KEY);
    assertEquals(OpenUriAction.NEW_WINDOW, holderWithAction.getOpenUriAction());
    assertEquals(res, holderWithAction.getHolder().get());
    assertFalse("Must not contain download interceptor.", containsDownloadInterceptor(holderWithAction.getHolder()));
    holderWithAction = storage.get(KEY);
    assertEquals(res, holderWithAction.getHolder().get());
    assertTrue("Must contain download interceptor.", containsDownloadInterceptor(holderWithAction.getHolder()));
    secondGet.countDown();
    waitFor(elementRemoved);
    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) CountDownLatch(java.util.concurrent.CountDownLatch) 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 2 with BinaryResourceHolderWithAction

use of org.eclipse.scout.rt.ui.html.json.desktop.DownloadHandlerStorage.BinaryResourceHolderWithAction 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)

Aggregations

BinaryResource (org.eclipse.scout.rt.platform.resource.BinaryResource)2 BinaryResourceHolderWithAction (org.eclipse.scout.rt.ui.html.json.desktop.DownloadHandlerStorage.BinaryResourceHolderWithAction)2 BinaryResourceHolder (org.eclipse.scout.rt.ui.html.res.BinaryResourceHolder)2 Test (org.junit.Test)2 CountDownLatch (java.util.concurrent.CountDownLatch)1