Search in sources :

Example 61 with Statement

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

the class SingleApplicationComposerRunner 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(getTestClass().getJavaClass());
                    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 62 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 63 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 64 with Statement

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

the class MetaRunner method methodBlock.

@Override
protected Statement methodBlock(final FrameworkMethod method) {
    final Object test;
    try {
        test = new ReflectiveCallable() {

            @Override
            protected Object runReflectiveCall() throws Throwable {
                return createTest();
            }
        }.run();
    } catch (final Throwable e) {
        return new Fail(e);
    }
    Statement statement = new MetaTest.$(method, test);
    statement = withBefores(method, test, statement);
    statement = withAfters(method, test, statement);
    return statement;
}
Also used : ReflectiveCallable(org.junit.internal.runners.model.ReflectiveCallable) Statement(org.junit.runners.model.Statement) Fail(org.junit.internal.runners.statements.Fail)

Example 65 with Statement

use of org.junit.runners.model.Statement in project blueocean-plugin by jenkinsci.

the class ATHJUnitRunner method methodInvoker.

@Override
protected Statement methodInvoker(FrameworkMethod method, Object test) {
    Statement next = super.methodInvoker(method, test);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            LoginPage loginPage = injector.getInstance(LoginPage.class);
            Login methodLogin = method.getAnnotation(Login.class);
            // first check test method, then walk up hierarchy at class level only
            if (methodLogin != null) {
                if (!methodLogin.disable()) {
                    loginPage.login();
                }
            } else {
                Class<?> clazz = test.getClass();
                while (clazz != null) {
                    Login classLogin = clazz.getAnnotation(Login.class);
                    if (classLogin != null) {
                        if (!classLogin.disable()) {
                            loginPage.login();
                        }
                        break;
                    }
                    clazz = clazz.getSuperclass();
                }
            }
            try {
                next.evaluate();
                outputConsoleLogs();
            } catch (Exception e) {
                writeScreenShotCause(e, test, method);
                outputConsoleLogs();
                throw e;
            }
            WebDriver driver = injector.getInstance(WebDriver.class);
            driver.close();
        // driver.quit();
        }
    };
}
Also used : WebDriver(org.openqa.selenium.WebDriver) Statement(org.junit.runners.model.Statement) LoginPage(io.blueocean.ath.pages.classic.LoginPage) IOException(java.io.IOException) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) ScreenshotException(org.openqa.selenium.remote.ScreenshotException)

Aggregations

Statement (org.junit.runners.model.Statement)138 Test (org.junit.Test)22 FrameworkMethod (org.junit.runners.model.FrameworkMethod)15 Method (java.lang.reflect.Method)11 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)11 Fail (org.junit.internal.runners.statements.Fail)9 Description (org.junit.runner.Description)8 TestRule (org.junit.rules.TestRule)7 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 MethodRule (org.junit.rules.MethodRule)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