Search in sources :

Example 61 with Statement

use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testInvalidContentChain.

@Test
@Ignore
public void testInvalidContentChain() throws IOException {
    Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
    Model env1Model = invalidDataset.getNamedModel(CREATE_ENV1_NAME);
    Model env2Model = invalidDataset.getNamedModel(CREATE_ENV2_NAME);
    // test 4
    // create invalid dataset by adding a triple that references a content from the second envelope (additionally to
    // the first envelope)
    Statement stmtNew = env2Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_ENV2_MSG_URI), WONMSG.HAS_CONTENT_PROPERTY, ResourceFactory.createResource(CREATE_CONTENT_NAME));
    env2Model.add(stmtNew);
    // validate this invalid dataset
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    boolean valid = validator.validate(invalidDataset, message);
    Assert.assertTrue("validation is expected to fail", !valid);
    Assert.assertTrue(message.toString().contains("validation/05_sign/signature_chain.rq"));
    // reset for further testing
    env2Model.remove(stmtNew);
    // TODO test 5
    // create invalid dataset by removing a reference to the content from the envelope
    Statement stmtOld = env1Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_ENV2_MSG_URI), WONMSG.HAS_CONTENT_PROPERTY, ResourceFactory.createResource(CREATE_CONTENT_NAME));
    env1Model.remove(stmtOld);
    // validate this invalid dataset
    valid = validator.validate(invalidDataset, message);
    Assert.assertTrue("validation is expected to fail", !valid);
    Assert.assertTrue(message.toString().contains("validation/05_sign/signature_chain.rq"));
    // reset for further testing
    env1Model.add(stmtOld);
}
Also used : Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 62 with Statement

use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testSignatureChainParallelToEnvelopeChain.

@Test
@Ignore
public void testSignatureChainParallelToEnvelopeChain() throws IOException {
    // create a dataset where the first envelope references the signature of the second envelope instead of content's
    // and the 2nd references the signature of the content
    Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
    Model env1Model = invalidDataset.getNamedModel(CREATE_ENV1_NAME);
    StmtIterator iter = env1Model.listStatements(null, WONMSG.HAS_SIGNATURE_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
    Statement stmtOld = iter.removeNext();
    iter = env1Model.listStatements(null, WONMSG.HAS_SIGNED_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
    Statement stmtOld2 = iter.removeNext();
    Statement stmtNew = stmtOld.changeObject(ResourceFactory.createResource(CREATE_ENV1_SIG_NAME));
    env1Model.add(stmtNew);
    Statement stmtNew2 = stmtOld2.changeObject(ResourceFactory.createResource(CREATE_ENV1_NAME));
    env1Model.add(stmtNew2);
    Model env2Model = invalidDataset.getNamedModel(CREATE_ENV2_NAME);
    iter = env2Model.listStatements(null, WONMSG.HAS_SIGNATURE_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
    Statement stmtOld3 = iter.removeNext();
    iter = env2Model.listStatements(null, WONMSG.HAS_SIGNED_GRAPH_PROPERTY, RdfUtils.EMPTY_RDF_NODE);
    Statement stmtOld4 = iter.removeNext();
    Statement stmtNew3 = stmtOld3.changeObject(ResourceFactory.createResource(CREATE_CONTENT_NAME_SIG));
    env2Model.add(stmtNew3);
    Statement stmtNew4 = stmtOld4.changeObject(ResourceFactory.createResource(CREATE_CONTENT_NAME));
    env2Model.add(stmtNew4);
    // String test = RdfUtils.writeDatasetToString(invalidDataset, Lang.TRIG);
    // System.out.println("OUT:\n" + test);
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    // validate this invalid dataset
    boolean valid = validator.validate(invalidDataset, message);
    Assert.assertTrue("validation is expected to fail", !valid);
    // actually
    Assert.assertTrue(message.toString().contains("signature_chain"));
    // reset for further testing:
    env1Model.add(stmtOld);
    env1Model.remove(stmtNew);
    env1Model.add(stmtOld2);
    env1Model.remove(stmtNew2);
    env2Model.add(stmtOld3);
    env2Model.remove(stmtNew3);
    env2Model.add(stmtOld4);
    env2Model.remove(stmtNew4);
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 63 with Statement

use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testInvalidEnvelopeChain.

@Test
@Ignore
public void testInvalidEnvelopeChain() throws IOException {
    // test 1
    // create invalid dataset by removing a triple that references envelope 1 from envelope 2
    Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
    Model env2Model = invalidDataset.getNamedModel(CREATE_ENV2_NAME);
    Model env1Model = invalidDataset.getNamedModel(CREATE_ENV1_NAME);
    Statement stmtOld = env2Model.createStatement(ResourceFactory.createResource(CREATE_ENV2_NAME), WONMSG.CONTAINS_ENVELOPE, ResourceFactory.createResource(CREATE_ENV1_NAME));
    env2Model.remove(stmtOld);
    // validate this invalid dataset
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    boolean valid = validator.validate(invalidDataset, message);
    Assert.assertTrue("validation is expected to fail", !valid);
    Assert.assertTrue(message.toString().contains("validation/05_sign/invalid_from_owner_signer.rq"));
    // reset for further testing
    env2Model.add(stmtOld);
    // test 2
    // create invalid dataset by adding a triple that references envelope 2 from envelope 1,
    // thus creating a cycle in the envelope chain
    Statement stmtNew = env1Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_NAME), WONMSG.CONTAINS_ENVELOPE, ResourceFactory.createResource(CREATE_ENV2_NAME));
    env1Model.add(stmtNew);
    // validate this invalid dataset
    valid = validator.validate(invalidDataset, message);
    Assert.assertTrue("validation is expected to fail", !valid);
    Assert.assertTrue(message.toString().contains("validation/05_sign/invalid_from_owner_signer.rq"));
    // reset for further testing
    env1Model.remove(stmtNew);
    // test 3
    // create invalid dataset by adding a triple that references an envelope that is not present in the dataset
    stmtNew = env1Model.createStatement(ResourceFactory.createResource(CREATE_ENV1_NAME), WONMSG.CONTAINS_ENVELOPE, ResourceFactory.createResource("test:resource:uri"));
    env1Model.add(stmtNew);
    // validate this invalid dataset
    valid = validator.validate(invalidDataset, message);
    Assert.assertTrue("validation is expected to fail", !valid);
    Assert.assertTrue(message.toString().contains("validation/05_sign/invalid_from_owner_signer.rq"));
    // reset for further testing
    env1Model.remove(stmtNew);
}
Also used : Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 64 with Statement

use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testEventConsistency.

@Test
@Ignore
public void testEventConsistency() throws IOException {
    // create a dataset with invalid remoteEvent uri by replacing the original remote event uri
    // with the dummy uri
    Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(textMessageDataset)).getCompleteDataset();
    Model envModel = invalidDataset.getNamedModel(TEXT_ENV3_NAME);
    String dummyName = TEXT_ENV3_NAME;
    StmtIterator iter = envModel.listStatements(null, WONMSG.HAS_CORRESPONDING_REMOTE_MESSAGE, RdfUtils.EMPTY_RDF_NODE);
    Statement stmtOld = iter.removeNext();
    Statement stmtNew = envModel.createStatement(stmtOld.getSubject(), stmtOld.getPredicate(), ResourceFactory.createResource(dummyName));
    envModel.add(stmtNew);
    String test = RdfUtils.writeDatasetToString(invalidDataset, Lang.TRIG);
    System.out.println("OUT:\n" + test);
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    // validate this invalid dataset
    boolean valid = validator.validate(invalidDataset, message);
    Assert.assertTrue("validation is expected to fail", !valid);
    // actually
    Assert.assertTrue(message.toString().contains("number_of_events"));
// reset for further testing:
// env2sigModel.add(stmtOld);
// env2sigModel.remove(stmtNew);
}
Also used : StmtIterator(org.apache.jena.rdf.model.StmtIterator) Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 65 with Statement

use of org.apache.jena.rdf.model.Statement in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testInvalidDefaultGraph.

@Test
public void testInvalidDefaultGraph() throws IOException {
    // create invalid dataset by adding a triple into the default graph
    Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(new WonMessage(createMessageDataset)).getCompleteDataset();
    Model defaultModel = invalidDataset.getDefaultModel();
    Statement stmt = defaultModel.createStatement(ResourceFactory.createResource(), ResourceFactory.createProperty("test:property:uri"), ResourceFactory.createPlainLiteral("test literal"));
    defaultModel.add(stmt);
    // validate this invalid dataset
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    boolean valid = validator.validate(invalidDataset, message);
    Assert.assertTrue("validation is expected to fail", !valid);
    Assert.assertTrue(message.toString().contains("invalid_default_graph"));
}
Also used : Dataset(org.apache.jena.query.Dataset) Statement(org.apache.jena.rdf.model.Statement) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Test(org.junit.Test)

Aggregations

Statement (org.apache.jena.rdf.model.Statement)72 Model (org.apache.jena.rdf.model.Model)43 StmtIterator (org.apache.jena.rdf.model.StmtIterator)28 Test (org.junit.Test)25 Dataset (org.apache.jena.query.Dataset)24 Resource (org.apache.jena.rdf.model.Resource)19 WonMessageValidator (won.protocol.validation.WonMessageValidator)15 Property (org.apache.jena.rdf.model.Property)13 RDFNode (org.apache.jena.rdf.model.RDFNode)13 ArrayList (java.util.ArrayList)11 Ignore (org.junit.Ignore)11 Triple (org.apache.jena.graph.Triple)7 BaseTest (org.apache.jena.atlas.junit.BaseTest)6 Iterator (java.util.Iterator)4 RdfUtils (won.protocol.util.RdfUtils)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 OntModel (org.apache.jena.ontology.OntModel)2 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)2 GraphCollection (de.uni_koblenz.aggrimm.icp.crypto.sign.graph.GraphCollection)1