Search in sources :

Example 6 with IBean

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

the class ClientSessionTest method testStopWithBlockingMessageBox.

@Test
public void testStopWithBlockingMessageBox() 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()));
    // 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)));
    try {
        f.awaitDoneAndGet(1, TimeUnit.SECONDS);
        fail("must throw a " + TimedOutError.class.getName());
    } catch (TimedOutError e) {
    // nop
    }
    assertFalse(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();
    assertEquals(JobState.DONE, f.getState());
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IBeanInstanceProducer(org.eclipse.scout.rt.platform.IBeanInstanceProducer) JobCompletionDelayOnSessionShutdown(org.eclipse.scout.rt.client.ClientConfigProperties.JobCompletionDelayOnSessionShutdown) TimedOutError(org.eclipse.scout.rt.platform.util.concurrent.TimedOutError) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) IBean(org.eclipse.scout.rt.platform.IBean) TestEnvironmentClientSession(org.eclipse.scout.rt.client.testenvironment.TestEnvironmentClientSession) Test(org.junit.Test)

Example 7 with IBean

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

the class PermissionServiceTest method testImpl.

/* ---------------------------------------------------------------------------------------------- */
/* Tests for Bug 398323 - CodeService / PermissionService: More fine-grained lookup strategies for finding classes */
/* ---------------------------------------------------------------------------------------------- */
private void testImpl(IPermissionService testService, boolean testPermission1Expected, boolean testPermission2Expected) {
    List<IBean<?>> reg = TestingUtility.registerBeans(new BeanMetaData(IPermissionService.class).withInitialInstance(testService).withApplicationScoped(true));
    try {
        IPermissionService service = BEANS.get(IPermissionService.class);
        assertSame(testService, service);
        // 
        Set<Class<? extends Permission>> result = service.getAllPermissionClasses();
        boolean testPermission1Found = false;
        boolean testPermission2Found = false;
        for (Class<?> b : result) {
            if (ObjectUtility.equals(b.getName(), TestPermission1.class.getName())) {
                testPermission1Found = true;
            }
            if (ObjectUtility.equals(b.getName(), TestPermission2.class.getName())) {
                testPermission2Found = true;
            }
        }
        // 
        if (testPermission1Expected) {
            assertTrue("TestPermission1 class not found (expected: found)", testPermission1Found);
        } else {
            assertFalse("TestPermission1 class found (expected: not found)", testPermission1Found);
        }
        if (testPermission2Expected) {
            assertTrue("TestPermission2 class not found (expected: found)", testPermission2Found);
        } else {
            assertFalse("TestPermission2 class found (expected: not found)", testPermission2Found);
        }
    } finally {
        TestingUtility.unregisterBeans(reg);
    }
}
Also used : IPermissionService(org.eclipse.scout.rt.shared.services.common.security.IPermissionService) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) TestPermission1(org.eclipse.scout.rt.server.services.common.security.fixture.TestPermission1) TestPermission2(org.eclipse.scout.rt.server.services.common.security.fixture.TestPermission2) Permission(java.security.Permission) IBean(org.eclipse.scout.rt.platform.IBean)

Example 8 with IBean

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

the class BeanAnnotations method init.

/**
 * Initialize fields annotated with {@link BeanMock}
 */
public void init(Object testObj) {
    List<IBean<?>> regs = new ArrayList<IBean<?>>();
    Field[] fields = testObj.getClass().getDeclaredFields();
    for (Field f : fields) {
        if (isBeanMock(f)) {
            regs.add(registerMock(testObj, f));
        }
    }
    m_regs = Collections.unmodifiableList(regs);
}
Also used : Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) IBean(org.eclipse.scout.rt.platform.IBean)

Example 9 with IBean

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

the class JandexTypeNameIdResolverTest method testPoJoInterfaceWithMultipleImplementation.

@Test
public void testPoJoInterfaceWithMultipleImplementation() {
    List<IBean<?>> registeredBeans = new ArrayList<>();
    try {
        registeredBeans.add(TestingUtility.registerBean(new BeanMetaData(Person.class)));
        registeredBeans.add(TestingUtility.registerBean(new BeanMetaData(ProjectPerson2.class).withReplace(true)));
        registeredBeans.add(TestingUtility.registerBean(new BeanMetaData(Company.class)));
        registeredBeans.add(TestingUtility.registerBean(new BeanMetaData(ProjectCompany2.class).withReplace(true)));
        CustomerResponse2 customerResponse = new CustomerResponse2();
        customerResponse.customers = new ArrayList<>();
        customerResponse.customers.add(BEANS.get(ProjectPerson2.class));
        customerResponse.customers.add(BEANS.get(ProjectCompany2.class));
        marshallUnmarshall(customerResponse);
    } finally {
        TestingUtility.unregisterBeans(registeredBeans);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) ArrayList(java.util.ArrayList) IBean(org.eclipse.scout.rt.platform.IBean) Test(org.junit.Test)

Example 10 with IBean

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

the class JandexTypeNameIdResolverTest method testBeanInterfaceWithMultipleImplementation.

@Test
public void testBeanInterfaceWithMultipleImplementation() {
    List<IBean<?>> registeredBeans = new ArrayList<>();
    try {
        registeredBeans.add(TestingUtility.registerBean(new BeanMetaData(Person.class)));
        registeredBeans.add(TestingUtility.registerBean(new BeanMetaData(ProjectPerson.class).withReplace(true)));
        runTestBeanInterfaceWithMultipleImplementation();
        registeredBeans.add(TestingUtility.registerBean(new BeanMetaData(Company.class)));
        registeredBeans.add(TestingUtility.registerBean(new BeanMetaData(ProjectCompany.class).withReplace(true)));
        runTestBeanInterfaceWithMultipleImplementation();
        CustomerResponse customerResponse = new CustomerResponse();
        customerResponse.customers = new ArrayList<>();
        customerResponse.customers.add(BEANS.get(ProjectPerson.class));
        customerResponse.customers.add(BEANS.get(ProjectCompany.class));
        marshallUnmarshall(customerResponse);
    } finally {
        TestingUtility.unregisterBeans(registeredBeans);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) ArrayList(java.util.ArrayList) IBean(org.eclipse.scout.rt.platform.IBean) Test(org.junit.Test)

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