use of org.pentaho.database.model.IDatabaseConnection in project data-access by pentaho.
the class ConnectionServiceHelperTest method setUp.
@Before
public void setUp() throws Exception {
when(service.getDatasourceByName(anyString())).thenAnswer(new Answer<IDatabaseConnection>() {
@Override
public IDatabaseConnection answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(VALID_CONNECTION)) {
return connection;
}
if (invocation.getArguments()[0].equals(INVALID_CONNECTION)) {
return null;
}
// throw exception for check if we get exception from getting connection
throw new DatasourceMgmtServiceException();
}
});
pentahoObjectFactory = mock(IPentahoObjectFactory.class);
when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
if (invocation.getArguments()[0].equals(IDatasourceMgmtService.class)) {
return service;
}
return null;
}
});
PentahoSystem.registerObjectFactory(pentahoObjectFactory);
}
use of org.pentaho.database.model.IDatabaseConnection 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))), nullable(String.class));
}
use of org.pentaho.database.model.IDatabaseConnection 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.database.model.IDatabaseConnection in project pentaho-platform by pentaho.
the class DatasourceMgmtToWebServiceAdapterTest method createDatabaseConnection.
private IDatabaseConnection createDatabaseConnection(final String dbName) throws Exception {
IDatabaseConnection dbConnection = new DatabaseConnection();
dbConnection.setName(dbName);
dbConnection.setHostname(EXP_DBMETA_HOSTNAME);
dbConnection.setDatabaseType(mockDatabaseType("Hypersonic"));
dbConnection.setAccessType(DatabaseAccessType.NATIVE);
dbConnection.setDatabasePort(EXP_DBMETA_PORT);
return dbConnection;
}
use of org.pentaho.database.model.IDatabaseConnection in project pentaho-platform by pentaho.
the class NonPooledDatasourceSystemListener method startup.
public boolean startup(final IPentahoSession session) {
try {
// $NON-NLS-1$
Logger.debug(this, "DatasourceSystemListener: called for startup ...");
ICacheManager cacheManager = addCacheRegions();
List<IDatabaseConnection> databaseConnections = getListOfDatabaseConnections(session);
String dsName = "";
DataSource ds = null;
for (IDatabaseConnection databaseConnection : databaseConnections) {
if (databaseConnection != null) {
// $NON-NLS-1$
Logger.debug(this, " Setting up datasource - " + databaseConnection);
dsName = databaseConnection.getName();
// http://jira.pentaho.com/browse/BISERVER-12244
if (!databaseConnection.getAccessType().equals(DatabaseAccessType.JNDI)) {
// if connection's port used by server there is no sense to get DataSource for this
ds = isPortUsedByServer(databaseConnection) ? null : setupDataSourceForConnection(databaseConnection);
} else {
Logger.debug(this, // $NON-NLS-1$
"(Datasource \"" + IDBDatasourceService.JDBC_DATASOURCE + dsName + // $NON-NLS-1$
"\" not cached)");
continue;
}
cacheManager.putInRegionCache(IDBDatasourceService.JDBC_DATASOURCE, dsName, ds);
Logger.debug(this, // $NON-NLS-1$
"(Storing datasource under key \"" + IDBDatasourceService.JDBC_DATASOURCE + dsName + // $NON-NLS-1$
"\")");
}
}
// $NON-NLS-1$
Logger.debug(this, "DatasourceSystemListener: Completed startup.");
return true;
} catch (ObjectFactoryException objface) {
Logger.error(this, Messages.getInstance().getErrorString("DatasourceSystemListener.ERROR_0001_UNABLE_TO_INSTANTIATE_OBJECT"), // $NON-NLS-1$
objface);
return false;
} catch (DatasourceMgmtServiceException dmse) {
Logger.error(this, Messages.getInstance().getErrorString("DatasourceSystemListener.ERROR_0002_UNABLE_TO_GET_DATASOURCE"), // $NON-NLS-1$
dmse);
return false;
}
}
Aggregations