use of org.eclipse.scout.rt.shared.ui.UserAgent in project scout.rt by eclipse.
the class AbstractServiceTunnel method interceptRequest.
protected void interceptRequest(ServiceTunnelRequest request) {
UserAgent userAgent = UserAgent.CURRENT.get();
if (userAgent == null) {
LOG.warn("No UserAgent set on calling context; include default in service-request");
userAgent = UserAgents.createDefault();
}
request.setUserAgent(userAgent.createIdentifier());
ISession session = ISession.CURRENT.get();
if (session != null) {
request.setSessionId(session.getId());
}
request.setClientNodeId(INode.ID);
}
use of org.eclipse.scout.rt.shared.ui.UserAgent in project scout.rt by eclipse.
the class ServerRunContextTest method testRunContextsCopyCurrent.
@Test
public void testRunContextsCopyCurrent() {
final IServerSession session = mock(IServerSession.class);
final UserAgent userAgent = UserAgents.create().build();
final Locale locale = Locale.CANADA_FRENCH;
final Subject subject = new Subject();
ServerRunContexts.empty().withSession(session).withUserAgent(userAgent).withLocale(locale).withSubject(subject).run(new IRunnable() {
@Override
public void run() throws Exception {
RunContext runContext = RunContexts.copyCurrent();
assertThat(runContext, CoreMatchers.instanceOf(ServerRunContext.class));
ServerRunContext serverCtx = (ServerRunContext) runContext;
assertSame(session, serverCtx.getSession());
assertSame(userAgent, serverCtx.getUserAgent());
assertSame(locale, serverCtx.getLocale());
assertSame(subject, serverCtx.getSubject());
}
});
}
use of org.eclipse.scout.rt.shared.ui.UserAgent 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);
}
}
use of org.eclipse.scout.rt.shared.ui.UserAgent in project scout.rt by eclipse.
the class ClientRunContextTest method testCurrentUserAgent.
@Test
public void testCurrentUserAgent() {
final UserAgent userAgent = UserAgents.create().build();
ClientRunContexts.empty().withUserAgent(null).run(new IRunnable() {
@Override
public void run() throws Exception {
assertNull(UserAgent.CURRENT.get());
assertNull(RunContexts.copyCurrent().getLocale());
}
});
ClientRunContexts.empty().withUserAgent(userAgent).run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(userAgent, UserAgent.CURRENT.get());
assertEquals(userAgent, ClientRunContexts.copyCurrent().getUserAgent());
final UserAgent customUserAgent = UserAgents.create().build();
assertEquals(customUserAgent, ClientRunContexts.copyCurrent().withUserAgent(customUserAgent).getUserAgent());
}
});
}
use of org.eclipse.scout.rt.shared.ui.UserAgent in project scout.rt by eclipse.
the class ClientRunContextTest method testRunContextsCopyCurrent.
@Test
public void testRunContextsCopyCurrent() {
final IClientSession session = mock(IClientSession.class);
final UserAgent sessionUserAgent = UserAgents.create().build();
final Locale sessionLocale = Locale.CANADA_FRENCH;
final Subject sessionSubject = new Subject();
final IDesktop sessionDesktop = mock(IDesktop.class);
when(session.getUserAgent()).thenReturn(sessionUserAgent);
when(session.getLocale()).thenReturn(sessionLocale);
when(session.getSubject()).thenReturn(sessionSubject);
when(session.getDesktopElseVirtualDesktop()).thenReturn(sessionDesktop);
ClientRunContexts.empty().withSession(session, true).run(new IRunnable() {
@Override
public void run() throws Exception {
RunContext runContext = RunContexts.copyCurrent();
assertThat(runContext, CoreMatchers.instanceOf(ClientRunContext.class));
ClientRunContext clientCtx = (ClientRunContext) runContext;
assertSame(session, clientCtx.getSession());
assertSame(sessionLocale, clientCtx.getLocale());
assertSame(sessionUserAgent, clientCtx.getUserAgent());
assertSame(sessionDesktop, clientCtx.getDesktop());
}
});
}
Aggregations