use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class UnifiedRepositoryTestUtils method stubGetChildren.
/**
* Stubs a {@code getChildren} call. {@code childrenNames} is zero or more file/folder names. A folder is
* indicated by a trailing forward slash.
*
* <p>
* Example:
* </p>
*
* <pre>
* stubGetChildren( repo, "/public", "hello/", "file1.txt" );
* </pre>
*/
public static void stubGetChildren(final IUnifiedRepository repo, final String path, final String... childrenNames) {
List<RepositoryFile> children = new ArrayList<RepositoryFile>(childrenNames.length);
for (String childName : childrenNames) {
if (childName.startsWith(RepositoryFile.SEPARATOR)) {
throw new IllegalArgumentException("child names must not begin with a forward slash");
}
final String fullChildPath = path + RepositoryFile.SEPARATOR + (childName.endsWith(RepositoryFile.SEPARATOR) ? StringUtils.substringBefore(childName, RepositoryFile.SEPARATOR) : childName);
RepositoryFile child = null;
if (childName.endsWith(RepositoryFile.SEPARATOR)) {
child = makeFolderObject(fullChildPath, true);
} else {
child = makeFileObject(fullChildPath, true);
}
children.add(child);
}
doReturn(children).when(repo).getChildren(makeIdObject(path));
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class UnifiedRepositoryTestUtils method stubGetChildren.
/**
* Stubs a {@code getChildren} call. {@code childrenNames} is zero or more file/folder names. A folder is
* indicated by a trailing forward slash.
*
* <p>
* Example:
* </p>
*
* <pre>
* stubGetChildren( repo, "/public", "hello/", "file1.txt" );
* </pre>
*/
public static void stubGetChildren(final IUnifiedRepository repo, RepositoryRequest request, final String... childrenNames) {
List<RepositoryFile> children = new ArrayList<RepositoryFile>(childrenNames.length);
for (String childName : childrenNames) {
if (childName.startsWith(RepositoryFile.SEPARATOR)) {
throw new IllegalArgumentException("child names must not begin with a forward slash");
}
final String fullChildPath = request.getPath() + RepositoryFile.SEPARATOR + (childName.endsWith(RepositoryFile.SEPARATOR) ? StringUtils.substringBefore(childName, RepositoryFile.SEPARATOR) : childName);
RepositoryFile child = null;
if (childName.endsWith(RepositoryFile.SEPARATOR)) {
child = makeFolderObject(fullChildPath, true);
} else {
child = makeFileObject(fullChildPath, true);
}
children.add(child);
}
doReturn(children).when(repo).getChildren(request);
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileIoTest method testReadNonExistentFile.
@Test(expected = FileNotFoundException.class)
public void testReadNonExistentFile() throws IOException {
final String fileName = "doesnotexist";
final String filePath = publicDirPath + "/" + fileName;
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// simulate file does not exist
doReturn(null).when(repo).getFile(filePath);
mp.defineInstance(IUnifiedRepository.class, repo);
RepositoryFileReader reader = new RepositoryFileReader(createFile(fileName));
reader.close();
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileIoTest method testWriteFileAtNewDir.
@Test(expected = FileNotFoundException.class)
public void testWriteFileAtNewDir() throws IOException {
final String fileName = "test.txt";
final String intermediateDir = "newdir";
final String filePath = publicDirPath + "/" + intermediateDir + "/" + fileName;
IUnifiedRepository repo = mock(IUnifiedRepository.class);
// simulate path does not exist
doReturn(null).when(repo).getFile(publicDirPath + "/" + intermediateDir);
mp.defineInstance(IUnifiedRepository.class, repo);
RepositoryFileWriter writer = new RepositoryFileWriter(filePath, "UTF-8");
writer.write("test123");
writer.close();
// test should fail because 'newdir' does not exist and the file writer
// should not create missing dirs
}
use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository in project pentaho-platform by pentaho.
the class RepositoryFileIoTest method testWriteToPath.
@Test
public void testWriteToPath() throws IOException {
final String fileName = "test-file1.txt";
final String filePath = publicDirPath + "/" + fileName;
IUnifiedRepository repo = mock(IUnifiedRepository.class);
RepositoryFile existingFile = new RepositoryFile.Builder("123", fileName).build();
// simulate file already exists
doReturn(existingFile).when(repo).getFile(filePath);
mp.defineInstance(IUnifiedRepository.class, repo);
RepositoryFileWriter writer = new RepositoryFileWriter(filePath, "UTF-8");
writer.write("test123");
writer.close();
verify(repo).updateFile(argThat(isLikeFile(existingFile)), argThat(hasData("test123", "UTF-8", "text/plain")), anyString());
}
Aggregations