use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class DefaultDatasourceMgmtWebServiceTest method setUp.
public void setUp() throws Exception {
IUnifiedRepository repository = new MockUnifiedRepository(new MockUnifiedRepository.SpringSecurityCurrentUserProvider());
datasourceMgmtService = new JcrBackedDatasourceMgmtService(repository, new DatabaseDialectService());
datasourceMgmtWebService = new DefaultDatasourceMgmtWebService(datasourceMgmtService);
dbConnectionAdapter = new DatabaseConnectionAdapter();
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.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileIoTest method testReadDirectoryPath.
@Test(expected = FileNotFoundException.class)
public void testReadDirectoryPath() throws IOException {
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// simulate file exists but is a directory
doReturn(new RepositoryFile.Builder("123", ClientRepositoryPaths.getPublicFolderName()).folder(true).build()).when(repo).getFile(ClientRepositoryPaths.getPublicFolderPath());
mp.defineInstance(IUnifiedRepository.class, repo);
RepositoryFileReader reader = new RepositoryFileReader(ClientRepositoryPaths.getPublicFolderPath());
reader.close();
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileIoTest method testReadNonExistentPath.
@Test(expected = FileNotFoundException.class)
public void testReadNonExistentPath() throws IOException {
final String filePath = ClientRepositoryPaths.getPublicFolderPath() + "/doesnotexist";
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// simulate path does not exist
doReturn(null).when(repo).getFile(filePath);
mp.defineInstance(IUnifiedRepository.class, repo);
RepositoryFileReader reader = new RepositoryFileReader(filePath);
reader.close();
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileIoTest method testWriteDirectory.
@Test(expected = FileNotFoundException.class)
public void testWriteDirectory() throws IOException {
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// simulate file exists but is a directory
doReturn(new RepositoryFile.Builder("123", ClientRepositoryPaths.getPublicFolderName()).folder(true).build()).when(repo).getFile(ClientRepositoryPaths.getPublicFolderPath());
mp.defineInstance(IUnifiedRepository.class, repo);
RepositoryFileWriter writer = new RepositoryFileWriter(ClientRepositoryPaths.getPublicFolderPath(), "UTF-8");
writer.close();
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository 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());
}
Aggregations