Search in sources :

Example 1 with TestingService

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"));
}
Also used : TestingService(com.haulmont.cuba.core.app.TestingService) Test(org.junit.Test)

Example 2 with TestingService

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;
    }
}
Also used : TestingService(com.haulmont.cuba.core.app.TestingService) Test(org.junit.Test)

Example 3 with TestingService

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());
}
Also used : Transaction(com.haulmont.cuba.core.Transaction) TestingService(com.haulmont.cuba.core.app.TestingService) Test(org.junit.Test)

Example 4 with TestingService

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);
    }
}
Also used : TestingService(com.haulmont.cuba.core.app.TestingService) RemoteException(com.haulmont.cuba.core.global.RemoteException) RemoteException(com.haulmont.cuba.core.global.RemoteException) Test(org.junit.Test)

Aggregations

TestingService (com.haulmont.cuba.core.app.TestingService)4 Test (org.junit.Test)4 Transaction (com.haulmont.cuba.core.Transaction)1 RemoteException (com.haulmont.cuba.core.global.RemoteException)1