use of com.haulmont.cuba.core.app.TestingService in project cuba by cuba-platform.
the class DeclarativeTransactionTest method test.
@Test
public void test() throws Exception {
TestingService service = AppBeans.get(TestingService.class);
service.declarativeTransaction();
assertNull(cont.persistence().getEntityManagerContext().getAttribute("test"));
}
use of com.haulmont.cuba.core.app.TestingService in project cuba by cuba-platform.
the class ServiceInterceptorTest method testLogMessage.
@Test
public void testLogMessage() throws Exception {
TestingService service1 = AppBeans.get(TestingService.class);
ServiceInterceptorTestService service2 = AppBeans.get(ServiceInterceptorTestService.class);
// normally no log messages for internal invocations
appender.getMessages().clear();
service1.declarativeTransaction();
assertEquals(0, appender.getMessages().stream().filter(s -> s.contains("from another service")).count());
appender.getMessages().clear();
service2.declarativeTransaction();
assertEquals(0, appender.getMessages().stream().filter(s -> s.contains("from another service")).count());
// old behaviour
ServiceInterceptor serviceInterceptor = AppBeans.get(ServiceInterceptor.class);
serviceInterceptor.logInternalServiceInvocation = true;
try {
appender.getMessages().clear();
service1.declarativeTransaction();
assertEquals(0, appender.getMessages().stream().filter(s -> s.contains("from another service")).count());
appender.getMessages().clear();
service2.declarativeTransaction();
assertEquals(1, appender.getMessages().stream().filter(s -> s.contains("from another service")).count());
} finally {
serviceInterceptor.logInternalServiceInvocation = false;
}
}
use of com.haulmont.cuba.core.app.TestingService in project cuba by cuba-platform.
the class ServiceInterceptorTest method testOpenTransaction.
@Test
public void testOpenTransaction() throws Exception {
TestingService service = AppBeans.get(TestingService.class);
appender.getMessages().clear();
// programmatic tx without proper completion
Object tx = service.leaveOpenTransaction();
((Transaction) tx).commit();
assertEquals(1, appender.getMessages().stream().filter(s -> s.contains("Open transaction")).count());
appender.getMessages().clear();
// declarative tx
service.declarativeTransaction();
assertEquals(0, appender.getMessages().stream().filter(s -> s.contains("Open transaction")).count());
}
use of com.haulmont.cuba.core.app.TestingService in project cuba by cuba-platform.
the class ServiceInterceptorTest method testExceptionHandling.
@Test
public void testExceptionHandling() throws Exception {
TestingService service1 = AppBeans.get(TestingService.class);
ServiceInterceptorTestService service2 = AppBeans.get(ServiceInterceptorTestService.class);
appender.getMessages().clear();
try {
service1.executeWithException();
} catch (Exception e) {
assertTrue(e instanceof RemoteException && ((RemoteException) e).getFirstCauseException() instanceof TestingService.TestException);
}
appender.getMessages().clear();
try {
service2.executeWithException();
} catch (Exception e) {
assertTrue(e instanceof RemoteException && ((RemoteException) e).getFirstCauseException() instanceof TestingService.TestException);
}
}
Aggregations