93 lines
2.5 KiB
Java
93 lines
2.5 KiB
Java
package org.gcube.datacatalogue.ckanutillibrary;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsFactory;
|
|
import org.gcube.datacatalogue.ckanutillibrary.CKanUtilsImpl;
|
|
import org.gcube.datacatalogue.ckanutillibrary.models.CKanUserWrapper;
|
|
import org.gcube.datacatalogue.ckanutillibrary.models.ROLES_IN_ORGANIZATION;
|
|
import org.junit.Test;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import eu.trentorise.opendata.jackan.model.CkanOrganization;
|
|
|
|
public class TestCKanLib {
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(TestCKanLib.class);
|
|
|
|
CKanUtilsImpl instance;
|
|
|
|
//@Before
|
|
public void before() throws Exception{
|
|
|
|
instance = new CKanUtilsImpl("/gcube");
|
|
|
|
}
|
|
|
|
//@Test
|
|
public void testgetApiKeyFromUser() {
|
|
|
|
logger.debug("Testing getApiKeyFromUser");
|
|
|
|
String username = "francescomangiacrapa";
|
|
String key = instance.getApiKeyFromUser(username);
|
|
|
|
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";
|
|
List<ROLES_IN_ORGANIZATION> rolesToMatch = new ArrayList<ROLES_IN_ORGANIZATION>();
|
|
rolesToMatch.add(ROLES_IN_ORGANIZATION.admin);
|
|
rolesToMatch.add(ROLES_IN_ORGANIZATION.member);
|
|
rolesToMatch.add(ROLES_IN_ORGANIZATION.editor);
|
|
Map<String, List<ROLES_IN_ORGANIZATION>> map = instance.getGroupsAndRolesByUser(username, rolesToMatch);
|
|
|
|
System.out.println("organizations for user " + username + " are " + map);
|
|
}
|
|
|
|
//@Test
|
|
public void testFactory() throws Exception{
|
|
|
|
System.out.println("Creating factory object");
|
|
CKanUtilsImpl obj = CKanUtilsFactory.getInstance().getCkanUtilsForScope("/gcube");
|
|
System.out.println("Object created " + obj.getCatalogueUrl());
|
|
|
|
|
|
}
|
|
|
|
}
|