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