Search in sources :

Example 26 with Holder

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

the class TreeProposalChooser method getNode.

/**
 * Node with a given key. Assumes the node is already loaded at this point
 */
private ITreeNode getNode(final LOOKUP_KEY key) {
    final Holder<ITreeNode> holder = new Holder<>(ITreeNode.class);
    m_model.visitTree(new ITreeVisitor() {

        @Override
        public boolean visit(ITreeNode node) {
            if (node.getCell().getValue() instanceof ILookupRow && ObjectUtility.equals(((ILookupRow) node.getCell().getValue()).getKey(), key)) {
                holder.setValue(node);
                return false;
            }
            return true;
        }
    });
    return holder.getValue();
}
Also used : ITreeNode(org.eclipse.scout.rt.client.ui.basic.tree.ITreeNode) ILookupRow(org.eclipse.scout.rt.shared.services.lookup.ILookupRow) Holder(org.eclipse.scout.rt.platform.holders.Holder) ITreeVisitor(org.eclipse.scout.rt.client.ui.basic.tree.ITreeVisitor)

Example 27 with Holder

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

the class AbstractJaxWsClientTest method testAcquirePortInDifferentTransactionsCancelFirstOne.

/**
 * Canceling a running web service invocation invalidates the port. This test verifies, that the canceled port is not
 * put back into the pool.
 */
@Test
public void testAcquirePortInDifferentTransactionsCancelFirstOne() throws InterruptedException {
    final Holder<JaxWsConsumerTestServicePortType> txn1PortHolder = new Holder<>(JaxWsConsumerTestServicePortType.class);
    final Holder<JaxWsConsumerTestServicePortType> txn2PortHolder = new Holder<>(JaxWsConsumerTestServicePortType.class);
    // This test case expects at most one port in the pool. It is guaranteed by discarding all pooled entries.
    BEANS.get(JaxWsConsumerTestClient.class).discardAllPoolEntries();
    final CountDownLatch requestRunningLatch = new CountDownLatch(1);
    final IFuture<Void> future = Jobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            JaxWsConsumerTestServicePortType port = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().getPort();
            txn1PortHolder.setValue(port);
            SleepRequest req = new SleepRequest();
            req.setMillis(1000);
            requestRunningLatch.countDown();
            port.sleep(req);
        }
    }, Jobs.newInput().withRunContext(ServerRunContexts.copyCurrent()).withExceptionHandling(null, true));
    requestRunningLatch.await();
    SleepUtil.sleepSafe(50, TimeUnit.MILLISECONDS);
    Jobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            future.cancel(true);
        }
    }, Jobs.newInput().withRunContext(ServerRunContexts.copyCurrent()));
    try {
        future.awaitDone();
    } catch (WebServiceRequestCancelledException e) {
    // NOSONAR
    // expected
    }
    assertTrue(future.isCancelled());
    ServerRunContexts.copyCurrent().run(new IRunnable() {

        @Override
        public void run() throws Exception {
            JaxWsConsumerTestServicePortType port = BEANS.get(JaxWsConsumerTestClient.class).newInvocationContext().getPort();
            assertSendEcho(port, 0);
            txn2PortHolder.setValue(port);
        }
    });
    assertDifferentPort(txn1PortHolder.getValue(), txn2PortHolder.getValue());
}
Also used : SleepRequest(org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.SleepRequest) Holder(org.eclipse.scout.rt.platform.holders.Holder) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) CountDownLatch(java.util.concurrent.CountDownLatch) JaxWsConsumerTestServicePortType(org.eclipse.scout.jaxws.consumer.jaxwsconsumertestservice.JaxWsConsumerTestServicePortType) SocketTimeoutException(java.net.SocketTimeoutException) WebServiceException(javax.xml.ws.WebServiceException) Test(org.junit.Test)

Example 28 with Holder

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

the class JsonOutlineTest method testNoEventsFiredOnChildPageCreation.

/**
 * Tests that no events are fired during page initialization
 */
@Test
public void testNoEventsFiredOnChildPageCreation() throws JSONException {
    final Holder<Integer> initPageCounter = new Holder<>(Integer.class);
    initPageCounter.setValue(0);
    // Build an outline with two nodes, where the second node has a child node
    IPage page1 = new AbstractPageWithNodes() {
    };
    IPage page2 = new AbstractPageWithNodes() {

        @Override
        protected void execCreateChildPages(List<IPage<?>> pageList) {
            pageList.add(new AbstractPageWithNodes() {

                @Override
                protected void execInitPage() {
                    // Change some properties (this would normally fire events, but we are inside execInitPage())
                    setLeaf(!isLeaf());
                    getCellForUpdate().setText("Test");
                    initPageCounter.setValue(initPageCounter.getValue() + 1);
                }
            });
            super.execCreateChildPages(pageList);
        }
    };
    List<IPage<?>> pages = new ArrayList<IPage<?>>();
    pages.add(page2);
    IOutline outline = new Outline(pages);
    outline.selectNode(page1);
    // Outline to JsonOutline
    JsonOutline<IOutline> jsonOutline = UiSessionTestUtility.newJsonAdapter(m_uiSession, outline, m_uiSession.getRootJsonAdapter());
    // simulate "send to client"
    jsonOutline.toJson();
    Assert.assertEquals(0, initPageCounter.getValue().intValue());
    // Simulate "select page2" event
    JsonEvent event = createNodeSelectionEvent(jsonOutline, page2);
    jsonOutline.handleUiEvent(event);
    assertEquals(1, initPageCounter.getValue().intValue());
    // Get all events for the outline (ignore table events)
    List<JsonEvent> responseEvents = JsonTestUtility.extractEventsFromResponse(m_uiSession.currentJsonResponse(), null, jsonOutline.getId());
    // Check that we got only two events: page-changed (because the table was created), node insertion
    assertEquals(2, responseEvents.size());
    assertEquals("pageChanged", responseEvents.get(0).getType());
    assertEquals(JsonTree.EVENT_NODES_INSERTED, responseEvents.get(1).getType());
}
Also used : AbstractPageWithNodes(org.eclipse.scout.rt.client.ui.desktop.outline.pages.AbstractPageWithNodes) Holder(org.eclipse.scout.rt.platform.holders.Holder) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) ArrayList(java.util.ArrayList) JsonEvent(org.eclipse.scout.rt.ui.html.json.JsonEvent) Outline(org.eclipse.scout.rt.ui.html.json.desktop.fixtures.Outline) IOutline(org.eclipse.scout.rt.client.ui.desktop.outline.IOutline) IPage(org.eclipse.scout.rt.client.ui.desktop.outline.pages.IPage) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) JsonTreeTest(org.eclipse.scout.rt.ui.html.json.tree.JsonTreeTest) 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