Search in sources :

Example 16 with IUnifiedRepository

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();
}
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 17 with IUnifiedRepository

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();
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 18 with IUnifiedRepository

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

Example 19 with IUnifiedRepository

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();
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 20 with IUnifiedRepository

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

Aggregations

IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)88 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)61 Test (org.junit.Test)51 Matchers.anyString (org.mockito.Matchers.anyString)37 ArrayList (java.util.ArrayList)18 List (java.util.List)10 StringObjectId (org.pentaho.di.repository.StringObjectId)10 Serializable (java.io.Serializable)9 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)7 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)7 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)7 InputStream (java.io.InputStream)6 JobMeta (org.pentaho.di.job.JobMeta)6 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)6 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)6 HashMap (java.util.HashMap)5 ObjectId (org.pentaho.di.repository.ObjectId)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 Properties (java.util.Properties)4 Log (org.apache.commons.logging.Log)4