Search in sources :

Example 56 with Statement

use of org.junit.runners.model.Statement in project sling by apache.

the class Service method apply.

public Statement apply(final Statement base, final Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            final BundleContext bundleContext = Activator.getBundleContext();
            if (bundleContext == null) {
                // No bundle context usually means we're running client-side
                // in a test that uses ServerSideTestRule. In this case, this
                // rule does nothing.
                base.evaluate();
                return;
            }
            serviceGetter = ServiceGetter.create(bundleContext, serviceClass, null);
            try {
                base.evaluate();
            } finally {
                serviceGetter.close();
            }
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) BundleContext(org.osgi.framework.BundleContext)

Example 57 with Statement

use of org.junit.runners.model.Statement in project tomee by apache.

the class ApplicationComposer method rules.

@Override
protected List<MethodRule> rules(final Object test) {
    final List<MethodRule> rules = super.rules(test);
    rules.add(new MethodRule() {

        public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
            return new DeployApplication(target, base, delegate);
        }
    });
    return rules;
}
Also used : MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 58 with Statement

use of org.junit.runners.model.Statement in project tomee by apache.

the class ApplicationRule method apply.

@Override
public Statement apply(final Statement statement, final Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            final Thread thread = Thread.currentThread();
            final ClassLoader old = thread.getContextClassLoader();
            final ApplicationComposers composers = new ApplicationOnlyApplicationComposers(instance);
            composers.deployApp(instance);
            try {
                statement.evaluate();
            } finally {
                composers.stopApplication();
                thread.setContextClassLoader(old);
            }
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) ApplicationComposers(org.apache.openejb.testing.ApplicationComposers)

Example 59 with Statement

use of org.junit.runners.model.Statement in project tomee by apache.

the class TomEEEmbeddedSingleRunner method rules.

@Override
protected List<MethodRule> rules(final Object test) {
    final List<MethodRule> rules = super.rules(test);
    rules.add(new MethodRule() {

        @Override
        public Statement apply(final Statement base, final FrameworkMethod method, final Object target) {
            return new Statement() {

                @Override
                public void evaluate() throws Throwable {
                    start(test);
                    getRunner().composerInject(target);
                    base.evaluate();
                }
            };
        }
    });
    return rules;
}
Also used : MethodRule(org.junit.rules.MethodRule) Statement(org.junit.runners.model.Statement) FrameworkMethod(org.junit.runners.model.FrameworkMethod)

Example 60 with Statement

use of org.junit.runners.model.Statement in project tomee by apache.

the class LocalClientRunner method methodBlock.

@Override
protected Statement methodBlock(final FrameworkMethod method) {
    final Object instance = newTestInstance();
    final Test test = new Test(clazz, method.getMethod(), instance, deployment);
    Statement statement = methodInvoker(method, instance);
    statement = wrap(test, statement, RunAs.class, javax.annotation.security.RunAs.class);
    statement = wrap(test, statement, RunTestAs.class, org.apache.openejb.junit.RunTestAs.class);
    statement = wrap(test, statement, Transaction.class, org.apache.openejb.junit.Transaction.class);
    statement = wrap(test, statement, TransactionAttribute.class, javax.ejb.TransactionAttribute.class);
    statement = possiblyExpectingExceptions(method, instance, statement);
    statement = withPotentialTimeout(method, instance, statement);
    statement = withBefores(method, instance, statement);
    statement = withAfters(method, instance, statement);
    return statement;
}
Also used : Statement(org.junit.runners.model.Statement)

Aggregations

Statement (org.junit.runners.model.Statement)129 Test (org.junit.Test)22 FrameworkMethod (org.junit.runners.model.FrameworkMethod)15 Method (java.lang.reflect.Method)10 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)10 Fail (org.junit.internal.runners.statements.Fail)9 TestRule (org.junit.rules.TestRule)7 Description (org.junit.runner.Description)7 MethodRule (org.junit.rules.MethodRule)6 MultipleFailureException (org.junit.runners.model.MultipleFailureException)6 ExecutorService (java.util.concurrent.ExecutorService)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ReflectiveCallable (org.junit.internal.runners.model.ReflectiveCallable)5 ArrayList (java.util.ArrayList)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 EmptyStatement (com.hazelcast.util.EmptyStatement)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 TestExecutorService (org.apache.beam.fn.harness.test.TestExecutors.TestExecutorService)3 CompositeConfiguration (org.apache.logging.log4j.core.config.composite.CompositeConfiguration)3 LoggerContextRule (org.apache.logging.log4j.junit.LoggerContextRule)3