Fixed GRSF utility test
This commit is contained in:
parent
e3b3c67c42
commit
fbed0f57b8
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import org.gcube.com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
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;
|
||||||
|
@ -14,6 +15,7 @@ import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
|
||||||
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;
|
||||||
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -24,6 +26,25 @@ public class GRSFUtilities extends ContextTest {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(CKANGroupTest.class);
|
private static Logger logger = LoggerFactory.getLogger(CKANGroupTest.class);
|
||||||
|
|
||||||
|
public static final String PRODUCTION_GRSF = "/d4science.research-infrastructures.eu/FARM/GRSF";
|
||||||
|
public static final String PRODUCTION_GRSF_ADMIN = "/d4science.research-infrastructures.eu/FARM/GRSF_Admin";
|
||||||
|
public static final String PRODUCTION_GRSF_PRE = "/d4science.research-infrastructures.eu/FARM/GRSF_Pre";
|
||||||
|
|
||||||
|
public static final String PREPROD_GRSF_PRE = "/pred4s/preprod/GRSF_Pre";
|
||||||
|
|
||||||
|
public GRSFUtilities() throws ObjectNotFound, Exception {
|
||||||
|
ContextTest.setContextByName(PRODUCTION_GRSF_PRE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() throws ObjectNotFound, Exception {
|
||||||
|
// ContextTest.setContextByName(PREPROD_GRSF_PRE);
|
||||||
|
//
|
||||||
|
// ContextTest.setContextByName(PRODUCTION_GRSF);
|
||||||
|
// ContextTest.setContextByName(PRODUCTION_GRSF_ADMIN);
|
||||||
|
// ContextTest.setContextByName(PRODUCTION_GRSF_PRE);
|
||||||
|
}
|
||||||
|
|
||||||
private void create(Set<String> createdGroup, Map<String, String> groups, String name) throws JsonProcessingException, IOException {
|
private void create(Set<String> createdGroup, Map<String, String> groups, String name) throws JsonProcessingException, IOException {
|
||||||
if(createdGroup.contains(name)) {
|
if(createdGroup.contains(name)) {
|
||||||
return;
|
return;
|
||||||
|
@ -48,9 +69,6 @@ public class GRSFUtilities extends ContextTest {
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
public void createGRSFGroups() throws ObjectNotFound, Exception {
|
public void createGRSFGroups() throws ObjectNotFound, Exception {
|
||||||
// Set grsf.publisher user
|
|
||||||
ContextTest.setContext("");
|
|
||||||
|
|
||||||
String key = CKANUtility.getSysAdminAPI();
|
String key = CKANUtility.getSysAdminAPI();
|
||||||
List<String> groupNames = CKANGroupTest.listGroup();
|
List<String> groupNames = CKANGroupTest.listGroup();
|
||||||
Map<String, String> groups = new HashMap<>();
|
Map<String, String> groups = new HashMap<>();
|
||||||
|
@ -64,18 +82,13 @@ public class GRSFUtilities extends ContextTest {
|
||||||
|
|
||||||
Set<String> createdGroup = new HashSet<>();
|
Set<String> createdGroup = new HashSet<>();
|
||||||
|
|
||||||
// Setting GRSF_PRE token of grsf.publisher user to create groups
|
|
||||||
ContextTest.setContext("");
|
|
||||||
for(String name : groupNames) {
|
for(String name : groupNames) {
|
||||||
create(createdGroup, groups, name);
|
create(createdGroup, groups, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
public void associateUserToAllCKANGroups() throws ObjectNotFound, Exception {
|
public void associateUserToAllCKANGroups() throws ObjectNotFound, Exception {
|
||||||
// Set grsf.publisher user
|
|
||||||
ContextTest.setContext("");
|
|
||||||
String sysAdminAPI = CKANUtility.getSysAdminAPI();
|
String sysAdminAPI = CKANUtility.getSysAdminAPI();
|
||||||
List<String> groupNames = CKANGroupTest.listGroup();
|
List<String> groupNames = CKANGroupTest.listGroup();
|
||||||
for(String groupName : groupNames) {
|
for(String groupName : groupNames) {
|
||||||
|
@ -86,15 +99,13 @@ public class GRSFUtilities extends ContextTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
private void purgeGRSFRecords(int limit, int offset) throws Exception {
|
||||||
public void purgeAllGRSFRecords() throws Exception {
|
logger.debug("Going to purge {} records, starting from {}", limit, limit*offset);
|
||||||
ContextTest.setContextByName("/d4science.research-infrastructures.eu/FARM/GRSF_Pre");
|
|
||||||
logger.debug("Going to purge all records");
|
|
||||||
CKANPackage ckanPackage = new CKANPackage();
|
CKANPackage ckanPackage = new CKANPackage();
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
boolean go = true;
|
boolean go = true;
|
||||||
while(go) {
|
while(go) {
|
||||||
String ret = ckanPackage.list(10, 0);
|
String ret = ckanPackage.list(limit, offset);
|
||||||
JsonNode gotList = mapper.readTree(ret);
|
JsonNode gotList = mapper.readTree(ret);
|
||||||
Assert.assertTrue(gotList instanceof ArrayNode);
|
Assert.assertTrue(gotList instanceof ArrayNode);
|
||||||
ArrayNode itemsArray = (ArrayNode) gotList;
|
ArrayNode itemsArray = (ArrayNode) gotList;
|
||||||
|
@ -103,15 +114,26 @@ public class GRSFUtilities extends ContextTest {
|
||||||
String name = jsonNode.asText();
|
String name = jsonNode.asText();
|
||||||
logger.debug("Going to purge record with name {}", name);
|
logger.debug("Going to purge record with name {}", name);
|
||||||
ckanPackage.setName(name);
|
ckanPackage.setName(name);
|
||||||
// ckanPackage.delete(true);
|
try {
|
||||||
if(go) {
|
ckanPackage.purgeNoCheckNoDeleteFiles();
|
||||||
break;
|
if(go) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}catch (Exception e) {
|
||||||
|
// TODO: handle exception
|
||||||
}
|
}
|
||||||
Thread.sleep(500);
|
// Thread.sleep(500);
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
go=false;
|
go=false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
// @Test
|
||||||
|
public void purgeAllGRSFRecords() throws Exception {
|
||||||
|
purgeGRSFRecords(100, 0);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue