use of org.eclipse.scout.rt.shared.ui.UserAgent in project scout.rt by eclipse.
the class ClientRunContextTest method testCurrentSessionAndDerivedValues.
@Test
public void testCurrentSessionAndDerivedValues() {
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(null, false).run(new IRunnable() {
@Override
public void run() throws Exception {
assertNull(ISession.CURRENT.get());
assertNull(NlsLocale.CURRENT.get());
assertNull(UserAgent.CURRENT.get());
assertNull(IDesktop.CURRENT.get());
assertNull(ClientRunContexts.copyCurrent().getSession());
assertNull(ClientRunContexts.copyCurrent().getLocale());
assertNull(ClientRunContexts.copyCurrent().getUserAgent());
assertNull(ClientRunContexts.copyCurrent().getDesktop());
}
});
ClientRunContexts.empty().withSession(session, false).run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(session, ISession.CURRENT.get());
assertNull(NlsLocale.CURRENT.get());
assertNull(UserAgent.CURRENT.get());
assertNull(IDesktop.CURRENT.get());
assertSame(session, ClientRunContexts.copyCurrent().getSession());
assertNull(ClientRunContexts.copyCurrent().getLocale());
assertNull(ClientRunContexts.copyCurrent().getUserAgent());
assertNull(ClientRunContexts.copyCurrent().getDesktop());
final UserAgent customUserAgent = UserAgents.create().build();
assertSame(customUserAgent, ClientRunContexts.copyCurrent().withUserAgent(customUserAgent).getUserAgent());
final Locale customLocale = Locale.ITALIAN;
assertSame(customLocale, ClientRunContexts.copyCurrent().withLocale(customLocale).getLocale());
}
});
ClientRunContexts.empty().withSession(session, true).run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(session, ISession.CURRENT.get());
assertSame(sessionLocale, NlsLocale.CURRENT.get());
assertSame(sessionUserAgent, UserAgent.CURRENT.get());
assertSame(sessionDesktop, IDesktop.CURRENT.get());
assertSame(session, ClientRunContexts.copyCurrent().getSession());
assertSame(sessionLocale, ClientRunContexts.copyCurrent().getLocale());
assertSame(sessionUserAgent, ClientRunContexts.copyCurrent().getUserAgent());
assertSame(sessionDesktop, ClientRunContexts.copyCurrent().getDesktop());
final UserAgent customUserAgent = UserAgents.create().build();
assertSame(customUserAgent, ClientRunContexts.copyCurrent().withUserAgent(customUserAgent).getUserAgent());
final Locale customLocale = Locale.ITALIAN;
assertSame(customLocale, ClientRunContexts.copyCurrent().withLocale(customLocale).getLocale());
final IDesktop customDesktop = mock(IDesktop.class);
assertSame(customDesktop, ClientRunContexts.copyCurrent().withDesktop(customDesktop).getDesktop());
}
});
}
use of org.eclipse.scout.rt.shared.ui.UserAgent in project scout.rt by eclipse.
the class ClientUIPreferences method getUserAgentPrefix.
protected String getUserAgentPrefix() {
UserAgent currentUserAgent = null;
if (m_prefs != null && m_prefs.userScope() instanceof IClientSession) {
currentUserAgent = ((IClientSession) m_prefs.userScope()).getUserAgent();
} else {
currentUserAgent = UserAgentUtility.getCurrentUserAgent();
}
if (currentUserAgent == null) {
return "";
}
String uiLayer = null;
if (!UiLayer.UNKNOWN.equals(currentUserAgent.getUiLayer())) {
uiLayer = currentUserAgent.getUiLayer().getIdentifier();
}
String uiDeviceType = null;
if (!UiDeviceType.UNKNOWN.equals(currentUserAgent.getUiDeviceType())) {
uiDeviceType = currentUserAgent.getUiDeviceType().getIdentifier();
}
return StringUtility.concatenateTokens(uiLayer, ".", uiDeviceType, ".");
}
Aggregations