2014-10-20 11:24:56 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
|
|
|
|
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
|
|
|
|
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
|
|
|
* @Oct 20, 2014
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class UriResolverTest {
|
|
|
|
|
2014-10-21 12:44:00 +02:00
|
|
|
@Test
|
2014-10-24 14:30:07 +02:00
|
|
|
public void testGIS() {
|
2014-10-20 11:24:56 +02:00
|
|
|
|
|
|
|
try {
|
|
|
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
|
|
|
UriResolverManager resolver = new UriResolverManager("GIS");
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
2014-10-29 16:03:09 +01:00
|
|
|
params.put("gis-UUID", "5ac49f44-999f-4efe-a32b-af71da2b39ac");
|
2014-10-20 11:24:56 +02:00
|
|
|
params.put("scope", "/gcube/devsec/devVRE");
|
|
|
|
String shortLink = resolver.getLink(params, true);
|
2014-10-20 11:28:59 +02:00
|
|
|
System.out.println(shortLink); //true, link is shorted otherwise none
|
2014-10-20 11:24:56 +02:00
|
|
|
} catch (UriResolverMapException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2014-10-21 12:43:00 +02:00
|
|
|
|
2014-10-29 16:03:09 +01:00
|
|
|
// @Test
|
2014-10-24 14:30:07 +02:00
|
|
|
public void testSMP() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
|
|
|
UriResolverManager resolver = new UriResolverManager("SMP");
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
|
params.put("smp-uri","smp://Wikipedia_logo_silver.png?5ezvFfBOLqaqBlwCEtAvz4ch5BUu1ag3yftpCvV+gayz9bAtSsnO1/sX6pemTKbDe0qbchLexXeWgGcJlskYE8td9QSDXSZj5VSl9kdN9SN0/LRYaWUZuP4Q1J7lEiwkU4GKPsiD6PDRVcT4QAqTEy5hSIbr6o4Y");
|
|
|
|
params.put("fileName", "wikipediaLogo");
|
|
|
|
params.put("contentType", "image/jpeg"); //true, link is shorted otherwise none
|
|
|
|
String shortLink = resolver.getLink(params, true);
|
|
|
|
System.out.println(shortLink);
|
|
|
|
} catch (UriResolverMapException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 12:43:00 +02:00
|
|
|
/**
|
|
|
|
* Thread safe
|
|
|
|
*/
|
|
|
|
// @Test
|
|
|
|
public void test2(){
|
|
|
|
|
|
|
|
|
|
|
|
//create thread to print counter value
|
|
|
|
Thread t = new Thread(new Runnable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
|
|
|
|
ScopeProvider.instance.set("/gcube/devsec/devVRE");
|
|
|
|
UriResolverManager resolver;
|
|
|
|
resolver = new UriResolverManager("GIS");
|
|
|
|
|
|
|
|
Map<String, String> params = new HashMap<String, String>();
|
|
|
|
params.put("gis-UUID", "eb1a1b63-f324-47ee-9522-b8f5803e19ec");
|
|
|
|
params.put("scope", "/gcube/devsec/devVRE");
|
|
|
|
String shortLink = resolver.getLink(params, true);
|
|
|
|
System.out.println(shortLink); //true, link is shorted otherwise none
|
|
|
|
|
2014-10-23 14:26:47 +02:00
|
|
|
System.out.println("Thread "+Thread.currentThread().getId() +" reading counter is: " + resolver.countReaders());
|
2014-10-21 12:43:00 +02:00
|
|
|
Thread.sleep(1000);
|
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
ex.printStackTrace();
|
|
|
|
}catch (UriResolverMapException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
t.start();
|
|
|
|
|
|
|
|
try {
|
|
|
|
Thread.sleep(500000);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2014-10-20 11:24:56 +02:00
|
|
|
|
|
|
|
}
|