@Test public void testPentahoConnectionServices( ){ try { // Now make sure that the resolve.. service method gets called; if not, // fail the test spyService.getDataSource( dsName ); verify(spyService).resolveDatabaseConnection( mockConnection ); verify(spyService, Mockito.never()).getJndiDataSource( dsName ); } catch ( DBDatasourceServiceException e ) { e.printStackTrace(); } }
@Test public void testJndiServices( ){ try { // Now make sure that the JNDI service method gets called; if not, // fail the test spyService.getDataSource( dsName ); verify(spyService).getJndiDataSource( dsName ); } catch ( DBDatasourceServiceException e ) { e.printStackTrace(); } }
@Test public void testCachedJndiServices( ){ try { // Now make sure that the JNDI service method gets called the first time, // but the second time it should retrieve from cache. spyService.getDataSource( dsName ); spyService.getDataSource( dsName ); verify(spyService, Mockito.times( 1 )).getJndiDataSource( dsName ); } catch ( DBDatasourceServiceException e ) { e.printStackTrace(); } }
@Before public void setUp(){ IDatabaseConnection mockConnection = mock(IDatabaseConnection.class); // Set it up - this is a JNDI connection when( mockConnection.getAccessType()).thenReturn( DatabaseAccessType.JNDI ); when( mockConnection.getDatabaseName()).thenReturn( dsName ); DataSource mockDs = mock(DataSource.class); IDatasourceMgmtService mockMgmtService = mock(IDatasourceMgmtService.class); spyService = spy(service ); try { when( mockMgmtService.getDatasourceByName( dsName ) ).thenReturn( mockConnection ); } catch ( DatasourceMgmtServiceException e ) { e.printStackTrace(); } try { doReturn(mockDs).when( spyService ).getJndiDataSource( dsName ); } catch ( DBDatasourceServiceException e ) { e.printStackTrace(); } doReturn( mockMgmtService ).when( spyService ).getDatasourceMgmtService(); service.clearCache(); }