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"));
}
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);
}
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);
}
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);
}
Aggregations