Search in sources :

Example 1 with ExpectedLookupTemplate

use of org.springframework.tests.mock.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.

the class WebSphereUowTransactionManagerTests method uowManagerAndUserTransactionFoundInJndi.

@Test
public void uowManagerAndUserTransactionFoundInJndi() throws Exception {
    UserTransaction ut = mock(UserTransaction.class);
    given(ut.getStatus()).willReturn(Status.STATUS_NO_TRANSACTION, Status.STATUS_ACTIVE, Status.STATUS_ACTIVE);
    MockUOWManager manager = new MockUOWManager();
    ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
    jndiTemplate.addObject(WebSphereUowTransactionManager.DEFAULT_USER_TRANSACTION_NAME, ut);
    jndiTemplate.addObject(WebSphereUowTransactionManager.DEFAULT_UOW_MANAGER_NAME, manager);
    WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager();
    ptm.setJndiTemplate(jndiTemplate);
    ptm.afterPropertiesSet();
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    TransactionStatus ts = ptm.getTransaction(definition);
    ptm.commit(ts);
    assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {

        @Override
        public String doInTransaction(TransactionStatus status) {
            return "result";
        }
    }));
    assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
    assertFalse(manager.getJoined());
    assertFalse(manager.getRollbackOnly());
    verify(ut).begin();
    verify(ut).commit();
}
Also used : UserTransaction(javax.transaction.UserTransaction) TransactionCallback(org.springframework.transaction.support.TransactionCallback) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) ExpectedLookupTemplate(org.springframework.tests.mock.jndi.ExpectedLookupTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) Test(org.junit.Test)

Example 2 with ExpectedLookupTemplate

use of org.springframework.tests.mock.jndi.ExpectedLookupTemplate in project spring-framework by spring-projects.

the class WebSphereUowTransactionManagerTests method uowManagerFoundInJndi.

@Test
public void uowManagerFoundInJndi() {
    MockUOWManager manager = new MockUOWManager();
    ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate(WebSphereUowTransactionManager.DEFAULT_UOW_MANAGER_NAME, manager);
    WebSphereUowTransactionManager ptm = new WebSphereUowTransactionManager();
    ptm.setJndiTemplate(jndiTemplate);
    ptm.afterPropertiesSet();
    DefaultTransactionDefinition definition = new DefaultTransactionDefinition();
    assertEquals("result", ptm.execute(definition, new TransactionCallback<String>() {

        @Override
        public String doInTransaction(TransactionStatus status) {
            return "result";
        }
    }));
    assertEquals(UOWManager.UOW_TYPE_GLOBAL_TRANSACTION, manager.getUOWType());
    assertFalse(manager.getJoined());
    assertFalse(manager.getRollbackOnly());
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) ExpectedLookupTemplate(org.springframework.tests.mock.jndi.ExpectedLookupTemplate) TransactionStatus(org.springframework.transaction.TransactionStatus) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 ExpectedLookupTemplate (org.springframework.tests.mock.jndi.ExpectedLookupTemplate)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)2 TransactionCallback (org.springframework.transaction.support.TransactionCallback)2 UserTransaction (javax.transaction.UserTransaction)1