Search in sources :

Example 86 with IUnifiedRepository

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

the class RepositoryFileIoTest method testWriteToFile.

@Test
public void testWriteToFile() throws IOException {
    final String fileName = "test-file2.txt";
    RepositoryFile file = createFile(fileName);
    IUnifiedRepository repo = mock(IUnifiedRepository.class);
    // simulate request for publicDir
    RepositoryFile publicDir = new RepositoryFile.Builder("123", ClientRepositoryPaths.getPublicFolderName()).folder(true).build();
    doReturn(publicDir).when(repo).getFile(publicDirPath);
    mp.defineInstance(IUnifiedRepository.class, repo);
    RepositoryFileWriter writer = new RepositoryFileWriter(file, "UTF-8");
    writer.write("test123");
    writer.close();
    verify(repo).createFile(eq("123"), argThat(isLikeFile(new RepositoryFile.Builder(fileName).build())), argThat(hasData("test123", "UTF-8", "text/plain")), anyString());
}
Also used : 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 87 with IUnifiedRepository

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

the class RepositoryFileIoTest method testWriteBinary.

@Test
public void testWriteBinary() throws IOException {
    final String fileName = "test.bin";
    final String filePath = publicDirPath + "/" + fileName;
    IUnifiedRepository repo = mock(IUnifiedRepository.class);
    // simulate request for publicDir
    RepositoryFile publicDir = new RepositoryFile.Builder("123", ClientRepositoryPaths.getPublicFolderName()).folder(true).build();
    doReturn(publicDir).when(repo).getFile(publicDirPath);
    mp.defineInstance(IUnifiedRepository.class, repo);
    final byte[] expectedPayload = "binary string".getBytes();
    RepositoryFileOutputStream rfos = new RepositoryFileOutputStream(filePath);
    IOUtils.write(expectedPayload, rfos);
    rfos.close();
    verify(repo).createFile(eq("123"), argThat(isLikeFile(new RepositoryFile.Builder(fileName).build())), argThat(hasData(expectedPayload, "application/octet-stream")), anyString());
}
Also used : 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 88 with IUnifiedRepository

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

the class ActionRunner method deleteEmptyFile.

private void deleteEmptyFile() {
    IUnifiedRepository repo = PentahoSystem.get(IUnifiedRepository.class);
    RepositoryFile file = repo.getFile(outputFilePath);
    Long emptyFileSize = new Long(0);
    Long fileSize = file.getFileSize();
    if (fileSize.equals(emptyFileSize)) {
        repo.deleteFile(file.getId(), true, null);
    }
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 89 with IUnifiedRepository

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

the class RepositoryFileTreeAdapterTest method testBIServer7777.

/**
 * Assert empty list in RepositoryFileTree#children survives full jaxb serialization roundtrip
 */
@Test
public void testBIServer7777() throws Exception {
    IUnifiedRepository unifiedRepository = mock(IUnifiedRepository.class);
    PentahoSystem.registerObject(unifiedRepository);
    RepositoryFileAcl acl = new RepositoryFileAcl.Builder("admin").build();
    when(unifiedRepository.getAcl(anyString())).thenReturn(acl);
    IRepositoryVersionManager mockRepositoryVersionManager = mock(IRepositoryVersionManager.class);
    when(mockRepositoryVersionManager.isVersioningEnabled(anyString())).thenReturn(true);
    when(mockRepositoryVersionManager.isVersionCommentEnabled(anyString())).thenReturn(false);
    JcrRepositoryFileUtils.setRepositoryVersionManager(mockRepositoryVersionManager);
    // file tree with empty children
    RepositoryFile empty = new RepositoryFile.Builder("empty").build();
    RepositoryFileTree emptyDir = new RepositoryFileTree(empty, Collections.<RepositoryFileTree>emptyList());
    RepositoryFile root = new RepositoryFile.Builder("rootDir").build();
    ArrayList<RepositoryFileTree> children = new ArrayList<RepositoryFileTree>(1);
    children.add(emptyDir);
    RepositoryFileTree rootDir = new RepositoryFileTree(root, children);
    // to DTO
    RepositoryFileTreeAdapter adapter = new RepositoryFileTreeAdapter();
    RepositoryFileTreeDto dtoThere = adapter.marshal(rootDir);
    assertNotNull(dtoThere.getChildren().get(0).getChildren());
    // serialize
    final JAXBContext jaxbContext = JAXBContext.newInstance(RepositoryFileTreeDto.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    StringWriter sw = new StringWriter();
    marshaller.marshal(dtoThere, sw);
    // and bring it back
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
    StringReader sr = new StringReader(sw.toString());
    RepositoryFileTreeDto dtoBackAgain = (RepositoryFileTreeDto) unmarshaller.unmarshal(sr);
    assertNotNull(dtoBackAgain.getChildren().get(0).getChildren());
    // unmarshall
    RepositoryFileTree rootDir2 = adapter.unmarshal(dtoBackAgain);
    assertNotNull(rootDir2.getChildren().get(0).getChildren());
    assertEquals(rootDir, rootDir2);
}
Also used : Marshaller(javax.xml.bind.Marshaller) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) IRepositoryVersionManager(org.pentaho.platform.api.repository2.unified.IRepositoryVersionManager) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) StringWriter(java.io.StringWriter) StringReader(java.io.StringReader) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Unmarshaller(javax.xml.bind.Unmarshaller) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 90 with IUnifiedRepository

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

the class MondrianCatalogHelperIT method testGenerateInMemoryDatasourcesXml_NullEtcMondrianFolder.

@Test
public void testGenerateInMemoryDatasourcesXml_NullEtcMondrianFolder() throws Exception {
    MondrianCatalogHelper helperMock = mock(MondrianCatalogHelper.class);
    IUnifiedRepository unifiedRepositoryMock = mock(IUnifiedRepository.class);
    doReturn(null).when(unifiedRepositoryMock).getFile(any(String.class));
    doCallRealMethod().when(helperMock).generateInMemoryDatasourcesXml(any(IUnifiedRepository.class));
    String result = helperMock.generateInMemoryDatasourcesXml(unifiedRepositoryMock);
    assertNull(result, null);
}
Also used : 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