@Test public void testIsReadOnlyTransactionWhenTrue() throws TransactionException { Transactional transactional = EasyMock.createMock(Transactional.class); EasyMock.expect(transactionAttributeBinder.getTransactionalInCurrentTransaction()) .andReturn(transactional) .once(); EasyMock.expect(transactional.readOnly()).andReturn(true).once(); EasyMock.replay(transactionAttributeBinder, transactional); Assert.assertTrue(dbConnProvider.isReadOnlyTransaction()); }
@Test public void testSetConnectionReadOnlyIfNecessaryOnTransactionReadOnlyButConnectionReadWrite() throws TransactionException, SQLException { Connection connection = EasyMock.createMock(Connection.class); Transactional transactional = EasyMock.createMock(Transactional.class); EasyMock.expect(transactionAttributeBinder.getTransactionalInCurrentTransaction()) .andReturn(transactional) .once(); EasyMock.expect(transactional.readOnly()).andReturn(true).once(); EasyMock.expect(connection.isReadOnly()).andReturn(false).once(); connection.setReadOnly(true); EasyMock.expectLastCall().once(); }