/** * Same as {@link ClientRunContexts#copyCurrent()}, but less strict if not running in a {@link RunContext}. * * @param orElseEmpty * indicates whether to return an empty {@link RunContext} if not running in a context yet. * @throws AssertionException * if not running in a {@link RunContext}, and <i>orElseEmpty</i> is set to <code>false</code>. */ public static ClientRunContext copyCurrent(final boolean orElseEmpty) { if (RunContext.CURRENT.get() != null) { return BEANS.get(ClientRunContextFactory.class).copyCurrent(); } if (orElseEmpty) { return BEANS.get(ClientRunContextFactory.class).empty(); } return Assertions.fail("Not running in a RunContext. Use '{}.empty()' or {}.copyCurrent(true) instead.", ClientRunContexts.class.getSimpleName(), ClientRunContexts.class.getSimpleName()); }
/** * Same as {@link ServerRunContexts#copyCurrent()}, but less strict if not running in a {@link RunContext} yet. * * @param orElseEmpty * indicates whether to return an empty {@link RunContext} if not running in a context yet. * @throws AssertionException * if not running in a {@link RunContext}, and <i>orElseEmpty</i> is set to <code>false</code>. */ public static ServerRunContext copyCurrent(final boolean orElseEmpty) { if (RunContext.CURRENT.get() != null) { return BEANS.get(ServerRunContextFactory.class).copyCurrent(); } if (orElseEmpty) { return BEANS.get(ServerRunContextFactory.class).empty(); } return Assertions.fail("Not running in a RunContext. Use '{}.empty()' or {}.copyCurrent(true) instead.", ServerRunContexts.class.getSimpleName(), ServerRunContexts.class.getSimpleName()); }
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(currentSubject) // set the test subject explicitly in case it is different to the session subject .run(invoker); invoker.throwOnError(); } finally { BEANS.getBeanManager().unregisterBean(clientSessionBean); } } }
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());
boolean applicationLocked = m_formStore.containsApplicationModalDialogs() || m_messageBoxStore.containsApplicationModalMessageBoxes() || m_fileChooserStore.containsApplicationModalFileChoosers(); if (applicationLocked) { Assertions.fail(generateApplicationModalErrorMessage());