Search in sources :

Example 6 with SafeStatementInvoker

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

the class ServerRunContextStatement method evaluateWithServerRunContext.

private void evaluateWithServerRunContext() throws Throwable {
    final Subject currentSubject = Subject.getSubject(AccessController.getContext());
    if (currentSubject == null) {
        Assertions.fail("Subject must not be null. Use the annotation '{}' to execute your test under a particular user. ", RunWithSubject.class.getSimpleName());
    }
    UserAgent userAgent = UserAgents.createDefault();
    Class<? extends ISession> sessionClass = m_serverSessionAnnotation.value();
    IBean<? extends ISession> sessionBean = BEANS.getBeanManager().uniqueBean(sessionClass);
    if (sessionBean != null) {
        sessionClass = sessionBean.getBeanClazz();
    }
    final IBean serverSessionBean = BEANS.getBeanManager().registerBean(new BeanMetaData(sessionClass).withOrder(-Long.MAX_VALUE));
    try {
        // Obtain the server session for the given subject. Depending on the session provider, a new session is created or a cached session returned.
        final IServerSession serverSession = BEANS.get(m_serverSessionAnnotation.provider()).provide(ServerRunContexts.copyCurrent().withSubject(currentSubject).withUserAgent(userAgent));
        // Run the test on behalf of a ServerRunContext.
        final SafeStatementInvoker invoker = new SafeStatementInvoker(m_next);
        ServerRunContexts.copyCurrent().withSession(serverSession).withSubject(// set the test subject explicitly in case it is different to the session subject
        currentSubject).withUserAgent(userAgent).run(invoker);
        invoker.throwOnError();
    } finally {
        BEANS.getBeanManager().unregisterBean(serverSessionBean);
    }
}
Also used : RunWithSubject(org.eclipse.scout.rt.testing.platform.runner.RunWithSubject) SafeStatementInvoker(org.eclipse.scout.rt.testing.platform.runner.SafeStatementInvoker) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) UserAgent(org.eclipse.scout.rt.shared.ui.UserAgent) IServerSession(org.eclipse.scout.rt.server.IServerSession) IBean(org.eclipse.scout.rt.platform.IBean) RunWithSubject(org.eclipse.scout.rt.testing.platform.runner.RunWithSubject) Subject(javax.security.auth.Subject)

Example 7 with SafeStatementInvoker

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

the class ClientRunContextStatement method evaluateWithClientRunContext.

private void evaluateWithClientRunContext() throws Throwable {
    final Subject currentSubject = Subject.getSubject(AccessController.getContext());
    if (currentSubject == null) {
        Assertions.fail("Subject must not be null. Use the annotation '{}' to execute your test under a particular user. ", RunWithSubject.class.getSimpleName());
    }
    Class<? extends ISession> sessionClass = m_clientSessionAnnotation.value();
    IBean<? extends ISession> sessionBean = BEANS.getBeanManager().uniqueBean(sessionClass);
    if (sessionBean != null) {
        sessionClass = sessionBean.getBeanClazz();
    }
    final IBean clientSessionBean = BEANS.getBeanManager().registerBean(new BeanMetaData(sessionClass).withOrder(-Long.MAX_VALUE));
    try {
        // Obtain the client session for the given subject. Depending on the session provider, a new session is created or a cached session returned.
        final IClientSession clientSession = BEANS.get(m_clientSessionAnnotation.provider()).provide(ClientRunContexts.copyCurrent().withSubject(currentSubject));
        // Run the test on behalf of a ClientRunContext.
        final SafeStatementInvoker invoker = new SafeStatementInvoker(m_next);
        ClientRunContexts.copyCurrent().withSession(clientSession, true).withSubject(// set the test subject explicitly in case it is different to the session subject
        currentSubject).run(invoker);
        invoker.throwOnError();
    } finally {
        BEANS.getBeanManager().unregisterBean(clientSessionBean);
    }
}
Also used : RunWithSubject(org.eclipse.scout.rt.testing.platform.runner.RunWithSubject) SafeStatementInvoker(org.eclipse.scout.rt.testing.platform.runner.SafeStatementInvoker) BeanMetaData(org.eclipse.scout.rt.platform.BeanMetaData) IClientSession(org.eclipse.scout.rt.client.IClientSession) IBean(org.eclipse.scout.rt.platform.IBean) RunWithSubject(org.eclipse.scout.rt.testing.platform.runner.RunWithSubject) Subject(javax.security.auth.Subject)

Example 8 with SafeStatementInvoker

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

the class SubjectStatement method evaluate.

@Override
public void evaluate() throws Throwable {
    if (m_subject == null) {
        m_next.evaluate();
    } else {
        SafeStatementInvoker invoker = new SafeStatementInvoker(m_next);
        RunContexts.copyCurrent().withSubject(m_subject).run(invoker);
        invoker.throwOnError();
    }
}
Also used : SafeStatementInvoker(org.eclipse.scout.rt.testing.platform.runner.SafeStatementInvoker)

Aggregations

SafeStatementInvoker (org.eclipse.scout.rt.testing.platform.runner.SafeStatementInvoker)8 Subject (javax.security.auth.Subject)2 BeanMetaData (org.eclipse.scout.rt.platform.BeanMetaData)2 IBean (org.eclipse.scout.rt.platform.IBean)2 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)2 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)2 RunWithSubject (org.eclipse.scout.rt.testing.platform.runner.RunWithSubject)2 TestTimedOutException (org.junit.runners.model.TestTimedOutException)2 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 IServerSession (org.eclipse.scout.rt.server.IServerSession)1 UserAgent (org.eclipse.scout.rt.shared.ui.UserAgent)1