Added test
This commit is contained in:
parent
d12ed67446
commit
246a481533
|
@ -1,10 +1,17 @@
|
|||
package org.gcube.gcat.persistence.ckan;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.gcat.ContextTest;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
public class CKANGroupTest extends ContextTest {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(CKANGroupTest.class);
|
||||
|
@ -26,12 +33,42 @@ public class CKANGroupTest extends ContextTest {
|
|||
logger.debug("{}", ret);
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void delete() throws Exception {
|
||||
public static List<String> listGroup() throws Exception {
|
||||
List<String> groupList = new ArrayList<>();
|
||||
CKANGroup group = new CKANGroup();
|
||||
String groups = group.list(1000, 0);
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
JsonNode jsonNodeGroups = objectMapper.readTree(groups);
|
||||
Iterator<JsonNode> iterator = jsonNodeGroups.elements();
|
||||
while(iterator.hasNext()) {
|
||||
JsonNode jsonNode = iterator.next();
|
||||
groupList.add(jsonNode.asText());
|
||||
}
|
||||
return groupList;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createDeleteGroup() throws Exception {
|
||||
CKANGroup ckanGroup = new CKANGroup();
|
||||
ckanGroup.setApiKey(CKANUtility.getSysAdminAPI());
|
||||
String name = "";
|
||||
String name = "my-test-group";
|
||||
ckanGroup.setName(name);
|
||||
ckanGroup.create();
|
||||
|
||||
|
||||
ckanGroup.delete(true);
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void deleteAllGroups() throws Exception {
|
||||
//ContextTest.setContextByName("/d4science.research-infrastructures.eu/D4Research/AGINFRAplusDev");
|
||||
CKANGroup ckanGroup = new CKANGroup();
|
||||
ckanGroup.setApiKey(CKANUtility.getSysAdminAPI());
|
||||
List<String> groups = listGroup();
|
||||
for(String name : groups) {
|
||||
ckanGroup.setName(name);
|
||||
ckanGroup.delete(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue