Tests
This commit is contained in:
parent
b8cb4e86f0
commit
9ba3559a15
|
@ -2,15 +2,23 @@ package org.gcube.application.geoportal.clients;
|
|||
|
||||
import org.bson.Document;
|
||||
import org.gcube.application.cms.tests.TokenSetter;
|
||||
import org.gcube.application.geoportal.client.utils.Serialization;
|
||||
import org.gcube.application.geoportal.common.model.document.accounting.User;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.DataAccessPolicy;
|
||||
import org.gcube.application.geoportal.common.model.useCaseDescriptor.UseCaseDescriptor;
|
||||
import org.gcube.application.geoportal.common.rest.UseCaseDescriptorsI;
|
||||
import org.gcube.application.geoportal.common.utils.tests.GCubeTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.useCaseDescriptors;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
public class UCDTests{
|
||||
|
@ -26,6 +34,7 @@ public class UCDTests{
|
|||
|
||||
@Test
|
||||
public void query() throws Exception {
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
UseCaseDescriptorsI client =getClient();
|
||||
QueryRequest request = new QueryRequest();
|
||||
// All
|
||||
|
@ -40,6 +49,7 @@ public class UCDTests{
|
|||
|
||||
@Test
|
||||
public void getByIdAll() throws Exception {
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
UseCaseDescriptorsI client =getClient();
|
||||
|
||||
QueryRequest request = new QueryRequest();
|
||||
|
@ -57,8 +67,26 @@ public class UCDTests{
|
|||
|
||||
@Test
|
||||
public void getById() throws Exception {
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
UseCaseDescriptorsI client =getClient();
|
||||
|
||||
System.out.println(client.getById("profiledConcessioni"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkPolicies() throws Exception {
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
UseCaseDescriptorsI client =getClient();
|
||||
UseCaseDescriptor ucd = client.getById("profiledConcessioni");
|
||||
System.out.println(Serialization.write(ucd));
|
||||
User u = new User();
|
||||
u.setRoles(new HashSet<>());
|
||||
u.getRoles().addAll(Arrays.asList("Members","Data-Manager"));
|
||||
|
||||
DataAccessPolicy p = ucd.getMatching(u);
|
||||
System.out.println("Evaluated policy : "+Serialization.write(p));
|
||||
assertEquals(p.getPolicy().getRead(), DataAccessPolicy.Policy.Type.any);
|
||||
assertEquals(p.getPolicy().getWrite(), DataAccessPolicy.Policy.Type.any);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,6 +121,8 @@ public class UseCaseDescriptor implements Serializable {
|
|||
|
||||
@JsonIgnore
|
||||
public DataAccessPolicy getMatching(User u){
|
||||
// TODO Evaluate higher permits
|
||||
|
||||
DataAccessPolicy defaultPolicy = null;
|
||||
if(dataAccessPolicies!=null)
|
||||
for (DataAccessPolicy dataAccessPolicy : dataAccessPolicies) {
|
||||
|
|
|
@ -17,7 +17,7 @@ public class GCubeTest {
|
|||
|
||||
testContext = "/pred4s/preprod/preVRE";
|
||||
// testContext = "/d4science.research-infrastructures.eu/D4OS/GNA";
|
||||
// testContext= "/gcube/devsec/devVRE";
|
||||
// testContext= "/gcube/devsec/devVRE";
|
||||
|
||||
System.out.println("TEST CONTEXT = "+testContext);
|
||||
return testContext;
|
||||
|
|
|
@ -18,12 +18,16 @@
|
|||
]
|
||||
}
|
||||
},
|
||||
"_dataAccessPolicies" : [
|
||||
{"_policy" : {"_read" : "own", "_write" : "own"}, "_roles":[]},
|
||||
{"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Guest"],
|
||||
"_enforcer": {"_filter" : "{\"_lifecycleInformation._phase\" : {\"$eq\" : \"PUBLISHED\"}}"}},
|
||||
{"_policy" : {"_read" : "any", "_write" : "none"}, "_roles":["Editor"]},
|
||||
{"_policy" : {"_read" : "any", "_write" : "any"}, "_roles":["Admin"]}
|
||||
"_dataAccessPolicies": [
|
||||
{"_policy": {"_read": "any","_write": "any"},
|
||||
"_roles": ["Data-Manager"]},
|
||||
{"_policy": {"_read": "own","_write": "own"},
|
||||
"_roles": ["Data-Editor"]},
|
||||
{"_policy": {"_read": "any","_write": "none"},
|
||||
"_roles": ["Member"],
|
||||
"_enforcer": {"_filter": "{\"_lifecycleInformation._phase\" : {\"$eq\" : \"Published\"}}"}},
|
||||
{"_policy": {"_read": "none","_write": "none"},
|
||||
"_roles": []}
|
||||
],
|
||||
|
||||
"_relationshipDefinitions" : [
|
||||
|
|
|
@ -53,7 +53,7 @@ public class ExportConcessioniAsProjects {
|
|||
File dir= new File("/Users/fabioisti/git/gcube-cms-suite/import1669889538860");
|
||||
|
||||
// select only cluster
|
||||
// dir = new File(dir,"cluster_1");
|
||||
dir = new File(dir,"61d5ec7495184b186ad0c2e4");
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue