/* * 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); } }