Search in sources :

Example 71 with IUnifiedRepository

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

Example 72 with IUnifiedRepository

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");
}
Also used : Log(org.apache.commons.logging.Log) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) 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 73 with IUnifiedRepository

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")));
}
Also used : IPentahoUser(org.pentaho.platform.api.engine.security.userroledao.IPentahoUser) User(org.pentaho.platform.web.http.api.resources.User) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 74 with IUnifiedRepository

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;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) ContentException(org.pentaho.platform.api.repository.ContentException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IOException(java.io.IOException) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 75 with IUnifiedRepository

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

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