Added GRSF tests
This commit is contained in:
parent
35feb32c93
commit
e10dbc9c4a
|
@ -12,6 +12,7 @@ import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
|
import org.gcube.com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.gcube.gcat.ContextTest;
|
import org.gcube.gcat.ContextTest;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
@ -33,12 +34,12 @@ public class GRSFUtilities extends ContextTest {
|
||||||
public static final String PREPROD_GRSF_PRE = "/pred4s/preprod/GRSF_Pre";
|
public static final String PREPROD_GRSF_PRE = "/pred4s/preprod/GRSF_Pre";
|
||||||
|
|
||||||
public GRSFUtilities() throws ObjectNotFound, Exception {
|
public GRSFUtilities() throws ObjectNotFound, Exception {
|
||||||
ContextTest.setContextByName(PRODUCTION_GRSF_PRE);
|
ContextTest.setContextByName(PREPROD_GRSF_PRE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws ObjectNotFound, Exception {
|
public void test() throws ObjectNotFound, Exception {
|
||||||
// ContextTest.setContextByName(PREPROD_GRSF_PRE);
|
ContextTest.setContextByName(PREPROD_GRSF_PRE);
|
||||||
//
|
//
|
||||||
// ContextTest.setContextByName(PRODUCTION_GRSF);
|
// ContextTest.setContextByName(PRODUCTION_GRSF);
|
||||||
// ContextTest.setContextByName(PRODUCTION_GRSF_ADMIN);
|
// ContextTest.setContextByName(PRODUCTION_GRSF_ADMIN);
|
||||||
|
@ -87,6 +88,50 @@ public class GRSFUtilities extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getGroupNameOnCkan(String origName){
|
||||||
|
|
||||||
|
if(origName == null)
|
||||||
|
throw new IllegalArgumentException("origName cannot be null");
|
||||||
|
|
||||||
|
String modified = origName.replaceAll("\\(", "");
|
||||||
|
modified = origName.replaceAll("\\)", "");
|
||||||
|
modified = origName.trim().toLowerCase().replaceAll("[^A-Za-z0-9-]", "-");
|
||||||
|
if(modified.startsWith("-"))
|
||||||
|
modified = modified.substring(1);
|
||||||
|
if(modified.endsWith("-"))
|
||||||
|
modified = modified.substring(0, modified.length() -1);
|
||||||
|
|
||||||
|
logger.info("Group name generated is " + modified);
|
||||||
|
|
||||||
|
return modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test
|
||||||
|
public void createNewGRSFGroups() throws ObjectNotFound, Exception {
|
||||||
|
String sysAdminAPI = CKANUtility.getSysAdminAPI();
|
||||||
|
String[] groupNames = new String[] {
|
||||||
|
"GRSF", "Legacy", "Fishery", "Stock", "FIRMS", "FishSource", "RAM",
|
||||||
|
"Catch", "Landing",
|
||||||
|
"Abundance Level", "Abundance Level (FIRMS Standard)", "Biomass",
|
||||||
|
"Fishing Pressure", "Fishing Pressure (FIRMS Standard)", "State and Trend",
|
||||||
|
"FAO Stock Status Category", "Scientific Advice",
|
||||||
|
"GRSF SDG Flag", "GRSF Traceability Flag"
|
||||||
|
};
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
for(String name : groupNames) {
|
||||||
|
CKANGroup ckanGroupToCreate = new CKANGroup();
|
||||||
|
ckanGroupToCreate.setApiKey(sysAdminAPI);
|
||||||
|
ckanGroupToCreate.setName(name);
|
||||||
|
ObjectNode node = objectMapper.createObjectNode();
|
||||||
|
node.put("display_name", name);
|
||||||
|
node.put("title", name);
|
||||||
|
node.put("name", getGroupNameOnCkan(name));
|
||||||
|
String json = objectMapper.writeValueAsString(node);
|
||||||
|
logger.info(json);
|
||||||
|
ckanGroupToCreate.create(json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
public void associateUserToAllCKANGroups() throws ObjectNotFound, Exception {
|
public void associateUserToAllCKANGroups() throws ObjectNotFound, Exception {
|
||||||
String sysAdminAPI = CKANUtility.getSysAdminAPI();
|
String sysAdminAPI = CKANUtility.getSysAdminAPI();
|
||||||
|
|
Loading…
Reference in New Issue