Search in sources :

Example 21 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository 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))), anyString());
}
Also used : 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 22 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtServiceTest method testDeleteDatasourceWithName.

@Test
public void testDeleteDatasourceWithName() 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 delete
    doReturn(new RepositoryFile.Builder(fileId, EXP_DBMETA_NAME + dotKdb).build()).when(repo).getFile(databasesFolderPath + RepositoryFile.SEPARATOR + EXP_DBMETA_NAME + dotKdb);
    IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
    datasourceMgmtService.deleteDatasourceByName(EXP_DBMETA_NAME);
    verify(repo).deleteFile(eq(fileId), eq(true), anyString());
}
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 23 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.

the class SolutionRepositoryVfsFileObjectTest method initFileTest.

@Test
public void initFileTest() throws Exception {
    String fileRef = "/etc/mondrian/SteelWheels/schema.xml";
    String dsRef = "/etc/mondrian/SteelWheels";
    SolutionRepositoryVfsFileObject fileObject = new SolutionRepositoryVfsFileObject(fileRef);
    SolutionRepositoryVfsFileObject fileObjectSpy = spy(fileObject);
    IAclNodeHelper aclNodeHelper = mock(IAclNodeHelper.class);
    doReturn(aclNodeHelper).when(fileObjectSpy).getAclHelper();
    RepositoryFile file = mock(RepositoryFile.class);
    doReturn(true).when(aclNodeHelper).canAccess(file, EnumSet.of(RepositoryFilePermission.READ));
    IUnifiedRepository repository = mock(IUnifiedRepository.class);
    doReturn(file).when(repository).getFile(fileRef);
    doReturn(repository).when(fileObjectSpy).getRepository();
    fileObjectSpy.getName();
    verify(repository, times(1)).getFile(eq(dsRef));
    verify(repository, times(1)).getFile(eq(fileRef));
    verify(aclNodeHelper, times(1)).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
    fileRef = "/etca/mondriana/SteelWheels/schema.xml";
    fileObject = new SolutionRepositoryVfsFileObject(fileRef);
    fileObjectSpy = spy(fileObject);
    doReturn(aclNodeHelper).when(fileObjectSpy).getAclHelper();
    doReturn(false).when(aclNodeHelper).canAccess(file, EnumSet.of(RepositoryFilePermission.READ));
    doReturn(repository).when(fileObjectSpy).getRepository();
    fileObjectSpy.getName();
    verify(repository, times(2)).getFile(eq(fileRef));
    verify(aclNodeHelper, times(2)).canAccess(any(RepositoryFile.class), eq(EnumSet.of(RepositoryFilePermission.READ)));
}
Also used : IAclNodeHelper(org.pentaho.platform.api.repository2.unified.IAclNodeHelper) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 24 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepositoryTest method testCreateOrUpdateAnnotationsXml.

@Test
public void testCreateOrUpdateAnnotationsXml() throws Exception {
    String metadataDirId = "00000000";
    String annotationsXml = "<annotations/>";
    RepositoryFile metaDataDir = mock(RepositoryFile.class);
    IUnifiedRepository repository = mock(IUnifiedRepository.class);
    Log logger = mock(Log.class);
    doReturn(logger).when(domainRepositorySpy).getLogger();
    doReturn(repository).when(domainRepositorySpy).getRepository();
    doReturn(metadataDirId).when(metaDataDir).getId();
    doReturn(metaDataDir).when(domainRepositorySpy).getMetadataDir();
    // Domain Not Found
    domainRepositorySpy.createOrUpdateAnnotationsXml(null, null, annotationsXml);
    verify(domainRepositorySpy, times(0)).getRepository();
    RepositoryFile domainFile = mock(RepositoryFile.class);
    // Create
    domainRepositorySpy.createOrUpdateAnnotationsXml(domainFile, null, annotationsXml);
    verify(repository, times(1)).createFile(any(String.class), any(RepositoryFile.class), any(IRepositoryFileData.class), any(String.class));
    // Update
    RepositoryFile annotationsFile = mock(RepositoryFile.class);
    domainRepositorySpy.createOrUpdateAnnotationsXml(domainFile, annotationsFile, annotationsXml);
    verify(repository, times(1)).updateFile(any(RepositoryFile.class), any(IRepositoryFileData.class), any(String.class));
    // Error
    doThrow(new RuntimeException()).when(domainRepositorySpy).getRepository();
    domainRepositorySpy.createOrUpdateAnnotationsXml(domainFile, annotationsFile, annotationsXml);
    verify(logger, times(1)).warn(any(), any(Throwable.class));
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Log(org.apache.commons.logging.Log) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 25 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepositoryTest method testGetAnnotationsXmlFile.

@Test
public void testGetAnnotationsXmlFile() throws Exception {
    String domainFileId = "00000000";
    assertNull(domainRepositorySpy.getAnnotationsXmlFile(null));
    Log logger = mock(Log.class);
    doReturn(logger).when(domainRepositorySpy).getLogger();
    IUnifiedRepository repository = mock(IUnifiedRepository.class);
    doReturn(repository).when(domainRepositorySpy).getRepository();
    RepositoryFile domainFile = mock(RepositoryFile.class);
    doReturn(domainFileId).when(domainFile).getId();
    // Not Found
    doReturn(domainFile).when(repository).getFileById("someOtherId");
    assertNull(domainRepositorySpy.getAnnotationsXmlFile(domainFile));
    // Found
    String annotationsFilePath = File.separator + "etc" + File.separator + "metadata/" + domainFileId + IModelAnnotationsAwareMetadataDomainRepositoryImporter.ANNOTATIONS_FILE_ID_POSTFIX;
    doReturn(domainFile).when(repository).getFile(annotationsFilePath);
    assertNotNull(domainRepositorySpy.getAnnotationsXmlFile(domainFile));
    // Error
    doThrow(new RuntimeException()).when(domainRepositorySpy).getRepository();
    assertNull(domainRepositorySpy.getAnnotationsXmlFile(domainFile));
    verify(logger, times(1)).warn("Unable to find annotations xml file for: " + domainFile.getId());
}
Also used : Log(org.apache.commons.logging.Log) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) 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