Search in sources :

Example 1 with IDatasourceMgmtService

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());
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) Test(org.junit.Test)

Example 2 with IDatasourceMgmtService

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());
}
Also used : DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) Test(org.junit.Test)

Example 3 with IDatasourceMgmtService

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());
}
Also used : DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) Test(org.junit.Test)

Example 4 with IDatasourceMgmtService

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();
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) Before(org.junit.Before)

Example 5 with IDatasourceMgmtService

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();
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException) Before(org.junit.Before)

Aggregations

IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)14 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)11 Test (org.junit.Test)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)6 DataSource (javax.sql.DataSource)5 Matchers.anyString (org.mockito.Matchers.anyString)5 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)5 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)5 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)5 Before (org.junit.Before)3 ArrayList (java.util.ArrayList)2 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 ZipInputStream (java.util.zip.ZipInputStream)1 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)1