use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class FileServiceTest method mockDoRestoreInHomeDir.
public void mockDoRestoreInHomeDir(FileService fileService) {
IUnifiedRepository iUnifiedRepository = mock(IUnifiedRepository.class);
List<RepositoryFileDto> homeFolderFiles = getMockedRepositoryFileDtoList(new String[] { FILE_1, FILE_3 });
when(fileService.doGetChildren(eq(PATH_USER_HOME_FOLDER), anyString(), anyBoolean(), anyBoolean())).thenReturn(homeFolderFiles);
when(fileService.getRepository()).thenReturn(iUnifiedRepository);
when(fileService.doRestoreFilesInHomeDir(eq(PARAMS), anyInt())).thenCallRealMethod();
RepositoryFile mockRepoFile1 = getMockedRepoFile(FILE_1);
RepositoryFile mockRepoFile2 = getMockedRepoFile(FILE_2);
when(iUnifiedRepository.getFileById(eq(FILE_1))).thenReturn(mockRepoFile1);
when(iUnifiedRepository.getFileById(eq(FILE_2))).thenReturn(mockRepoFile2);
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class PentahoMetadataDomainRepositoryTest method testLoadAnnotationsXml.
@Test
public void testLoadAnnotationsXml() throws Exception {
String domainId = "test.xmi";
String domainFileId = "00000000";
String annotationsId = domainFileId + IModelAnnotationsAwareMetadataDomainRepositoryImporter.ANNOTATIONS_FILE_ID_POSTFIX;
String annotationsXml = "<annotations/>";
Log logger = mock(Log.class);
doReturn(logger).when(domainRepositorySpy).getLogger();
assertNull(domainRepositorySpy.loadAnnotationsXml(null));
assertNull(domainRepositorySpy.loadAnnotationsXml(""));
IUnifiedRepository repository = mock(IUnifiedRepository.class);
doReturn(repository).when(domainRepositorySpy).getRepository();
// Success
RepositoryFile domainFile = mock(RepositoryFile.class);
doReturn(domainFile).when(domainRepositorySpy).getMetadataRepositoryFile(domainId);
doReturn(domainFileId).when(domainFile).getId();
RepositoryFile annotationsFile = mock(RepositoryFile.class);
doReturn(annotationsFile).when(repository).getFile(File.separator + "etc" + File.separator + "metadata/" + annotationsId);
doReturn(annotationsId).when(annotationsFile).getId();
SimpleRepositoryFileData data = mock(SimpleRepositoryFileData.class);
doReturn(data).when(repository).getDataForRead(annotationsId, SimpleRepositoryFileData.class);
doReturn(IOUtils.toInputStream(annotationsXml)).when(data).getInputStream();
assertEquals(annotationsXml, domainRepositorySpy.loadAnnotationsXml(domainId));
// Error
doThrow(new RuntimeException()).when(data).getInputStream();
domainRepositorySpy.loadAnnotationsXml(domainId);
verify(logger, times(1)).warn("Unable to load annotations xml file for domain: test.xmi");
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class UserRoleDaoServiceTest method testCreateUserValidation.
@Test
public void testCreateUserValidation() {
List<String> reservedChars = Arrays.asList("/,\\,\t,\r,\n".split(","));
IUnifiedRepository repo = mock(IUnifiedRepository.class);
doReturn(reservedChars).when(repo).getReservedChars();
PentahoSystem.registerObject(repo);
UserRoleDaoService service = new UserRoleDaoService();
setupMockSessionUser(SESSION_USER_NAME, true);
Assert.assertTrue(validationFailed(service, new User("\\", "pass")));
Assert.assertTrue(validationFailed(service, new User("/www", "pass")));
Assert.assertTrue(validationFailed(service, new User("\tqwer", "pass")));
Assert.assertTrue(validationFailed(service, new User("\rqwer", "pass")));
Assert.assertTrue(validationFailed(service, new User("qwer\n", "pass")));
Assert.assertTrue(validationFailed(service, new User("normalName", "")));
Assert.assertTrue(validationFailed(service, new User("", "pass")));
Assert.assertTrue(validationFailed(service, new User(null, "pass")));
Assert.assertTrue(validationFailed(service, new User("name", null)));
Assert.assertFalse(validationFailed(service, new User("normalName", "pass")));
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileContentItem method getInputStream.
public InputStream getInputStream() throws ContentException {
if (inputStream == null) {
try {
RepositoryFileOutputStream outputStream = (RepositoryFileOutputStream) getOutputStream(null);
if ((outputStream.autoCreateUniqueFileName) && !(outputStream.flushed)) {
throw new FileNotFoundException("File not yet versioned.");
}
if (inputStream == null) {
IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
RepositoryFile repositoryFile = repository.getFile(outputStream.path);
if ((repositoryFile == null) || repositoryFile.isFolder()) {
throw new FileNotFoundException();
}
return new RepositoryFileInputStream(repositoryFile);
}
} catch (FileNotFoundException e) {
throw new ContentException(e);
} catch (IOException e) {
throw new ContentException(e);
}
}
return inputStream;
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileReader method getEncoding.
protected static String getEncoding(String path) throws FileNotFoundException {
IUnifiedRepository repository = PentahoSystem.get(IUnifiedRepository.class);
RepositoryFile file = (new RepositoryFileInputStream(path)).getFile();
SimpleRepositoryFileData fileData = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
return fileData.getEncoding();
}
Aggregations