69 lines
2.7 KiB
Java
69 lines
2.7 KiB
Java
package org.gcube.data.transfer.library;
|
|
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.net.MalformedURLException;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
import org.gcube.contentmanagement.blobstorage.transport.backend.RemoteBackendException;
|
|
import org.gcube.data.transfer.library.faults.FailedTransferException;
|
|
import org.gcube.data.transfer.library.faults.InitializationException;
|
|
import org.gcube.data.transfer.library.faults.InvalidSourceException;
|
|
import org.gcube.data.transfer.library.faults.ServiceNotFoundException;
|
|
import org.gcube.data.transfer.library.faults.SourceNotSetException;
|
|
import org.gcube.data.transfer.library.faults.UnreachableNodeException;
|
|
import org.gcube.data.transfer.library.utils.StorageUtils;
|
|
import org.junit.BeforeClass;
|
|
import org.junit.Test;
|
|
|
|
public class TransfererTest {
|
|
|
|
static String hostname="http://pc-fabio.isti.cnr.it:8080/data-transfer-service/gcube/service";
|
|
static String scope="/gcube/devNext";
|
|
|
|
static DataTransferClient client;
|
|
|
|
@BeforeClass
|
|
public static void init() throws UnreachableNodeException, ServiceNotFoundException{
|
|
ScopeProvider.instance.set(scope);
|
|
client=DataTransferClient.getInstanceByEndpoint(hostname);
|
|
}
|
|
|
|
@Test
|
|
public void localFile() throws InvalidSourceException, SourceNotSetException, FailedTransferException, InitializationException{
|
|
String localFile="/home/fabio/Downloads/Puntata 3.mp3";
|
|
System.out.println(client.localFile(localFile));
|
|
}
|
|
|
|
|
|
@Test
|
|
public void httpUrl() throws MalformedURLException, InvalidSourceException, SourceNotSetException, FailedTransferException, InitializationException{
|
|
String link="http://goo.gl/oLP7zG";
|
|
System.out.println(client.httpSource(link));
|
|
}
|
|
|
|
|
|
@Test
|
|
public void storage() throws InvalidSourceException, SourceNotSetException, FailedTransferException, InitializationException, RemoteBackendException, FileNotFoundException{
|
|
String toUpload="/home/fabio/Downloads/Incantesimi3_5.doc";
|
|
System.out.println(client.storageId(StorageUtils.putOntoStorage(new File(toUpload))));
|
|
}
|
|
|
|
@Test
|
|
public void wrongStorage() throws InvalidSourceException, SourceNotSetException, FailedTransferException, InitializationException{
|
|
System.out.println(client.storageId("13245780t"));
|
|
}
|
|
|
|
@Test
|
|
public void wrongLocal() throws InvalidSourceException, SourceNotSetException, FailedTransferException, InitializationException{
|
|
String localFile="/home/fabio/Downloads/123045689.mp3";
|
|
System.out.println(client.localFile(localFile));
|
|
}
|
|
|
|
@Test
|
|
public void wrongUrl() throws MalformedURLException, InvalidSourceException, SourceNotSetException, FailedTransferException, InitializationException{
|
|
String link="https://www.dropbox.com/s/789023450";
|
|
System.out.println(client.httpSource(link));
|
|
}
|
|
}
|