use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method testUploadArchiveFile.
private void testUploadArchiveFile(String archiveFileName, URL archiveFileSource, String testFolderName) throws Exception {
File tmpZipFile = tmpDir.newFile(archiveFileName);
FileUtils.copyInputStreamToFile(archiveFileSource.openStream(), tmpZipFile);
// use standard client
IDataSpaceClient client = clientInstance();
LocalFileSource source = new LocalFileSource(tmpZipFile);
RemoteDestination dest = new RemoteDestination(USER, testFolderName + "/" + archiveFileName);
assertTrue(client.upload(source, dest));
String destDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0)).getPath();
File destFile = new File(destDirPath, testFolderName + "/" + archiveFileName);
assertTrue(Files.equal(tmpZipFile, destFile));
// use RemoteSpace API
FileUtils.deleteQuietly(destFile);
client.getUserSpace().pushFile(tmpZipFile, testFolderName + "/" + archiveFileName);
assertTrue(Files.equal(tmpZipFile, destFile));
}
use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method testCreateFile.
@Test
public void testCreateFile() throws Exception {
URI srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0));
String filename = TEMP_FILE_TMP_NAME;
RemoteSource source = new RemoteSource(USER, filename);
source.setType(FileType.FILE);
IDataSpaceClient client = clientInstance();
assertTrue(client.create(source));
File expectedFile = new File(srcDirPath.getPath(), filename);
assertTrue(expectedFile.exists());
assertTrue(expectedFile.isFile());
}
use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method testDeleteFile.
@Test
public void testDeleteFile() throws Exception {
URI srcDirPath = URI.create(getScheduler().getUserSpaceURIs().get(0));
File srcFile = new File(new File(srcDirPath), TEMP_FILE_TMP_NAME);
if (srcFile.exists()) {
assertTrue(srcFile.delete());
}
Files.write(randomFileContents(), srcFile);
// use standard client
IDataSpaceClient client = clientInstance();
RemoteSource source = new RemoteSource(USER, TEMP_FILE_TMP_NAME);
assertTrue(client.delete(source));
assertFalse(srcFile.exists());
// use RemoteSpace API
Files.write(randomFileContents(), srcFile);
client.getUserSpace().deleteFile(TEMP_FILE_TMP_NAME);
assertFalse(srcFile.exists());
}
use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method clientInstance.
private IDataSpaceClient clientInstance() throws Exception {
DataSpaceClient client = new DataSpaceClient();
client.init(new ConnectionInfo(getRestServerUrl(), getLogin(), getPassword(), null, true));
return client;
}
use of org.ow2.proactive.scheduler.rest.ds.IDataSpaceClient in project scheduling by ow2-proactive.
the class DataTransferTest method testListFilesRecursive.
@Test
public void testListFilesRecursive() throws Exception {
System.out.println("testListFilesRecursive");
createFilesInUserSpace("testListFilesRecursive");
// use standard client
IDataSpaceClient client = clientInstance();
RemoteSource source = new RemoteSource(USER, "testListFilesRecursive");
source.setIncludes("**");
ListFile listFile = client.list(source);
List<String> directories = listFile.getDirectoryListing();
System.out.println("Directories : " + directories);
assertEquals(1, directories.size());
assertEquals(DataTransferTest.TEMP_DIR_NAME, directories.get(0));
List<String> files = listFile.getFileListing();
System.out.println("Files : " + files);
assertEquals(2, files.size());
assertEquals(TEMP_FILE_TMP_PATH, files.get(0));
assertEquals(TEMP_FILE_TXT_NAME, files.get(1));
// use RemoteSpace API
List<String> foundFiles = client.getUserSpace().listFiles("testListFilesRecursive", "**");
System.out.println("Full : " + foundFiles);
assertEquals(3, foundFiles.size());
assertArrayEquals(new String[] { TEMP_DIR_NAME, TEMP_FILE_TMP_PATH, TEMP_FILE_TXT_NAME }, foundFiles.toArray(new String[0]));
}
Aggregations