Search in sources :

Example 1 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.

the class AbstractOutline method findPage.

@Override
public <T extends IPage> T findPage(final Class<T> pageType) {
    final Holder<T> result = new Holder<T>(pageType, null);
    ITreeVisitor v = new ITreeVisitor() {

        @Override
        @SuppressWarnings("unchecked")
        public boolean visit(ITreeNode node) {
            IPage<?> page = (IPage) node;
            Class<? extends IPage> pageClass = page.getClass();
            if (pageType.isAssignableFrom(pageClass)) {
                result.setValue((T) page);
            }
            return result.getValue() == null;
        }
    };
    visitNode(getRootNode(), v);
    return result.getValue();
}
Also used : IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) Holder(org.eclipse.scout.rt.platform.holders.Holder) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Example 2 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.

the class WhenDoneTest method testError.

@Test
public void testError() throws InterruptedException {
    // synchronized because modified/read by different threads.
    final List<String> protocol = Collections.synchronizedList(new ArrayList<String>());
    final Holder<DoneEvent<String>> eventHolder = new Holder<>();
    final ProcessingException pe = new ProcessingException("expected JUnit test exception");
    final IFuture<String> future = Jobs.schedule(new Callable<String>() {

        @Override
        public String call() throws Exception {
            protocol.add("1");
            throw pe;
        }
    }, Jobs.newInput().withExceptionHandling(null, false).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.SECONDS)));
    final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
    future.whenDone(new IDoneHandler<String>() {

        @Override
        public void onDone(DoneEvent<String> event) {
            protocol.add("2");
            if (future.isDone()) {
                protocol.add("done");
            }
            if (future.isCancelled()) {
                protocol.add("cancelled");
            }
            eventHolder.setValue(event);
            verifyLatch.countDown();
        }
    }, RunContexts.copyCurrent());
    assertTrue(verifyLatch.await());
    assertEquals(CollectionUtility.arrayList("1", "2", "done"), protocol);
    assertSame(pe, eventHolder.getValue().getException());
    assertNull(eventHolder.getValue().getResult());
    assertFalse(eventHolder.getValue().isCancelled());
    assertTrue(eventHolder.getValue().isFailed());
}
Also used : BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) Holder(org.eclipse.scout.rt.platform.holders.Holder) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 3 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.

the class WhenDoneTest method testCancel.

@Test
public void testCancel() throws InterruptedException {
    // synchronized because modified/read by different threads.
    final List<String> protocol = Collections.synchronizedList(new ArrayList<String>());
    final Holder<DoneEvent<String>> eventHolder = new Holder<>();
    final IFuture<String> future = Jobs.schedule(new Callable<String>() {

        @Override
        public String call() throws Exception {
            protocol.add("1");
            return "result";
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()).withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(1, TimeUnit.SECONDS)));
    future.cancel(true);
    final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
    future.whenDone(new IDoneHandler<String>() {

        @Override
        public void onDone(DoneEvent<String> event) {
            protocol.add("2");
            if (future.isDone()) {
                protocol.add("done");
            }
            if (future.isCancelled()) {
                protocol.add("cancelled");
            }
            eventHolder.setValue(event);
            verifyLatch.countDown();
        }
    }, RunContexts.copyCurrent());
    assertTrue(verifyLatch.await());
    assertEquals(CollectionUtility.arrayList("2", "done", "cancelled"), protocol);
    assertNull(eventHolder.getValue().getException());
    assertNull(eventHolder.getValue().getResult());
    assertTrue(eventHolder.getValue().isCancelled());
    assertFalse(eventHolder.getValue().isFailed());
}
Also used : BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) Holder(org.eclipse.scout.rt.platform.holders.Holder) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 4 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.

the class WhenDoneTest method testCancelWithJobAlreadyCompleted.

@Test
public void testCancelWithJobAlreadyCompleted() throws InterruptedException {
    // synchronized because modified/read by different threads.
    final List<String> protocol = Collections.synchronizedList(new ArrayList<String>());
    final Holder<DoneEvent<String>> eventHolder = new Holder<>();
    final IFuture<String> future = Jobs.schedule(new Callable<String>() {

        @Override
        public String call() throws Exception {
            protocol.add("1");
            return "result";
        }
    }, Jobs.newInput().withRunContext(RunContexts.copyCurrent()));
    future.awaitDoneAndGet();
    future.cancel(true);
    final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
    future.whenDone(new IDoneHandler<String>() {

        @Override
        public void onDone(DoneEvent<String> event) {
            protocol.add("2");
            if (future.isDone()) {
                protocol.add("done");
            }
            if (future.isCancelled()) {
                protocol.add("cancelled");
            }
            eventHolder.setValue(event);
            verifyLatch.countDown();
        }
    }, RunContexts.copyCurrent());
    assertTrue(verifyLatch.await());
    assertEquals(CollectionUtility.arrayList("1", "2", "done"), protocol);
    assertNull(eventHolder.getValue().getException());
    assertEquals("result", eventHolder.getValue().getResult());
    assertFalse(eventHolder.getValue().isCancelled());
    assertFalse(eventHolder.getValue().isFailed());
}
Also used : BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) Holder(org.eclipse.scout.rt.platform.holders.Holder) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Example 5 with Holder

use of org.eclipse.scout.rt.platform.holders.Holder in project scout.rt by eclipse.

the class WhenDoneTest method testErrorWithJobAlreadyCompleted.

@Test
public void testErrorWithJobAlreadyCompleted() throws InterruptedException {
    // synchronized because modified/read by different threads.
    final List<String> protocol = Collections.synchronizedList(new ArrayList<String>());
    final Holder<DoneEvent<String>> eventHolder = new Holder<>();
    final Exception error = new ProcessingException("expected JUnit test exception");
    final IFuture<String> future = Jobs.schedule(new Callable<String>() {

        @Override
        public String call() throws Exception {
            protocol.add("1");
            throw error;
        }
    }, Jobs.newInput().withExceptionHandling(null, false));
    try {
        future.awaitDoneAndGet();
        fail("exception expected");
    } catch (ProcessingException e) {
        final BlockingCountDownLatch verifyLatch = new BlockingCountDownLatch(1);
        future.whenDone(new IDoneHandler<String>() {

            @Override
            public void onDone(DoneEvent<String> event) {
                protocol.add("2");
                if (future.isDone()) {
                    protocol.add("done");
                }
                if (future.isCancelled()) {
                    protocol.add("cancelled");
                }
                eventHolder.setValue(event);
                verifyLatch.countDown();
            }
        }, RunContexts.copyCurrent());
        assertTrue(verifyLatch.await());
        assertEquals(CollectionUtility.arrayList("1", "2", "done"), protocol);
        assertSame(error, eventHolder.getValue().getException());
        assertNull(eventHolder.getValue().getResult());
        assertFalse(eventHolder.getValue().isCancelled());
        assertTrue(eventHolder.getValue().isFailed());
    }
}
Also used : BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) Holder(org.eclipse.scout.rt.platform.holders.Holder) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) Test(org.junit.Test)

Aggregations

Holder (org.eclipse.scout.rt.platform.holders.Holder)28 Test (org.junit.Test)20 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)6 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)6 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)6 IHolder (org.eclipse.scout.rt.platform.holders.IHolder)4 IPropertyHolder (org.eclipse.scout.rt.shared.data.form.IPropertyHolder)4 SocketTimeoutException (java.net.SocketTimeoutException)3 List (java.util.List)3 WebServiceException (javax.xml.ws.WebServiceException)3 JaxWsConsumerTestServicePortType (org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.JaxWsConsumerTestServicePortType)3 IFormFieldVisitor (org.eclipse.scout.rt.client.ui.form.IFormFieldVisitor)3 IFormField (org.eclipse.scout.rt.client.ui.form.fields.IFormField)3 CallableChain (org.eclipse.scout.rt.platform.chain.callable.CallableChain)3 PlatformError (org.eclipse.scout.rt.platform.exception.PlatformError)3 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 IExtensibleObject (org.eclipse.scout.rt.shared.extension.IExtensibleObject)3 InOrder (org.mockito.InOrder)3 InvocationHandler (java.lang.reflect.InvocationHandler)2 Method (java.lang.reflect.Method)2