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