1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.data.jpa.eclipselink;
17
18 import org.eclipse.persistence.exceptions.TransactionException;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.kuali.rice.core.framework.persistence.jta.Jta;
22 import org.kuali.rice.krad.data.jpa.eclipselink.JtaTransactionController;
23 import org.mockito.Mock;
24 import org.mockito.runners.MockitoJUnitRunner;
25
26 import javax.transaction.TransactionManager;
27 import javax.transaction.UserTransaction;
28
29 import static org.junit.Assert.*;
30
31
32
33
34
35
36 @RunWith(MockitoJUnitRunner.class)
37 public class JtaTransactionControllerTest {
38
39 @Mock private TransactionManager transactionManager;
40 @Mock private UserTransaction userTransaction;
41
42
43
44
45
46
47 @Test
48 public void testAcquireTransactionManager_JtaDisabled() throws Exception {
49 assertFalse(Jta.isEnabled());
50 try {
51 new JtaTransactionController();
52 fail("A TransactionException should have been thrown");
53 } catch (TransactionException e) {
54 assertEquals(TransactionException.ERROR_OBTAINING_TRANSACTION_MANAGER, e.getErrorCode());
55 assertEquals(IllegalStateException.class, e.getInternalException().getClass());
56 }
57 }
58
59 @Test
60 public void testAcquireTransactionManager() throws Exception {
61 Jta.configure(transactionManager, userTransaction);
62 try {
63 assertTrue(Jta.isEnabled());
64 JtaTransactionController controller = new JtaTransactionController();
65 assertEquals(transactionManager, controller.acquireTransactionManager());
66 } finally {
67 Jta.reset();
68 }
69 }
70
71
72 }