Search in sources :

Example 21 with BeanMetaData

use of org.eclipse.scout.rt.platform.BeanMetaData in project scout.rt by eclipse.

the class ClientNotificationRegistryTest method testNotificationsWithoutDistributingOverCluster.

/**
 * Empty collection of notifications must not trigger a cluster notification.
 */
@Test
public void testNotificationsWithoutDistributingOverCluster() {
    final IClusterSynchronizationService mockClusterSyncService = Mockito.mock(IClusterSynchronizationService.class);
    final IBean<?> bean = TestingUtility.registerBean(new BeanMetaData(IClusterSynchronizationService.class).withInitialInstance(mockClusterSyncService).withApplicationScoped(true));
    try {
        ClientNotificationRegistry reg = new ClientNotificationRegistry(TEST_QUEUE_EXPIRE_TIMEOUT);
        reg.registerSession("testNodeId", "testSessionId", TEST_USER);
        reg.registerSession("testNodeId2", "testSessionId", TEST_USER);
        reg.putForAllNodes(TEST_NOTIFICATION, false);
        List<ClientNotificationMessage> notificationsNode1 = consumeNoWait(reg, "testNodeId");
        List<ClientNotificationMessage> notificationsNode2 = consumeNoWait(reg, "testNodeId2");
        assertSingleTestNotification(notificationsNode1);
        assertSingleTestNotification(notificationsNode2);
        Mockito.verifyZeroInteractions(mockClusterSyncService);
    } finally {
        TestingUtility.unregisterBean(bean);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IClusterSynchronizationService(org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService) ClientNotificationMessage(org.eclipse.scout.rt.shared.clientnotification.ClientNotificationMessage) Test(org.junit.Test)

Example 22 with BeanMetaData

use of org.eclipse.scout.rt.platform.BeanMetaData in project scout.rt by eclipse.

the class ClientNotificationRegistryTest method testEmptyNotificationsAreNotDistributedOverCluster.

/**
 * Empty collection of notifications must not trigger a cluster notification.
 */
@Test
public void testEmptyNotificationsAreNotDistributedOverCluster() {
    final IClusterSynchronizationService mockClusterSyncService = Mockito.mock(IClusterSynchronizationService.class);
    final IBean<?> bean = TestingUtility.registerBean(new BeanMetaData(IClusterSynchronizationService.class).withInitialInstance(mockClusterSyncService).withApplicationScoped(true));
    try {
        ClientNotificationRegistry reg = new ClientNotificationRegistry(TEST_QUEUE_EXPIRE_TIMEOUT);
        reg.registerSession("testNodeId", "testSessionId", TEST_USER);
        reg.publish(Collections.<ClientNotificationMessage>emptySet());
        assertEquals(Collections.emptyList(), consumeNoWait(reg, "testNodeId"));
        Mockito.verifyZeroInteractions(mockClusterSyncService);
    } finally {
        TestingUtility.unregisterBean(bean);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IClusterSynchronizationService(org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService) Test(org.junit.Test)

Example 23 with BeanMetaData

use of org.eclipse.scout.rt.platform.BeanMetaData in project scout.rt by eclipse.

the class ServerRunContextStatement method evaluateWithServerRunContext.

private void evaluateWithServerRunContext() throws Throwable {
    final Subject currentSubject = Subject.getSubject(AccessController.getContext());
    if (currentSubject == null) {
        Assertions.fail("Subject must not be null. Use the annotation '{}' to execute your test under a particular user. ", RunWithSubject.class.getSimpleName());
    }
    UserAgent userAgent = UserAgents.createDefault();
    Class<? extends ISession> sessionClass = m_serverSessionAnnotation.value();
    IBean<? extends ISession> sessionBean = BEANS.getBeanManager().uniqueBean(sessionClass);
    if (sessionBean != null) {
        sessionClass = sessionBean.getBeanClazz();
    }
    final IBean serverSessionBean = BEANS.getBeanManager().registerBean(new BeanMetaData(sessionClass).withOrder(-Long.MAX_VALUE));
    try {
        // Obtain the server session for the given subject. Depending on the session provider, a new session is created or a cached session returned.
        final IServerSession serverSession = BEANS.get(m_serverSessionAnnotation.provider()).provide(ServerRunContexts.copyCurrent().withSubject(currentSubject).withUserAgent(userAgent));
        // Run the test on behalf of a ServerRunContext.
        final SafeStatementInvoker invoker = new SafeStatementInvoker(m_next);
        ServerRunContexts.copyCurrent().withSession(serverSession).withSubject(// set the test subject explicitly in case it is different to the session subject
        currentSubject).withUserAgent(userAgent).run(invoker);
        invoker.throwOnError();
    } finally {
        BEANS.getBeanManager().unregisterBean(serverSessionBean);
    }
}
Also used : RunWithSubject(org.eclipse.scout.rt.testing.platform.runner.RunWithSubject) SafeStatementInvoker(org.eclipse.scout.rt.testing.platform.runner.SafeStatementInvoker) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) UserAgent(org.eclipse.scout.rt.shared.ui.UserAgent) IServerSession(org.eclipse.scout.rt.server.IServerSession) IBean(org.eclipse.scout.rt.platform.IBean) RunWithSubject(org.eclipse.scout.rt.testing.platform.runner.RunWithSubject) Subject(javax.security.auth.Subject)

Example 24 with BeanMetaData

use of org.eclipse.scout.rt.platform.BeanMetaData in project scout.rt by eclipse.

the class ClientRunContextStatement method evaluateWithClientRunContext.

private void evaluateWithClientRunContext() throws Throwable {
    final Subject currentSubject = Subject.getSubject(AccessController.getContext());
    if (currentSubject == null) {
        Assertions.fail("Subject must not be null. Use the annotation '{}' to execute your test under a particular user. ", RunWithSubject.class.getSimpleName());
    }
    Class<? extends ISession> sessionClass = m_clientSessionAnnotation.value();
    IBean<? extends ISession> sessionBean = BEANS.getBeanManager().uniqueBean(sessionClass);
    if (sessionBean != null) {
        sessionClass = sessionBean.getBeanClazz();
    }
    final IBean clientSessionBean = BEANS.getBeanManager().registerBean(new BeanMetaData(sessionClass).withOrder(-Long.MAX_VALUE));
    try {
        // Obtain the client session for the given subject. Depending on the session provider, a new session is created or a cached session returned.
        final IClientSession clientSession = BEANS.get(m_clientSessionAnnotation.provider()).provide(ClientRunContexts.copyCurrent().withSubject(currentSubject));
        // Run the test on behalf of a ClientRunContext.
        final SafeStatementInvoker invoker = new SafeStatementInvoker(m_next);
        ClientRunContexts.copyCurrent().withSession(clientSession, true).withSubject(// set the test subject explicitly in case it is different to the session subject
        currentSubject).run(invoker);
        invoker.throwOnError();
    } finally {
        BEANS.getBeanManager().unregisterBean(clientSessionBean);
    }
}
Also used : RunWithSubject(org.eclipse.scout.rt.testing.platform.runner.RunWithSubject) SafeStatementInvoker(org.eclipse.scout.rt.testing.platform.runner.SafeStatementInvoker) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IClientSession(org.eclipse.scout.rt.client.IClientSession) IBean(org.eclipse.scout.rt.platform.IBean) RunWithSubject(org.eclipse.scout.rt.testing.platform.runner.RunWithSubject) Subject(javax.security.auth.Subject)

Example 25 with BeanMetaData

use of org.eclipse.scout.rt.platform.BeanMetaData in project scout.rt by eclipse.

the class ClientSessionTest method testStopWithClosedMessageBox.

@Test
public void testStopWithClosedMessageBox() throws Exception {
    TestingUtility.registerBean(new BeanMetaData(TestEnvironmentClientSession.class));
    session = BEANS.get(ClientSessionProvider.class).provide(ClientRunContexts.empty().withUserAgent(UserAgents.createDefault()));
    // show a messagebox
    IFuture<Integer> f = ModelJobs.schedule(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            messageBox = MessageBoxes.createYesNo();
            return messageBox.show();
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true)));
    // confirm the messagebox
    ModelJobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            messageBox.getUIFacade().setResultFromUI(IMessageBox.YES_OPTION);
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true)));
    int messageBoxResult = f.awaitDoneAndGet().intValue();
    assertEquals(IMessageBox.YES_OPTION, messageBoxResult);
    assertTrue(f.isDone());
    // close from ui
    ModelJobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            session.getDesktop().getUIFacade().closeFromUI(true);
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDone();
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) TestEnvironmentClientSession(org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession) Test(org.junit.Test)

Aggregations

BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)53 Test (org.junit.Test)18 Before (org.junit.Before)11 IBean (org.eclipse.scout.rt.platform.IBean)9 IBeanManager (org.eclipse.scout.rt.platform.IBeanManager)6 TestEnvironmentClientSession (org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession)5 Callable (java.util.concurrent.Callable)3 JobCompletionDelayOnSessionShutdown (org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown)3 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)3 After (org.junit.After)3 ArrayList (java.util.ArrayList)2 Subject (javax.security.auth.Subject)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 IMomImplementor (org.eclipse.scout.rt.mom.api.IMomImplementor)2 NullMomImplementor (org.eclipse.scout.rt.mom.api.NullMomImplementor)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 JaxWsImplementorSpecifics (org.eclipse.scout.rt.server.jaxws.implementor.JaxWsImplementorSpecifics)2 IClusterSynchronizationService (org.eclipse.scout.rt.server.services.common.clustersync.IClusterSynchronizationService)2