use of com.haulmont.cuba.security.app.UserSessions in project cuba by cuba-platform.
the class ServiceInterceptorTest method testNewThread.
@Test
public void testNewThread() throws Exception {
ServiceInterceptorTestService service = AppBeans.get(ServiceInterceptorTestService.class);
UserSessions userSessions = AppBeans.get(UserSessions.class);
// workaround for test security setup
Field startedField = AppContext.class.getDeclaredField("started");
startedField.setAccessible(true);
startedField.set(null, true);
AppContext.setSecurityContext(AppContext.NO_USER_CONTEXT);
UserSession userSession = new UserSession(AppContext.NO_USER_CONTEXT.getSessionId(), new User(), Collections.emptyList(), Locale.ENGLISH, true);
userSessions.add(userSession);
try {
appender.getMessages().clear();
service.declarativeTransactionNewThread();
assertEquals(0, appender.getMessages().stream().filter(s -> s.contains("from another service")).count());
appender.getMessages().clear();
try {
service.executeWithExceptionNewThread();
} catch (Exception e) {
assertTrue(e instanceof RemoteException && ((RemoteException) e).getFirstCauseException() instanceof TestingService.TestException);
}
} finally {
userSessions.remove(userSession);
startedField.set(null, false);
}
}
Aggregations