2016-06-07 16:00:05 +02:00
|
|
|
package org.gcube.datacatalogue.ckanutillibrary;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.models.CKanUserWrapper;
|
2016-06-14 17:05:24 +02:00
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.models.RolesIntoOrganization;
|
2016-06-07 16:00:05 +02:00
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import eu.trentorise.opendata.jackan.model.CkanOrganization;
|
|
|
|
|
|
|
|
public class TestCKanLib {
|
|
|
|
|
2016-06-08 18:31:25 +02:00
|
|
|
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(TestCKanLib.class);
|
2016-06-07 16:00:05 +02:00
|
|
|
|
|
|
|
CKanUtilsImpl instance;
|
|
|
|
|
2016-06-16 18:09:26 +02:00
|
|
|
//@Test
|
2016-06-07 16:00:05 +02:00
|
|
|
public void before() throws Exception{
|
|
|
|
|
|
|
|
instance = new CKanUtilsImpl("/gcube");
|
2016-06-16 18:09:26 +02:00
|
|
|
List<String> orgs = instance.getOrganizationsNamesByUser("costantino.perciante");
|
|
|
|
for (String string : orgs) {
|
|
|
|
System.out.println("org is " + string);
|
|
|
|
}
|
2016-06-07 16:00:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void testgetApiKeyFromUser() {
|
|
|
|
|
|
|
|
logger.debug("Testing getApiKeyFromUser");
|
|
|
|
|
|
|
|
String username = "francescomangiacrapa";
|
2016-06-16 18:09:26 +02:00
|
|
|
String key = instance.getApiKeyFromUsername(username);
|
2016-06-07 16:00:05 +02:00
|
|
|
|
|
|
|
System.out.println("key for " + username + " is " + key);
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void testgetUserFromApiKey() {
|
|
|
|
|
|
|
|
logger.debug("Testing getApiKeyFromUser");
|
|
|
|
|
|
|
|
String key = "put-your-key-here";
|
|
|
|
CKanUserWrapper user = instance.getUserFromApiKey(key);
|
|
|
|
|
|
|
|
System.out.println("user for " + key + " is " + user);
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getOrganizationsByUser() {
|
|
|
|
|
|
|
|
System.out.println("Testing getOrganizationsByUser");
|
|
|
|
|
|
|
|
String username = "francescomangiacrapa";
|
|
|
|
List<CkanOrganization> organizations = instance.getOrganizationsByUser(username);
|
|
|
|
|
|
|
|
System.out.println("organizations for user " + username + " are: ");
|
|
|
|
|
|
|
|
for (CkanOrganization ckanOrganization : organizations) {
|
|
|
|
System.out.println("-" + ckanOrganization.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void getGroupsAndRolesByUser() {
|
|
|
|
|
|
|
|
logger.debug("Testing getGroupsAndRolesByUser");
|
|
|
|
|
|
|
|
String username = "francescomangiacrapa";
|
2016-06-14 17:05:24 +02:00
|
|
|
List<RolesIntoOrganization> rolesToMatch = new ArrayList<RolesIntoOrganization>();
|
|
|
|
rolesToMatch.add(RolesIntoOrganization.ADMIN);
|
|
|
|
rolesToMatch.add(RolesIntoOrganization.MEMBER);
|
|
|
|
rolesToMatch.add(RolesIntoOrganization.EDITOR);
|
|
|
|
Map<String, List<RolesIntoOrganization>> map = instance.getGroupsAndRolesByUser(username, rolesToMatch);
|
2016-06-07 16:00:05 +02:00
|
|
|
|
|
|
|
System.out.println("organizations for user " + username + " are " + map);
|
|
|
|
}
|
2016-06-20 10:13:46 +02:00
|
|
|
|
|
|
|
//@Test
|
|
|
|
public void isRoleAlreadySet() throws Exception{
|
|
|
|
|
|
|
|
instance = new CKanUtilsImpl("/gcube");
|
|
|
|
boolean res = instance.isRoleAlreadySet("andrea_rossi", "devVRE".toLowerCase(), RolesIntoOrganization.EDITOR);
|
|
|
|
logger.debug("Res is " + res);
|
|
|
|
|
|
|
|
}
|
2016-06-07 16:00:05 +02:00
|
|
|
}
|