AxiomLoader { Collection<Axiom<?>> loadAxioms(AxiomDescriptor axiomDescriptor) throws SesameDriverException { return findStatements(axiomDescriptor); } AxiomLoader(Connector connector, ValueFactory valueFactory, RuntimeConfiguration config);   }
@Test void loadsAllAxiomsWhenUnspecifiedPropertyIsUsedInDescriptor() throws Exception { connector.begin(); final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); final AxiomDescriptor desc = new AxiomDescriptor(NamedResource.create(individual)); desc.addAssertion(Assertion.createUnspecifiedPropertyAssertion(false)); generatedData.values.get(individual).keySet().stream().filter(a -> Generator.randomBoolean()) .forEach(desc::addAssertion); final Collection<Axiom<?>> res = axiomLoader.loadAxioms(desc); assertEquals(generatedData.getTotalValueCount(individual), res.size()); }
@Test void loadAxiomsSearchesInContextWhenItIsSpecifiedForAssertion() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); final Assertion property = generatedData.values.get(individual).keySet().iterator().next(); final String context = "http: final Object value = saveValueIntoContext(individual, property, context); final AxiomDescriptor desc = new AxiomDescriptor(NamedResource.create(individual)); desc.addAssertion(property); desc.setAssertionContext(property, URI.create(context)); connector.begin(); final Collection<Axiom<?>> res = axiomLoader.loadAxioms(desc); assertEquals(1, res.size()); final Axiom<?> a = res.iterator().next(); assertEquals(property, a.getAssertion()); assertEquals(value.toString(), a.getValue().getValue().toString()); }
@Test void loadAxiomsLoadsValuesFromContextAndNotFromDefaultWhenContextIsSpecifiedForAssertion() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); final Assertion property = generatedData.values.get(individual).keySet().iterator().next(); final String context = "http: final Object value = saveValueIntoContext(individual, property, context); final AxiomDescriptor desc = new AxiomDescriptor(NamedResource.create(individual)); desc.addAssertion(property); desc.setAssertionContext(property, URI.create(context)); final Set<Assertion> assertions = generatedData.values.get(individual).keySet(); assertions.stream().filter(a -> !a.equals(property)).forEach(desc::addAssertion); connector.begin(); final Collection<Axiom<?>> res = axiomLoader.loadAxioms(desc); int valueCount = 1; for (Assertion a : desc.getAssertions()) { if (!a.equals(property)) { valueCount += generatedData.values.get(individual).get(a).size(); } } assertEquals(valueCount, res.size()); for (Axiom<?> a : res) { assertTrue(assertions.contains(a.getAssertion())); if (a.getAssertion().equals(property)) { assertEquals(value, a.getValue().getValue()); } } }
@Test void loadAxiomsCombinesUnspecifiedPropertyInDefaultWithPropertyInContext() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); final Assertion property = generatedData.values.get(individual).keySet().iterator().next(); final String context = "http: Object value = saveValueIntoContext(individual, property, context); final AxiomDescriptor desc = new AxiomDescriptor(NamedResource.create(individual)); desc.addAssertion(property); desc.setAssertionContext(property, URI.create(context)); final Assertion unspecified = Assertion.createUnspecifiedPropertyAssertion(false); desc.addAssertion(unspecified); connector.begin(); final Collection<Axiom<?>> res = axiomLoader.loadAxioms(desc); assertEquals(generatedData.getTotalValueCount(individual) + 1, res.size()); final Optional<Axiom<?>> found = res.stream().filter(a -> a.getAssertion().equals(property) && a.getValue().getValue().equals(value)).findFirst(); assertTrue(found.isPresent()); }
@Test void loadAxiomsCombinesPropertiesInDefaultAndUnspecifiedPropertyInContext() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); final Assertion property = generatedData.values.get(individual).keySet().iterator().next(); final Assertion propertyInCtx = Assertion .createDataPropertyAssertion(URI.create("http: final String context = "http: int ctxCount = Generator.randomPositiveInt(10); final Set<Object> contextValues = new HashSet<>(); for (int i = 0; i < ctxCount; i++) { contextValues.add(saveValueIntoContext(individual, propertyInCtx, context)); } final AxiomDescriptor desc = new AxiomDescriptor(NamedResource.create(individual)); desc.addAssertion(property); desc.addAssertion(Assertion.createUnspecifiedPropertyAssertion(false)); desc.setAssertionContext(Assertion.createUnspecifiedPropertyAssertion(false), URI.create(context)); connector.begin(); final Collection<Axiom<?>> res = axiomLoader.loadAxioms(desc); assertEquals(contextValues.size() + generatedData.values.get(individual).get(property).size(), res.size()); for (Axiom<?> ax : res) { if (ax.getAssertion().equals(property)) { assertTrue(generatedData.values.get(individual).get(property).contains(ax.getValue().getValue())); } else { assertEquals(propertyInCtx.getIdentifier(), ax.getAssertion().getIdentifier()); assertEquals(propertyInCtx.isInferred(), ax.getAssertion().isInferred()); assertTrue(contextValues.contains(ax.getValue().getValue())); } } }
@Test void loadAxiomsSkipsPropertyValueOfInvalidType_OP() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); final Assertion a = Assertion .createObjectPropertyAssertion(URI.create("http: final RepositoryConnection conn = connector.unwrap(Repository.class).getConnection(); conn.begin(); conn.add(vf.createIRI(individual), vf.createIRI(a.getIdentifier().toString()), vf.createLiteral(false)); conn.commit(); conn.close(); connector.begin(); final AxiomDescriptor descOne = new AxiomDescriptor(NamedResource.create(individual)); descOne.addAssertion(a); assertTrue(axiomLoader.loadAxioms(descOne).isEmpty()); final AxiomDescriptor descTwo = new AxiomDescriptor(NamedResource.create(individual)); descTwo.addAssertion(Assertion.createDataPropertyAssertion(a.getIdentifier(), false)); assertFalse(axiomLoader.loadAxioms(descTwo).isEmpty()); }
@Test void loadAxiomsSkipsPropertyValueOfInvalidType_DP() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); final Assertion a = Assertion .createDataPropertyAssertion(URI.create("http: final RepositoryConnection conn = connector.unwrap(Repository.class).getConnection(); conn.begin(); conn.add(vf.createIRI(individual), vf.createIRI(a.getIdentifier().toString()), vf.createIRI("http: conn.commit(); conn.close(); connector.begin(); final AxiomDescriptor descOne = new AxiomDescriptor(NamedResource.create(individual)); descOne.addAssertion(a); assertTrue(axiomLoader.loadAxioms(descOne).isEmpty()); final AxiomDescriptor descTwo = new AxiomDescriptor(NamedResource.create(individual)); descTwo.addAssertion(Assertion.createObjectPropertyAssertion(a.getIdentifier(), false)); assertFalse(axiomLoader.loadAxioms(descTwo).isEmpty()); }
@Test void loadAxiomsLoadsStringLiteralWithCorrectLanguage() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); persistLanguageTaggedStrings(individual); connector.begin(); final AxiomDescriptor descriptor = new AxiomDescriptor(NamedResource.create(individual)); descriptor .addAssertion( Assertion.createAnnotationPropertyAssertion(URI.create(RDFS.LABEL.stringValue()), "en", false)); final Collection<Axiom<?>> axioms = axiomLoader.loadAxioms(descriptor); assertEquals(1, axioms.size()); final Axiom<?> ax = axioms.iterator().next(); final LangString value = (LangString) ax.getValue().getValue(); assertEquals("a", value.getValue()); }
@Test void loadAxiomsLoadsStringLiteralWithCorrectLanguageForUnspecifiedPropertyType() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); persistLanguageTaggedStrings(individual); connector.begin(); final AxiomDescriptor descriptor = new AxiomDescriptor(NamedResource.create(individual)); descriptor.addAssertion(Assertion.createPropertyAssertion(URI.create(RDFS.LABEL.stringValue()), "en", false)); final Collection<Axiom<?>> axioms = axiomLoader.loadAxioms(descriptor); assertEquals(1, axioms.size()); final Axiom<?> ax = axioms.iterator().next(); final LangString value = (LangString) ax.getValue().getValue(); assertEquals("a", value.getValue()); }
@Test void loadsStringLiteralWithCorrectLanguageTagWhenItIsSpecifiedInAssertion() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); persistLanguageTaggedStrings(individual); connector.begin(); final AxiomDescriptor descriptor = new AxiomDescriptor(NamedResource.create(individual)); final Assertion assertion = Assertion.createDataPropertyAssertion(URI.create(RDFS.LABEL.stringValue()), "cs", false); descriptor.addAssertion(assertion); final Collection<Axiom<?>> axioms = axiomLoader.loadAxioms(descriptor); assertEquals(1, axioms.size()); final Axiom<?> ax = axioms.iterator().next(); final LangString value = (LangString) ax.getValue().getValue(); assertEquals("b", value.getValue()); }
@Test void loadsStringLiteralWithCorrectLanguageTagWhenItIsSpecifiedInAssertionOfUnspecifiedProperty() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); persistLanguageTaggedStrings(individual); connector.begin(); final AxiomDescriptor descriptor = new AxiomDescriptor(NamedResource.create(individual)); final Assertion assertion = Assertion.createPropertyAssertion(URI.create(RDFS.LABEL.stringValue()), "cs", false); descriptor.addAssertion(assertion); final Collection<Axiom<?>> axioms = axiomLoader.loadAxioms(descriptor); assertEquals(1, axioms.size()); final Axiom<?> ax = axioms.iterator().next(); final LangString value = (LangString) ax.getValue().getValue(); assertEquals("b", value.getValue()); }
@Test void loadsStringLiteralWithAllLanguagesWhenLanguageTagIsExplicitlySetToNull() throws Exception { final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); persistLanguageTaggedStrings(individual); connector.begin(); final AxiomDescriptor descriptor = new AxiomDescriptor(NamedResource.create(individual)); final Assertion assertion = Assertion.createDataPropertyAssertion(URI.create(RDFS.LABEL.stringValue()), null, false); descriptor.addAssertion(assertion); final Collection<Axiom<?>> axioms = axiomLoader.loadAxioms(descriptor); assertEquals(2, axioms.size()); final Set<String> values = axioms.stream().map(ax -> ax.getValue().stringValue()).collect(Collectors.toSet()); assertTrue(values.contains(new LangString("a", "en").toString())); assertTrue(values.contains(new LangString("b", "cs").toString())); }
@Test void loadAxiomsForSingleAssertionFindsMatchingValues() throws Exception { connector.begin(); final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); final Assertion property = generatedData.values.get(individual).keySet().iterator().next(); final Set<Object> values = generatedData.values.get(individual).get(property); final AxiomDescriptor desc = new AxiomDescriptor(NamedResource.create(individual)); desc.addAssertion(property); final Collection<Axiom<?>> res = axiomLoader.loadAxioms(desc); assertEquals(values.size(), res.size()); for (Axiom<?> a : res) { assertEquals(individual, a.getSubject().toString()); assertEquals(property, a.getAssertion()); assertTrue(values.contains(a.getValue().getValue())); } }
@Test void loadAxiomsReturnsEmptyCollectionForUnknownIndividual() throws Exception { connector.begin(); final String individual = "http: final AxiomDescriptor desc = new AxiomDescriptor(NamedResource.create(individual)); desc.addAssertion(Assertion.createClassAssertion(false)); assertTrue(axiomLoader.loadAxioms(desc).isEmpty()); }
@Test void loadAxiomsLoadsAxiomsBasedOnSpecifiedAssertions() throws Exception { connector.begin(); final String individual = generatedData.individuals.get(Generator.randomIndex(generatedData.individuals)); final AxiomDescriptor desc = new AxiomDescriptor(NamedResource.create(individual)); generatedData.values.get(individual).keySet().forEach(desc::addAssertion); final Collection<Axiom<?>> res = axiomLoader.loadAxioms(desc); assertEquals(generatedData.getTotalValueCount(individual), res.size()); }
@Test void loadAxiomsSkipsValuesOfNonSelectedAssertions() throws Exception { connector.begin(); final String individual = selectIndividualWithEnoughProperties(); final AxiomDescriptor desc = new AxiomDescriptor(NamedResource.create(individual)); final Set<Assertion> skippedAssertions = new HashSet<>(); int counter = 0; for (Assertion a : generatedData.values.get(individual).keySet()) { if (counter < Constants.DEFAULT_LOAD_ALL_THRESHOLD) { desc.addAssertion(a); } else { skippedAssertions.add(a); } counter++; } final Collection<Axiom<?>> res = axiomLoader.loadAxioms(desc); res.forEach(a -> assertFalse(skippedAssertions.contains(a.getAssertion()))); }