Search in sources :

Example 36 with BeanMetaData

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

the class PlatformTestRunner method interceptMethodLevelStatement.

/**
 * Overwrite this method to contribute some 'method-level' behavior to this Runner.
 * <p>
 * Contributions are plugged according to the design pattern: 'chain-of-responsibility' - it is easiest to read the
 * chain from 'bottom-to-top'.
 * <p>
 * To contribute on top of the chain (meaning that you are invoked <strong>after</strong> the contributions of super
 * classes and therefore can base on their contributed functionality), you can use constructions of the following
 * form:
 * <p>
 * <code>
 *   Statement s2 = new YourInterceptor2(<strong>next</strong>); // executed 3th<br/>
 *   Statement s1 = new YourInterceptor1(s2); // executed 2nd<br/>
 *   Statement head = <i>super.interceptMethodLevelStatement(s1)</i>; // executed 1st<br/>
 *   return head;
 * </code>
 * </p>
 * To be invoked <strong>before</strong> the super class contributions, you can use constructions of the following
 * form:
 * <p>
 * <code>
 *   Statement s2 = <i>super.interceptMethodLevelStatement(<strong>next</strong>)</i>; // executed 3th<br/>
 *   Statement s1 = new YourInterceptor2(s2); // executed 2nd<br/>
 *   Statement head = new YourInterceptor1(s1); // executed 1st<br/>
 *   return head;
 * </code>
 *
 * @param next
 *          subsequent {@link Statement}.
 * @return the head of the chain to be invoked first.
 */
protected Statement interceptMethodLevelStatement(final Statement next, final Class<?> testClass, final Method testMethod) {
    final Statement s5 = new ClearThreadInterruptionStatusStatement(next);
    final Statement s4 = new SubjectStatement(s5, ReflectionUtility.getAnnotation(RunWithSubject.class, testMethod, testClass));
    // exception handler to not silently swallow handled exceptions.
    final Statement s3 = new RegisterBeanStatement(s4, new BeanMetaData(JUnitExceptionHandler.class).withReplace(true).withOrder(-1000));
    final Statement s2 = new AssertNoRunningJobsStatement(s3, "Test method");
    final Statement s1 = new TimesStatement(s2, ReflectionUtility.getAnnotation(Times.class, testMethod, testClass));
    return s1;
}
Also used : SubjectStatement(org.eclipse.scout.rt.testing.platform.runner.statement.SubjectStatement) TimesStatement(org.eclipse.scout.rt.testing.platform.runner.statement.TimesStatement) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) Statement(org.junit.runners.model.Statement) SubjectStatement(org.eclipse.scout.rt.testing.platform.runner.statement.SubjectStatement) BeanAnnotationsCleanupStatement(org.eclipse.scout.rt.testing.platform.runner.statement.BeanAnnotationsCleanupStatement) AssertNoRunningJobsStatement(org.eclipse.scout.rt.testing.platform.runner.statement.AssertNoRunningJobsStatement) TimeoutRunContextStatement(org.eclipse.scout.rt.testing.platform.runner.statement.TimeoutRunContextStatement) BeanAnnotationsInitStatement(org.eclipse.scout.rt.testing.platform.runner.statement.BeanAnnotationsInitStatement) RegisterBeanStatement(org.eclipse.scout.rt.testing.platform.runner.statement.RegisterBeanStatement) ThrowHandledExceptionStatement(org.eclipse.scout.rt.testing.platform.runner.statement.ThrowHandledExceptionStatement) ClearThreadInterruptionStatusStatement(org.eclipse.scout.rt.testing.platform.runner.statement.ClearThreadInterruptionStatusStatement) RunContextStatement(org.eclipse.scout.rt.testing.platform.runner.statement.RunContextStatement) PlatformStatement(org.eclipse.scout.rt.testing.platform.runner.statement.PlatformStatement) TransactionAddFailureOnAnyExceptionStatement(org.eclipse.scout.rt.testing.platform.runner.statement.TransactionAddFailureOnAnyExceptionStatement) TimesStatement(org.eclipse.scout.rt.testing.platform.runner.statement.TimesStatement) RegisterBeanStatement(org.eclipse.scout.rt.testing.platform.runner.statement.RegisterBeanStatement) ClearThreadInterruptionStatusStatement(org.eclipse.scout.rt.testing.platform.runner.statement.ClearThreadInterruptionStatusStatement) AssertNoRunningJobsStatement(org.eclipse.scout.rt.testing.platform.runner.statement.AssertNoRunningJobsStatement)

Example 37 with BeanMetaData

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

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

the class JandexTypeNameIdResolverTest method testPoJoClassWithMultipleImplementation.

/**
 * Test-case with a base class and two subclasses which do not specify an own JSON type identifier.
 * <p>
 * This example is a completeness test for JandexTypeNameIdResolver, in a normal case this scenario is not
 * reproducible due to a check for duplicated replaced classes within bean manager. This test case should fail, since
 * JandexTypeNameIdResolver cannot find the correct matching class if more than one matching subclass is available.
 */
@Test(expected = InvalidTypeIdException.class)
public void testPoJoClassWithMultipleImplementation() throws Exception {
    IBean<?> personBean = TestingUtility.registerBean(new BeanMetaData(ProjectPerson.class));
    IBean<?> person2Bean = TestingUtility.registerBean(new BeanMetaData(ProjectPerson2.class));
    try {
        String json = "{\"persons\":[{\"type\":\"Person\"},{\"type\":\"Person\"}]}";
        ObjectMapper mapper = new ObjectMapper();
        mapper.setAnnotationIntrospector(BEANS.get(JandexJacksonAnnotationIntrospector.class));
        mapper.readValue(json, PersonResponse.class);
    } finally {
        TestingUtility.unregisterBean(personBean);
        TestingUtility.unregisterBean(person2Bean);
    }
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 39 with BeanMetaData

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

the class JandexTypeNameIdResolverTest method beforeClass.

@BeforeClass
public static void beforeClass() {
    s_beans.add(TestingUtility.registerBean(new BeanMetaData(CoreBean.class)));
    s_beans.add(TestingUtility.registerBean(new BeanMetaData(ProjectTemplateBean.class).withReplace(true)));
}
Also used : BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) BeforeClass(org.junit.BeforeClass)

Example 40 with BeanMetaData

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

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