X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=test%2Fenterprise%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Ftest%2Ftransactions%2FSimpleTransactionManagerIntegrationTest.java;fp=test%2Fenterprise%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Ftest%2Ftransactions%2FSimpleTransactionManagerIntegrationTest.java;h=1ad1a2b3c8523cffd72c72f6d0f888485c43c7ec;hb=2505dde4c404d845afdd4448134980ad9636b878;hp=0000000000000000000000000000000000000000;hpb=af14985679932ccffe4f6845b5b4192a2b2e3522;p=utils diff --git a/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerIntegrationTest.java b/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerIntegrationTest.java new file mode 100644 index 00000000..1ad1a2b3 --- /dev/null +++ b/test/enterprise/src/test/java/org/wamblee/test/transactions/SimpleTransactionManagerIntegrationTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2005-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.wamblee.test.transactions; + +import static junit.framework.Assert.*; +import static org.mockito.Matchers.*; +import static org.mockito.Mockito.*; + +import javax.transaction.Status; +import javax.transaction.UserTransaction; + +import org.junit.Before; +import org.junit.Test; + +public class SimpleTransactionManagerIntegrationTest { + + + private TransactionResource resource1; + private TransactionResource resource2; + private Object tx1; + private Object tx2; + + private SimpleTransactionManager manager; + + @Before + public void setUp() { + UserTransactionFactory factory = new DefaultUserTransactionFactory(); + manager = new SimpleTransactionManager(factory); + resource1 = mock(TransactionResource.class); + resource2 = mock(TransactionResource.class); + tx1 = mock(Object.class); + tx2 = mock(Object.class); + when(resource1.begin()).thenReturn(tx1); + when(resource2.begin()).thenReturn(tx2); + } + + @Test + public void testMultipleResources() throws Exception { + manager.addResource(resource1); + manager.addResource(resource2); + UserTransaction tx = manager.getTransaction(); + tx.begin(); + verify(resource1).begin(); + verify(resource2).begin(); + verifyNoMoreInteractions(resource1, resource2); + reset(resource1, resource2); + assertEquals(Status.STATUS_ACTIVE, tx.getStatus()); + tx.commit(); + verify(resource1).commit(same(tx1)); + verify(resource2).commit(same(tx2)); + + verifyNoMoreInteractions(resource1, resource2); + } + +}