2018-02-15 18:13:50 +01:00
|
|
|
package org.gcube.data.access.fs;
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.common.storagehub.client.StreamDescriptor;
|
|
|
|
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.ItemManagerClient;
|
|
|
|
import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
public class TestCall {
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setUp(){
|
2018-03-07 18:42:10 +01:00
|
|
|
SecurityTokenProvider.instance.set("52b59669-ccde-46d2-a4da-108b9e941f7c-98187548");
|
2018-02-15 18:13:50 +01:00
|
|
|
ScopeProvider.instance.set("/gcube/devNext");
|
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
2018-03-07 18:42:10 +01:00
|
|
|
public void getListByPath() throws Exception{
|
2018-02-15 18:13:50 +01:00
|
|
|
WorkspaceManagerClient client = AbstractPlugin.workspace().build();
|
2018-03-07 18:42:10 +01:00
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
client.getWorkspace("hl:accounting", "jcr:content");
|
|
|
|
System.out.println("["+Thread.currentThread().getName()+"] took: "+(System.currentTimeMillis()-start) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i=0; i<=1; i++)
|
|
|
|
new Thread(runnable).start();
|
|
|
|
|
|
|
|
|
|
|
|
System.in.read();
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
|
|
|
public void getById() throws Exception{
|
2018-03-07 18:42:10 +01:00
|
|
|
final ItemManagerClient client = AbstractPlugin.item().build();
|
|
|
|
Runnable runnable = new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
client.getChildren("07cd8d55-a35b-4445-9680-c98f158c55de", "hl:accounting", "jcr:content");
|
|
|
|
System.out.println("["+Thread.currentThread().getName()+"] took: "+(System.currentTimeMillis()-start) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i=0; i<=1; i++)
|
|
|
|
new Thread(runnable).start();
|
|
|
|
|
|
|
|
|
|
|
|
System.in.read();
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
|
|
|
public void download() throws Exception{
|
|
|
|
ItemManagerClient client = AbstractPlugin.item().build();
|
|
|
|
StreamDescriptor streamDescr = client.download("07cd8d55-a35b-4445-9680-c98f158c55de");
|
|
|
|
File output = Files.createTempFile("down", streamDescr.getFileName()).toFile();
|
|
|
|
try (BufferedInputStream bi = new BufferedInputStream(streamDescr.getStream()); FileOutputStream fo = new FileOutputStream(output)){
|
|
|
|
byte[] buf = new byte[2048];
|
|
|
|
int read = -1;
|
|
|
|
while ((read=bi.read(buf))!=-1) {
|
|
|
|
fo.write(buf, 0, read);
|
|
|
|
}
|
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
System.out.println("file written "+output.getAbsolutePath());
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
|
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
|
|
|
/*
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
|
|
|
public void createFolder() throws Exception{
|
|
|
|
Items.createFolder();
|
|
|
|
}
|
2018-03-07 18:42:10 +01:00
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
@Test
|
|
|
|
public void createFile() throws Exception{
|
|
|
|
Items.create();
|
|
|
|
}*/
|
2018-03-07 18:42:10 +01:00
|
|
|
|
|
|
|
|
2018-02-15 18:13:50 +01:00
|
|
|
}
|