Search in sources :

Example 11 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtServiceTest method testUpdateDatasourceWithName.

@Test
public void testUpdateDatasourceWithName() 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);
    // stub out update file which requires a file to be returned
    doReturn(f).when(repo).updateFile(any(RepositoryFile.class), any(NodeRepositoryFileData.class), anyString());
    IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
    IDatabaseConnection databaseConnection = createDatabaseConnection(EXP_DBMETA_NAME);
    updateDatabaseConnection(databaseConnection);
    datasourceMgmtService.updateDatasourceByName(EXP_DBMETA_NAME, databaseConnection);
    verify(repo).updateFile(argThat(isLikeFile(new RepositoryFile.Builder(EXP_DBMETA_NAME + ".kdb").build())), argThat(hasData(pathPropertyPair("/databaseMeta/HOST_NAME", EXP_UPDATED_DBMETA_HOSTNAME))), anyString());
}
Also used : 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 12 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtServiceTest method testDatasourceNotFound.

@Test
public void testDatasourceNotFound() throws Exception {
    final String datasourceName = "not_here";
    final String dotKdb = ".kdb";
    final String fileName = datasourceName + dotKdb;
    final String databasesFolderPath = "/etc/pdi/databases";
    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 not found
    doReturn(null).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + fileName);
    IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
    Assert.assertNull(datasourceMgmtService.getDatasourceByName(datasourceName));
}
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 13 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project pentaho-platform by pentaho.

the class DatasourceMgmtToWebServiceAdapterTest method setUp.

@Override
protected void setUp() throws Exception {
    IUnifiedRepository repository = new MockUnifiedRepository(new MockUnifiedRepository.SpringSecurityCurrentUserProvider());
    datasourceMgmtService = new JcrBackedDatasourceMgmtService(repository, new DatabaseDialectService());
    datasourceMgmtWS = new DefaultDatasourceMgmtWebService(datasourceMgmtService);
    adapter = new DatasourceMgmtToWebServiceAdapter(datasourceMgmtWS);
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(MockUnifiedRepository.root().getName(), null, new ArrayList<GrantedAuthority>()));
    repository.createFolder(repository.getFile("/etc").getId(), new RepositoryFile.Builder(FOLDER_PDI).folder(true).build(), new RepositoryFileAcl.Builder(MockUnifiedRepository.root()).ace(MockUnifiedRepository.everyone(), READ, WRITE).build(), null);
    repository.createFolder(repository.getFile("/etc/pdi").getId(), new RepositoryFile.Builder(FOLDER_DATABASES).folder(true).build(), null);
    SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(EXP_LOGIN, null, new ArrayList<GrantedAuthority>()));
    KettleClientEnvironment.init();
}
Also used : ArrayList(java.util.ArrayList) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) MockUnifiedRepository(org.pentaho.test.platform.repository2.unified.MockUnifiedRepository) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) JcrBackedDatasourceMgmtService(org.pentaho.platform.repository.JcrBackedDatasourceMgmtService) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 14 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project pentaho-platform by pentaho.

the class PooledDatasourceHelperTest method testCreatePoolNoDialectService.

@Test
public void testCreatePoolNoDialectService() throws Exception {
    DatabaseDialectService dialectService = new DatabaseDialectService(false);
    final DatabaseTypeHelper databaseTypeHelper = new DatabaseTypeHelper(dialectService.getDatabaseTypes());
    final DatabaseConnection con = new DatabaseConnection();
    con.setId("Postgres");
    con.setName("Postgres");
    con.setAccessType(DatabaseAccessType.NATIVE);
    con.setDatabaseType(databaseTypeHelper.getDatabaseTypeByShortName("GENERIC"));
    con.setUsername("pentaho_user");
    con.setPassword("password");
    final HashMap<String, String> attrs = new HashMap<>();
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "org.postgresql.Driver");
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
    con.setAttributes(attrs);
    try {
        PooledDatasourceHelper.setupPooledDataSource(con);
        fail("Expecting the exception to be thrown");
    } catch (DBDatasourceServiceException ex) {
        assertNotNull(ex);
    }
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) DatabaseTypeHelper(org.pentaho.database.util.DatabaseTypeHelper) HashMap(java.util.HashMap) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 15 with DatabaseDialectService

use of org.pentaho.database.service.DatabaseDialectService in project pentaho-platform by pentaho.

the class PooledDatasourceHelperTest method testCreatePoolNoDialect.

@Test
public void testCreatePoolNoDialect() throws Exception {
    DatabaseDialectService dialectService = new DatabaseDialectService(false);
    mp = new MicroPlatform(SOLUTION_PATH);
    mp.defineInstance(IDatabaseDialectService.class, dialectService);
    mp.start();
    final DatabaseConnection con = new DatabaseConnection();
    con.setId("Postgres");
    con.setName("Postgres");
    con.setAccessType(DatabaseAccessType.NATIVE);
    con.setUsername("pentaho_user");
    con.setPassword("password");
    final HashMap<String, String> attrs = new HashMap<>();
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_DRIVER_CLASS, "");
    attrs.put(DatabaseConnection.ATTRIBUTE_CUSTOM_URL, "jdbc:postgresql://localhost:5432/hibernate");
    con.setAttributes(attrs);
    try {
        PooledDatasourceHelper.setupPooledDataSource(con);
        fail("Expecting the exception to be thrown");
    } catch (DBDatasourceServiceException ex) {
        assertNotNull(ex);
    }
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) HashMap(java.util.HashMap) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)17 Test (org.junit.Test)10 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)10 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)7 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)7 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)6 IDatabaseDialectService (org.pentaho.database.service.IDatabaseDialectService)6 HashMap (java.util.HashMap)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 Matchers.anyString (org.mockito.Matchers.anyString)5 DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 IDatabaseDialect (org.pentaho.database.IDatabaseDialect)4 DatabaseTypeHelper (org.pentaho.database.util.DatabaseTypeHelper)4 DatabaseDialectException (org.pentaho.database.DatabaseDialectException)3 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)3 Driver (java.sql.Driver)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)2