use of org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testGetDatasources.
@Test
public void testGetDatasources() throws Exception {
final String fileId = "456";
final String databasesFolderPath = "/etc/pdi/databases";
final String dotKdb = ".kdb";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
doReturn(reservedChars).when(repo).getReservedChars();
// stub out get file to update
RepositoryFile f = new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).path(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb).build();
doReturn(f).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
final String EXP_HOST_NAME = "hello";
DataNode rootNode = new DataNode("databaseMeta");
// required
rootNode.setProperty("TYPE", "Hypersonic");
rootNode.setProperty("HOST_NAME", EXP_HOST_NAME);
// required
rootNode.addNode("attributes");
doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(eq(fileId), eq(NodeRepositoryFileData.class));
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
IDatabaseConnection conn = datasourceMgmtService.getDatasourceByName(EXP_DBMETA_NAME);
assertEquals(EXP_HOST_NAME, conn.getHostname());
}
use of org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testCreateDatasource.
@Test
public void testCreateDatasource() throws Exception {
final String parentFolderId = "123";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder(parentFolderId, "databases").folder(true).build()).when(repo).getFile("/etc/pdi/databases");
doReturn(reservedChars).when(repo).getReservedChars();
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
IDatabaseConnection databaseConnection = createDatabaseConnection(EXP_DBMETA_NAME);
datasourceMgmtService.createDatasource(databaseConnection);
verify(repo).createFile(eq(parentFolderId), argThat(isLikeFile(new RepositoryFile.Builder(EXP_DBMETA_NAME + ".kdb").build())), argThat(hasData(pathPropertyPair("/databaseMeta/HOST_NAME", EXP_DBMETA_HOSTNAME))), anyString());
}
use of org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtServiceTest method testDeleteDatasourceWithName.
@Test
public void testDeleteDatasourceWithName() throws Exception {
final String fileId = "456";
final String databasesFolderPath = "/etc/pdi/databases";
final String dotKdb = ".kdb";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// stub out get parent folder
doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFile(databasesFolderPath);
doReturn(reservedChars).when(repo).getReservedChars();
// stub out get file to delete
doReturn(new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).build()).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
datasourceMgmtService.deleteDatasourceByName(EXP_DBMETA_NAME);
verify(repo).deleteFile(eq(fileId), eq(true), anyString());
}
use of org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService in project pentaho-platform by pentaho.
the class DynamicConnectionDatasourceServiceTest method setUp.
@Before
public void setUp() {
mockConnection = mock(IDatabaseConnection.class);
// Set it up - this is a NATIVE connection
when(mockConnection.getAccessType()).thenReturn(DatabaseAccessType.NATIVE);
when(mockConnection.getDatabaseName()).thenReturn(dsName);
DataSource mockDs = mock(DataSource.class);
IDatasourceMgmtService mockMgmtService = mock(IDatasourceMgmtService.class);
DynamicallyPooledOrJndiDatasourceService dynamic = new DynamicallyPooledOrJndiDatasourceService();
dynamic.setNonPooledDatasourceService(nonPooledSpyService);
dynamic.setPooledDatasourceService(pooledSpyService);
spyService = spy(dynamic);
try {
when(mockMgmtService.getDatasourceByName(dsName)).thenReturn(mockConnection);
} catch (DatasourceMgmtServiceException e) {
e.printStackTrace();
}
try {
doReturn(mockDs).when(nonPooledSpyService).resolveDatabaseConnection(mockConnection);
doReturn(mockDs).when(pooledSpyService).resolveDatabaseConnection(mockConnection);
} catch (DBDatasourceServiceException e) {
e.printStackTrace();
}
doReturn(mockMgmtService).when(nonPooledSpyService).getDatasourceMgmtService();
doReturn(mockMgmtService).when(pooledSpyService).getDatasourceMgmtService();
doReturn(mockMgmtService).when(spyService).getDatasourceMgmtService();
spyService.clearCache();
}
use of org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService in project pentaho-platform by pentaho.
the class JNDIDatasourceServiceTest method setUp.
@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();
}
Aggregations