Search in sources :

Example 1 with RegisterBeanStatement

use of org.eclipse.scout.rt.testing.platform.runner.statement.RegisterBeanStatement in project scout.rt by eclipse.

the class PlatformTestRunner method interceptClassLevelStatement.

/**
 * Overwrite this method to contribute some 'class-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.interceptClassLevelStatement(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.interceptClassLevelStatement(<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 interceptClassLevelStatement(final Statement next, final Class<?> testClass) {
    final Statement s2 = new SubjectStatement(next, testClass.getAnnotation(RunWithSubject.class));
    // exception handler to not silently swallow handled exceptions.
    final Statement s1 = new RegisterBeanStatement(s2, new BeanMetaData(JUnitExceptionHandler.class).withReplace(true).withOrder(-1000));
    return s1;
}
Also used : SubjectStatement(org.eclipse.scout.rt.testing.platform.runner.statement.SubjectStatement) 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)

Example 2 with RegisterBeanStatement

use of org.eclipse.scout.rt.testing.platform.runner.statement.RegisterBeanStatement 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)

Aggregations

BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)2 AssertNoRunningJobsStatement (org.eclipse.scout.rt.testing.platform.runner.statement.AssertNoRunningJobsStatement)2 BeanAnnotationsCleanupStatement (org.eclipse.scout.rt.testing.platform.runner.statement.BeanAnnotationsCleanupStatement)2 BeanAnnotationsInitStatement (org.eclipse.scout.rt.testing.platform.runner.statement.BeanAnnotationsInitStatement)2 ClearThreadInterruptionStatusStatement (org.eclipse.scout.rt.testing.platform.runner.statement.ClearThreadInterruptionStatusStatement)2 PlatformStatement (org.eclipse.scout.rt.testing.platform.runner.statement.PlatformStatement)2 RegisterBeanStatement (org.eclipse.scout.rt.testing.platform.runner.statement.RegisterBeanStatement)2 RunContextStatement (org.eclipse.scout.rt.testing.platform.runner.statement.RunContextStatement)2 SubjectStatement (org.eclipse.scout.rt.testing.platform.runner.statement.SubjectStatement)2 ThrowHandledExceptionStatement (org.eclipse.scout.rt.testing.platform.runner.statement.ThrowHandledExceptionStatement)2 TimeoutRunContextStatement (org.eclipse.scout.rt.testing.platform.runner.statement.TimeoutRunContextStatement)2 TimesStatement (org.eclipse.scout.rt.testing.platform.runner.statement.TimesStatement)2 TransactionAddFailureOnAnyExceptionStatement (org.eclipse.scout.rt.testing.platform.runner.statement.TransactionAddFailureOnAnyExceptionStatement)2 Statement (org.junit.runners.model.Statement)2