Пример #1
0
 def reserveConnection_nonExistantDataSourceLookedUp_shouldFail(self):
     System.setProperty('java.naming.factory.initial', 'com.vaadin.addon.sqlcontainer.connection.MockInitialContextFactory')
     context = EasyMock.createMock(Context)
     context.lookup('foo')
     EasyMock.expectLastCall().andThrow(NamingException('fail'))
     MockInitialContextFactory.setMockContext(context)
     EasyMock.replay(context)
     pool = self.J2EEConnectionPool('foo')
     pool.reserveConnection()
     EasyMock.verify(context)
Пример #2
0
 def reserveConnection_dataSourceLookedUp_shouldReturnValidConnection(self):
     connection = EasyMock.createMock(Connection)
     connection.setAutoCommit(False)
     EasyMock.expectLastCall()
     connection.close()
     EasyMock.expectLastCall()
     ds = EasyMock.createMock(DataSource)
     ds.getConnection()
     EasyMock.expectLastCall().andReturn(connection)
     System.setProperty('java.naming.factory.initial', 'com.vaadin.data.util.sqlcontainer.connection.MockInitialContextFactory')
     context = EasyMock.createMock(Context)
     context.lookup('testDataSource')
     EasyMock.expectLastCall().andReturn(ds)
     MockInitialContextFactory.setMockContext(context)
     EasyMock.replay(context, connection, ds)
     pool = self.J2EEConnectionPool('testDataSource')
     c = pool.reserveConnection()
     Assert.assertEquals(connection, c)
     pool.releaseConnection(c)
     EasyMock.verify(context, connection, ds)