Search in sources :

Example 21 with WonMessageValidator

use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testMissingAndInvalidMessageType.

@Test
@Ignore
public void testMissingAndInvalidMessageType() throws IOException {
    // create invalid dataset by removing a triple with message type
    Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(WonMessage.of(createMessageDataset)).getCompleteDataset();
    Model env1Model = invalidDataset.getNamedModel(CREATE_ENV_NAME);
    Statement stmtOld = env1Model.createStatement(ResourceFactory.createResource(CREATE_MSG_URI), WONMSG.messageType, WONMSG.CreateMessage);
    env1Model.remove(stmtOld);
    // validate this invalid dataset
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    boolean valid = validator.validate(invalidDataset, message);
    Assert.assertFalse(valid);
    Assert.assertTrue(message.toString().contains("missing_type"));
    // create invalid dataset by adding a triple with invalid message type
    Statement stmtNew = env1Model.createStatement(ResourceFactory.createResource(CREATE_MSG_URI), WONMSG.messageType, ResourceFactory.createProperty("test:property:uri"));
    env1Model.add(stmtNew);
    // validate this invalid dataset
    valid = validator.validate(invalidDataset, message);
    Assert.assertFalse(valid);
    Assert.assertTrue(message.toString().contains("invalid_type"));
}
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 22 with WonMessageValidator

use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testInvalidContentChain.

@Test
@Ignore
public void testInvalidContentChain() throws IOException {
    Dataset invalidDataset = WonRdfUtils.MessageUtils.copyByDatasetSerialization(WonMessage.of(createMessageDataset)).getCompleteDataset();
    Model env1Model = invalidDataset.getNamedModel(CREATE_ENV_NAME);
    // test 4
    // create invalid dataset by adding a triple that references a content from the
    // second envelope (additionally to
    // the first envelope)
    // validate this invalid dataset
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    boolean valid = validator.validate(invalidDataset, message);
    Assert.assertFalse(valid);
    Assert.assertTrue(message.toString().contains("validation/05_sign/signature_chain.rq"));
    Statement stmtOld = env1Model.createStatement(ResourceFactory.createResource(CREATE_MSG_URI), WONMSG.content, ResourceFactory.createResource(CREATE_CONTENT_NAME));
    env1Model.remove(stmtOld);
    // validate this invalid dataset
    valid = validator.validate(invalidDataset, message);
    Assert.assertFalse(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 23 with WonMessageValidator

use of won.protocol.validation.WonMessageValidator 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(WonMessage.of(textMessageDataset)).getCompleteDataset();
    Model envModel = invalidDataset.getNamedModel(TEXT_ENV3_NAME);
    String dummyName = TEXT_ENV3_NAME;
    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.assertFalse(valid);
    // actually
    Assert.assertTrue(message.toString().contains("number_of_events"));
// reset for further testing:
// env2sigModel.add(stmtOld);
// env2sigModel.remove(stmtNew);
}
Also used : Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 24 with WonMessageValidator

use of won.protocol.validation.WonMessageValidator in project webofneeds by researchstudio-sat.

the class WonMessageValidatorTest method testValidFailureResponseMessage.

@Test
@Ignore
public void testValidFailureResponseMessage() throws IOException {
    WonMessageValidator validator = new WonMessageValidator();
    StringBuilder message = new StringBuilder();
    boolean valid = validator.validate(Utils.createTestDataset("/validation/valid/failure_response_msg.trig"), message);
    Assert.assertTrue("validation is expected not to fail at " + message, valid);
}
Also used : WonMessageValidator(won.protocol.validation.WonMessageValidator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)24 WonMessageValidator (won.protocol.validation.WonMessageValidator)24 Ignore (org.junit.Ignore)18 Dataset (org.apache.jena.query.Dataset)15 Model (org.apache.jena.rdf.model.Model)15 Statement (org.apache.jena.rdf.model.Statement)14 StmtIterator (org.apache.jena.rdf.model.StmtIterator)5