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());
}
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));
}
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();
}
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);
}
}
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);
}
}
Aggregations