Search in sources :

Example 1 with IBean

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

the class FileServiceTest method syncRemoteFilesToPath.

@Test
public void syncRemoteFilesToPath() {
    // register services
    List<IBean<?>> reg = TestingUtility.registerBeans(new BeanMetaData(DummyRemoteFileService.class).withInitialInstance(new DummyRemoteFileService()).withApplicationScoped(true));
    // start with clean setup
    File outFolder = new File(TEST_DIR_OUT);
    assertFalse("Folder is not synchronized yet, but exists", outFolder.exists());
    try {
        // synchronize test folder to path
        FileService svc = new FileService();
        svc.syncRemoteFilesToPath(TEST_DIR_OUT, TEST_DIR_IN, null);
        File synchronizedFile = new File(TEST_PATH_1);
        File synchronizedFile2 = new File(TEST_PATH_2);
        File synchronizedFolder = new File(TEST_DIR_OUT);
        assertTrue("Synchronized file does not exist " + synchronizedFile, synchronizedFile.exists());
        assertTrue("Synchronized file does not exist " + synchronizedFile2, synchronizedFile2.exists());
        assertTrue("Synchronized folder does not exist " + synchronizedFolder, synchronizedFolder.exists());
        assertTrue("Incorrect number of synchronized files", synchronizedFolder.listFiles().length == 2);
        // synchronize again
        svc.syncRemoteFilesToPath(TEST_DIR_OUT, TEST_DIR_IN, null);
        assertTrue("Synchronized file does not exist " + synchronizedFile, synchronizedFile.exists());
        assertTrue("Synchronized file does not exist " + synchronizedFile2, synchronizedFile2.exists());
        assertTrue("Synchronized folder does not exist " + synchronizedFolder, synchronizedFolder.exists());
        assertTrue("Incorrect number of synchronized files", synchronizedFolder.listFiles().length == 2);
    } finally {
        TestingUtility.unregisterBeans(reg);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IRemoteFileService(org.eclipse.scout.rt.shared.services.common.file.IRemoteFileService) IBean(org.eclipse.scout.rt.platform.IBean) File(java.io.File) RemoteFile(org.eclipse.scout.rt.shared.services.common.file.RemoteFile) Test(org.junit.Test)

Example 2 with IBean

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

the class BeanManagerImplementor method getDecoratedBeans.

protected <T> List<IBean<T>> getDecoratedBeans(List<IBean<T>> beans, Class<T> beanClazz) {
    IBeanDecorationFactory beanDecorationFactory = getBeanDecorationFactory();
    if (beanDecorationFactory == null || !beanClazz.isInterface()) {
        return beans;
    }
    // apply decorations
    List<IBean<T>> result = new ArrayList<IBean<T>>(beans.size());
    for (IBean<T> bean : beans) {
        result.add(getDecoratedBean(bean, beanClazz, beanDecorationFactory));
    }
    return result;
}
Also used : IBeanDecorationFactory(org.eclipse.scout.rt.platform.IBeanDecorationFactory) ArrayList(java.util.ArrayList) IBean(org.eclipse.scout.rt.platform.IBean)

Example 3 with IBean

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

the class ClientSessionTest method testStopWithBlockingClientCallback.

@Test
public void testStopWithBlockingClientCallback() throws Exception {
    TestingUtility.registerBean(new BeanMetaData(TestEnvironmentClientSession.class));
    TestingUtility.registerBean(new BeanMetaData(JobCompletionDelayOnSessionShutdown.class).withProducer(new IBeanInstanceProducer<JobCompletionDelayOnSessionShutdown>() {

        @Override
        public JobCompletionDelayOnSessionShutdown produce(IBean<JobCompletionDelayOnSessionShutdown> bean) {
            return new JobCompletionDelayOnSessionShutdown() {

                @Override
                protected Long getDefaultValue() {
                    return 1000L;
                }
            };
        }
    }));
    session = BEANS.get(ClientSessionProvider.class).provide(ClientRunContexts.empty().withUserAgent(UserAgents.createDefault()));
    // request a geo location
    Future<Coordinates> geo = ModelJobs.schedule(new Callable<Future<Coordinates>>() {

        @Override
        public Future<Coordinates> call() throws Exception {
            return IDesktop.CURRENT.get().requestGeolocation();
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDoneAndGet();
    assertFalse(geo.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();
    assertTrue(geo.isCancelled());
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IBeanInstanceProducer(org.eclipse.scout.rt.platform.IBeanInstanceProducer) Coordinates(org.eclipse.scout.rt.client.ui.Coordinates) JobCompletionDelayOnSessionShutdown(org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IBean(org.eclipse.scout.rt.platform.IBean) Callable(java.util.concurrent.Callable) TestEnvironmentClientSession(org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession) Test(org.junit.Test)

Example 4 with IBean

use of org.eclipse.scout.rt.platform.IBean 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 5 with IBean

use of org.eclipse.scout.rt.platform.IBean 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)

Aggregations

IBean (org.eclipse.scout.rt.platform.IBean)12 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)9 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)4 Subject (javax.security.auth.Subject)2 JobCompletionDelayOnSessionShutdown (org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown)2 TestEnvironmentClientSession (org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession)2 IBeanInstanceProducer (org.eclipse.scout.rt.platform.IBeanInstanceProducer)2 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)2 RunWithSubject (org.eclipse.scout.rt.testing.platform.runner.RunWithSubject)2 SafeStatementInvoker (org.eclipse.scout.rt.testing.platform.runner.SafeStatementInvoker)2 File (java.io.File)1 Field (java.lang.reflect.Field)1 Permission (java.security.Permission)1 Callable (java.util.concurrent.Callable)1 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 Coordinates (org.eclipse.scout.rt.client.ui.Coordinates)1 IBeanDecorationFactory (org.eclipse.scout.rt.platform.IBeanDecorationFactory)1 IBeanManager (org.eclipse.scout.rt.platform.IBeanManager)1 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)1