diff --git a/jopa-integration-tests-owlapi/src/test/java/cz/cvut/kbss/jopa/test/integration/owlapi/RetrieveOperationsTest.java b/jopa-integration-tests-owlapi/src/test/java/cz/cvut/kbss/jopa/test/integration/owlapi/RetrieveOperationsTest.java index 539820e7d..86e1d31d5 100644 --- a/jopa-integration-tests-owlapi/src/test/java/cz/cvut/kbss/jopa/test/integration/owlapi/RetrieveOperationsTest.java +++ b/jopa-integration-tests-owlapi/src/test/java/cz/cvut/kbss/jopa/test/integration/owlapi/RetrieveOperationsTest.java @@ -20,6 +20,8 @@ import cz.cvut.kbss.jopa.test.environment.OwlapiDataAccessor; import cz.cvut.kbss.jopa.test.environment.OwlapiPersistenceFactory; import cz.cvut.kbss.jopa.test.runner.RetrieveOperationsRunner; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -37,4 +39,25 @@ public RetrieveOperationsTest() { protected void addFileStorageProperties(Map properties) { // Do nothing } + + @Test + @Disabled + @Override + public void testRetrieveWithCollectionQueryAttribute() { + // disabled because OWL does not support SPARQL VALUES keyword + } + + @Test + @Disabled + @Override + public void testRetrieveWithSetQueryAttribute() { + // disabled because OWL does not support SPARQL VALUES keyword + } + + @Test + @Disabled + @Override + public void testRetrieveWithListQueryAttribute() { + // disabled because OWL does not support SPARQL VALUES keyword + } } diff --git a/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/OWLClassWithQueryAttr7.java b/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/OWLClassWithQueryAttr7.java new file mode 100644 index 000000000..8a85de444 --- /dev/null +++ b/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/OWLClassWithQueryAttr7.java @@ -0,0 +1,99 @@ +/* + * JOPA + * Copyright (C) 2024 Czech Technical University in Prague + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3.0 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package cz.cvut.kbss.jopa.test; + +import cz.cvut.kbss.jopa.model.annotations.Id; +import cz.cvut.kbss.jopa.model.annotations.OWLClass; +import cz.cvut.kbss.jopa.model.annotations.Sparql; + +import java.net.URI; +import java.util.Collection; +import java.util.List; +import java.util.Set; + +@OWLClass(iri = Vocabulary.C_OwlClassWithQueryAttr6) +public class OWLClassWithQueryAttr7 implements HasUri { + + private static final String QUERY = "SELECT ?x WHERE { VALUES (?x) {(99)(2)(99)}}"; + + @Id + private URI uri; + + @Sparql(query=QUERY) + private Collection collectionQueryAttribute; + + @Sparql(query=QUERY) + private Set setQueryAttribute; + + @Sparql(query=QUERY) + private List listQueryAttribute; + + public OWLClassWithQueryAttr7() { + } + + public OWLClassWithQueryAttr7(URI uri) { + this.uri = uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + @Override + public URI getUri() { + return uri; + } + + public Collection getCollectionQueryAttribute() { + return collectionQueryAttribute; + } + + public void setCollectionQueryAttribute(Collection collectionQueryAttribute) { + this.collectionQueryAttribute = collectionQueryAttribute; + } + + public Set getSetQueryAttribute() { + return setQueryAttribute; + } + + public void setSetQueryAttribute(Set setQueryAttribute) { + this.setQueryAttribute = setQueryAttribute; + } + + public List getListQueryAttribute() { + return listQueryAttribute; + } + + public void setListQueryAttribute(List listQueryAttribute) { + this.listQueryAttribute = listQueryAttribute; + } + + public static String getSparqlQuery() { + return QUERY; + } + + @Override + public String toString() { + return "OWLClassWithQueryAttr7{" + + "uri=" + uri + + ", collectionQueryAttribute=" + collectionQueryAttribute + + ", setQueryAttribute=" + setQueryAttribute + + ", listQueryAttribute=" + listQueryAttribute + + '}'; + } +} diff --git a/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/runner/BaseRunner.java b/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/runner/BaseRunner.java index 184907a86..e894b9aad 100644 --- a/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/runner/BaseRunner.java +++ b/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/runner/BaseRunner.java @@ -67,6 +67,7 @@ public abstract class BaseRunner { protected OWLClassWithQueryAttr4 entityWithQueryAttr4; protected OWLClassWithQueryAttr5 entityWithQueryAttr5; protected OWLClassWithQueryAttr6 entityWithQueryAttr6; + protected OWLClassWithQueryAttr7 entityWithQueryAttr7; protected final DataAccessor dataAccessor; protected final PersistenceFactory persistenceFactory; @@ -147,6 +148,8 @@ private void init() { entityWithQueryAttr5.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityWithQueryAttr5")); this.entityWithQueryAttr6 = new OWLClassWithQueryAttr6(); entityWithQueryAttr6.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityWithQueryAttr6")); + this.entityWithQueryAttr7 = new OWLClassWithQueryAttr7(); + entityWithQueryAttr7.setUri(URI.create("http://krizik.felk.cvut.cz/ontologies/jopa/tests/entityWithQueryAttr7")); } @AfterEach diff --git a/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/runner/RetrieveOperationsRunner.java b/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/runner/RetrieveOperationsRunner.java index 17af7de89..a45af1368 100644 --- a/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/runner/RetrieveOperationsRunner.java +++ b/jopa-integration-tests/src/main/java/cz/cvut/kbss/jopa/test/runner/RetrieveOperationsRunner.java @@ -36,6 +36,7 @@ import cz.cvut.kbss.jopa.test.OWLClassWithQueryAttr; import cz.cvut.kbss.jopa.test.OWLClassWithQueryAttr2; import cz.cvut.kbss.jopa.test.OWLClassWithQueryAttr6; +import cz.cvut.kbss.jopa.test.OWLClassWithQueryAttr7; import cz.cvut.kbss.jopa.test.OWLClassWithUrn; import cz.cvut.kbss.jopa.test.Thing; import cz.cvut.kbss.jopa.test.Vocabulary; @@ -61,6 +62,7 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; @@ -542,6 +544,45 @@ void testRetrieveWithLazyQueryAttribute() throws Exception { assertEquals(entityD.getUri(), res.getLazyQueryAttribute().getUri()); } + + @Test + public void testRetrieveWithCollectionQueryAttribute() { + this.em = getEntityManager("RetrieveWithPluralQueryAttribute", false); + + persist(entityWithQueryAttr7); + final OWLClassWithQueryAttr7 res = findRequired(OWLClassWithQueryAttr7.class, entityWithQueryAttr7.getUri()); + Collection result = res.getCollectionQueryAttribute(); + assertInstanceOf(List.class, result); + assertEquals(3, result.size()); + assertEquals(2, result.stream().filter(i -> i.equals(99)).count()); + } + + @Test + public void testRetrieveWithSetQueryAttribute() { + this.em = getEntityManager("RetrieveWithPluralQueryAttribute", false); + + persist(entityWithQueryAttr7); + final OWLClassWithQueryAttr7 res = findRequired(OWLClassWithQueryAttr7.class, entityWithQueryAttr7.getUri()); + Set result = res.getSetQueryAttribute(); + assertInstanceOf(Set.class, result); + assertEquals(2, result.size()); + assertTrue(result.containsAll(List.of(99, 2))); + } + + @Test + public void testRetrieveWithListQueryAttribute() { + this.em = getEntityManager("RetrieveWithPluralQueryAttribute", false); + + persist(entityWithQueryAttr7); + final OWLClassWithQueryAttr7 res = findRequired(OWLClassWithQueryAttr7.class, entityWithQueryAttr7.getUri()); + Collection result = res.getCollectionQueryAttribute(); + assertInstanceOf(List.class, result); + assertEquals(3, result.size()); + assertEquals(2, result.stream().filter(i -> i.equals(99)).count()); + } + + + @Test void testSupportForUrnIrisInClassAndProperty() { this.em = getEntityManager("testSupportForUrnIrisInClassAndProperty", false);