Search in sources :

Example 1 with AseRoot

use of won.auth.model.AseRoot in project webofneeds by researchstudio-sat.

the class GrantedOperationsTest method testSet1.

@Test
public void testSet1() throws IOException {
    Shacl2JavaInstanceFactory factory = AuthUtils.instanceFactory();
    Shapes atomDataShapes = loadShapes(atomDataShapesDef);
    ModelBasedConnectionTargetCheckEvaluator targetAtomChecker = new ModelBasedConnectionTargetCheckEvaluator(atomDataShapes, "won.auth.test.model");
    ModelBasedAtomNodeChecker atomNodeChecker = new ModelBasedAtomNodeChecker(atomDataShapes, "won.auth.test.model");
    String folder = "set1";
    for (Resource socketGraphResource : getInputs(folder)) {
        String baseName = getTestBaseName(socketGraphResource.getFilename());
        Graph inputGraph = loadGraph(socketGraphResource);
        String testIdentifier = folder + "/" + baseName;
        logger.debug("running test {}", testIdentifier);
        validateTestData(atomDataShapes, inputGraph, true, testIdentifier);
        validateTestData(AuthUtils.shapes(), inputGraph, true, testIdentifier);
        Shacl2JavaInstanceFactory.Accessor ac = factory.accessor(inputGraph);
        targetAtomChecker.loadData(inputGraph);
        atomNodeChecker.loadData(inputGraph);
        Set<OperationRequest> operationRequestSet = ac.getInstancesOfType(OperationRequest.class);
        if (operationRequestSet.size() > 1) {
            Assert.fail("only one operationRequest allowed per file");
        }
        OperationRequest operationRequest = operationRequestSet.stream().findFirst().get();
        setValidTokenExpiryDate(operationRequest);
        WonAclEvaluatorTestFactory evaluatorFactory = new WonAclEvaluatorTestFactory(targetAtomChecker, atomNodeChecker, null);
        evaluatorFactory.load(inputGraph);
        WonAclEvaluator evaluator = evaluatorFactory.create(false);
        Optional<AseRoot> grantedOperations = evaluator.getGrants(operationRequest);
        Graph actualResult = RdfOutput.toGraph(grantedOperations.get(), false);
        actualResult = new Difference(actualResult, AuthUtils.shapes().getGraph());
        Graph expectedResult = loadGraph(new ClassPathResource("/won/grantedOps/" + folder + "/" + baseName + "-expected.ttl"));
        assertIsomorphicGraphs(expectedResult, actualResult, testIdentifier);
    }
}
Also used : ClassPathResource(org.springframework.core.io.ClassPathResource) Resource(org.springframework.core.io.Resource) OperationRequest(won.auth.model.OperationRequest) Difference(org.apache.jena.graph.compose.Difference) ClassPathResource(org.springframework.core.io.ClassPathResource) Graph(org.apache.jena.graph.Graph) Shapes(org.apache.jena.shacl.Shapes) AseRoot(won.auth.model.AseRoot) Shacl2JavaInstanceFactory(won.shacl2java.Shacl2JavaInstanceFactory) Test(org.junit.Test)

Aggregations

Graph (org.apache.jena.graph.Graph)1 Difference (org.apache.jena.graph.compose.Difference)1 Shapes (org.apache.jena.shacl.Shapes)1 Test (org.junit.Test)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 Resource (org.springframework.core.io.Resource)1 AseRoot (won.auth.model.AseRoot)1 OperationRequest (won.auth.model.OperationRequest)1 Shacl2JavaInstanceFactory (won.shacl2java.Shacl2JavaInstanceFactory)1