@Test void testInvalidInsertedContentRelation() { final List<IRI> found = models.stream() .filter(type -> svc.constrainedBy(identifier, type, asGraph("/hasInsertedContent.ttl", domain + "foo"), domain).findFirst().isPresent()) .collect(toList()); assertTrue(found.contains(LDP.Container), "ldp:Container not present!"); assertFalse(found.contains(LDP.DirectContainer), "ldp:DirectContainer not expected!"); assertFalse(found.contains(LDP.IndirectContainer), "ldp:IndirectContainer not expected!"); models.forEach(type -> { final String subject = domain + "foo"; final Optional<ConstraintViolation> res = svc.constrainedBy(identifier, type, asGraph("/hasInsertedContent.ttl", subject), domain).findFirst(); if (type.equals(LDP.IndirectContainer) || type.equals(LDP.DirectContainer)) { assertFalse(res.isPresent(), "constraint violation not expected for " + type); } else { assertTrue(res.isPresent(), "constraint violation not found for " + type); res.ifPresent(violation -> { assertEquals(Trellis.InvalidProperty, violation.getConstraint(), "no InvalidProperty violation!"); assertTrue(violation.getTriples().contains( rdf.createTriple(rdf.createIRI(subject), LDP.hasMemberRelation, DC.isPartOf)), "Triple missing from violation!"); }); } }); }
@Override public Stream<ConstraintViolation> constrainedBy(final IRI identifier, final IRI model, final Graph graph, final String domain) { final Stream<ConstraintViolation> violations = graph.stream() .flatMap(t -> violatesModelConstraints(t, model, domain).stream()); if (violatesCardinality(graph, model)) { final List<Triple> triples = new ArrayList<>(graph.stream().collect(toList())); final BlankNode bnode = rdf.createBlankNode(); triples.add(rdf.createTriple(bnode, RDFS.label, rdf.createLiteral("Invalid cardinality", EN))); triples.add(rdf.createTriple(bnode, RDFS.comment, rdf.createLiteral( "The supplied graph contains at least one property with an invalid cardinality " + "for the provided interaction model", EN))); final ConstraintViolation cardinalityViolation = new ConstraintViolation(Trellis.InvalidCardinality, triples); return concat(violations, Stream.of(cardinalityViolation)); } return violations; }
LdpConstraintService implements ConstraintService { @Override public Stream<ConstraintViolation> constrainedBy(final IRI identifier, final IRI model, final Graph graph, final String domain) { final Stream<ConstraintViolation> violations = graph.stream() .flatMap(t -> violatesModelConstraints(t, model, domain).stream()); if (violatesCardinality(graph, model)) { final List<Triple> triples = new ArrayList<>(graph.stream().collect(toList())); final BlankNode bnode = rdf.createBlankNode(); triples.add(rdf.createTriple(bnode, RDFS.label, rdf.createLiteral("Invalid cardinality", EN))); triples.add(rdf.createTriple(bnode, RDFS.comment, rdf.createLiteral( "The supplied graph contains at least one property with an invalid cardinality " + "for the provided interaction model", EN))); final ConstraintViolation cardinalityViolation = new ConstraintViolation(Trellis.InvalidCardinality, triples); return concat(violations, Stream.of(cardinalityViolation)); } return violations; } }
LdpConstraintService implements ConstraintService { @Override public Stream<ConstraintViolation> constrainedBy(final IRI identifier, final IRI model, final Graph graph, final String domain) { final Stream<ConstraintViolation> violations = graph.stream() .flatMap(t -> violatesModelConstraints(t, model, domain).stream()); if (violatesCardinality(graph, model)) { final List<Triple> triples = new ArrayList<>(graph.stream().collect(toList())); final BlankNode bnode = rdf.createBlankNode(); triples.add(rdf.createTriple(bnode, RDFS.label, rdf.createLiteral("Invalid cardinality", EN))); triples.add(rdf.createTriple(bnode, RDFS.comment, rdf.createLiteral( "The supplied graph contains at least one property with an invalid cardinality " + "for the provided interaction model", EN))); final ConstraintViolation cardinalityViolation = new ConstraintViolation(Trellis.InvalidCardinality, triples); return concat(violations, Stream.of(cardinalityViolation)); } return violations; }  }
LdpConstraintService implements ConstraintService { @Override public Stream<ConstraintViolation> constrainedBy(final IRI identifier, final IRI model, final Graph graph, final String domain) { final Stream<ConstraintViolation> violations = graph.stream() .flatMap(t -> violatesModelConstraints(t, model, domain).stream()); if (violatesCardinality(graph, model)) { final List<Triple> triples = new ArrayList<>(graph.stream().collect(toList())); final BlankNode bnode = rdf.createBlankNode(); triples.add(rdf.createTriple(bnode, RDFS.label, rdf.createLiteral("Invalid cardinality", EN))); triples.add(rdf.createTriple(bnode, RDFS.comment, rdf.createLiteral( "The supplied graph contains at least one property with an invalid cardinality " + "for the provided interaction model", EN))); final ConstraintViolation cardinalityViolation = new ConstraintViolation(Trellis.InvalidCardinality, triples); return concat(violations, Stream.of(cardinalityViolation)); } return violations; }  @Override Stream<ConstraintViolation> constrainedBy(final IRI identifier, final IRI model, final Graph graph,
            final String domain); }
LdpConstraintService implements ConstraintService { @Override public Stream<ConstraintViolation> constrainedBy(final IRI identifier, final IRI model, final Graph graph, final String domain) { final Stream<ConstraintViolation> violations = graph.stream() .flatMap(t -> violatesModelConstraints(t, model, domain).stream()); if (violatesCardinality(graph, model)) { final List<Triple> triples = new ArrayList<>(graph.stream().collect(toList())); final BlankNode bnode = rdf.createBlankNode(); triples.add(rdf.createTriple(bnode, RDFS.label, rdf.createLiteral("Invalid cardinality", EN))); triples.add(rdf.createTriple(bnode, RDFS.comment, rdf.createLiteral( "The supplied graph contains at least one property with an invalid cardinality " + "for the provided interaction model", EN))); final ConstraintViolation cardinalityViolation = new ConstraintViolation(Trellis.InvalidCardinality, triples); return concat(violations, Stream.of(cardinalityViolation)); } return violations; }  @Override Stream<ConstraintViolation> constrainedBy(final IRI identifier, final IRI model, final Graph graph,
            final String domain);  }