use of org.junit.runners.model.Statement in project tomee by apache.
the class JUnit4Runner method createUnsecuredStatement.
/**
* Builds a method statement that executes in an unauthenticated context
*/
protected Statement createUnsecuredStatement(final FrameworkMethod method) {
final Object test = newTestInstance();
Statement statement = methodInvoker(method, test);
statement = possiblyExpectingExceptions(method, test, statement);
statement = withPotentialTimeout(method, test, statement);
statement = withBefores(method, test, statement);
statement = withAfters(method, test, statement);
final TestContext context = runner.newTestContext(method.getMethod());
return new ContextWrapperStatement(context, statement, test);
}
use of org.junit.runners.model.Statement in project tomee by apache.
the class JUnit4Runner method createSecuredStatementExecutor.
/**
* Create a method statement that executes the test for each of the specified
* roles, both doing authorized and unauthorized tests.
* <p/>
* Unauthorized roles are configured to fail with EJBAccessExceptions.
*
* @param method
* @param testSecurity
* @return created statement
*/
private Statement createSecuredStatementExecutor(final FrameworkMethod method, final TestSecurity testSecurity) {
final MultiStatementExecutor statementExecutor = new MultiStatementExecutor();
for (final String role : testSecurity.authorized()) {
final Statement statement = createSecuredStatement(method, role, false);
statementExecutor.addStatement(statement);
}
for (final String role : testSecurity.unauthorized()) {
final Statement statement = createSecuredStatement(method, role, true);
statementExecutor.addStatement(statement);
}
return statementExecutor;
}
use of org.junit.runners.model.Statement in project tomee by apache.
the class JUnit4Runner method createSecuredStatement.
/**
* Create a new statement to run with a given role and whether it should fail or not.
*
* @param method
* @param role
* @param failWithAccessException
* @return statement
*/
private Statement createSecuredStatement(final FrameworkMethod method, final String role, final boolean failWithAccessException) {
final Object test = newTestInstance();
Statement statement = methodInvoker(method, test);
statement = possiblyExpectingAccessException(statement, failWithAccessException);
// specified in @Test
statement = possiblyExpectingExceptions(method, test, statement);
statement = withPotentialTimeout(method, test, statement);
statement = withBefores(method, test, statement);
statement = withAfters(method, test, statement);
final TestContext context = runner.newTestContext(method.getMethod(), role);
return new ContextWrapperStatement(context, statement, test);
}
use of org.junit.runners.model.Statement in project tomee by apache.
the class ContainerRule method apply.
@Override
public Statement apply(final Statement statement, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final ApplicationComposers composers = new ContainerApplicationComposers(instance);
composers.startContainer(instance);
try {
statement.evaluate();
} finally {
composers.after();
}
}
};
}
use of org.junit.runners.model.Statement in project tomee by apache.
the class RunAsRule method apply.
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
final RunAs annotation = description.getAnnotation(RunAs.class);
final As as = description.getAnnotation(As.class);
String currentRole = role.get();
// no more needed
role.remove();
if (annotation == null && as == null && currentRole == null) {
base.evaluate();
return;
}
final BeanContext beanContext = getBeanContext();
if (currentRole == null) {
if (annotation == null) {
currentRole = as.value();
} else {
currentRole = annotation.value();
}
}
final String runAs = beanContext.getRunAs();
final String runAsUser = beanContext.getRunAsUser();
beanContext.setRunAs(currentRole);
final ThreadContext old = ThreadContext.enter(new ThreadContext(beanContext, null));
try {
base.evaluate();
} finally {
// reset for next test
ThreadContext.exit(old);
beanContext.setRunAs(runAs);
beanContext.setRunAsUser(runAsUser);
}
}
};
}
Aggregations