2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.test.transactions;
18 import static junit.framework.Assert.*;
19 import static org.mockito.Matchers.*;
20 import static org.mockito.Mockito.*;
22 import javax.transaction.Status;
23 import javax.transaction.UserTransaction;
25 import org.junit.Before;
26 import org.junit.Test;
28 public class SimpleTransactionManagerIntegrationTest {
31 private TransactionResource resource1;
32 private TransactionResource resource2;
36 private SimpleTransactionManager manager;
40 UserTransactionFactory factory = new DefaultUserTransactionFactory();
41 manager = new SimpleTransactionManager(factory);
42 resource1 = mock(TransactionResource.class);
43 resource2 = mock(TransactionResource.class);
44 tx1 = mock(Object.class);
45 tx2 = mock(Object.class);
46 when(resource1.begin()).thenReturn(tx1);
47 when(resource2.begin()).thenReturn(tx2);
51 public void testMultipleResources() throws Exception {
52 manager.addResource(resource1);
53 manager.addResource(resource2);
54 UserTransaction tx = manager.getTransaction();
56 verify(resource1).begin();
57 verify(resource2).begin();
58 verifyNoMoreInteractions(resource1, resource2);
59 reset(resource1, resource2);
60 assertEquals(Status.STATUS_ACTIVE, tx.getStatus());
62 verify(resource1).commit(same(tx1));
63 verify(resource2).commit(same(tx2));
65 verifyNoMoreInteractions(resource1, resource2);
69 public void testTwoTransactions() throws Exception {
70 UserTransaction transaction = manager.getTransaction();