Skip to content

Commit

Permalink
[Bug #276] Add Integration Tests to check if Collection Sparql attrib…
Browse files Browse the repository at this point in the history
…utes are treated as Lists
  • Loading branch information
luxbe committed Nov 21, 2024
1 parent 3eaaac9 commit 4899f6f
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -37,4 +39,25 @@ public RetrieveOperationsTest() {
protected void addFileStorageProperties(Map<String, String> 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
}
}
Original file line number Diff line number Diff line change
@@ -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<Integer> collectionQueryAttribute;

@Sparql(query=QUERY)
private Set<Integer> setQueryAttribute;

@Sparql(query=QUERY)
private List<Integer> 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<Integer> getCollectionQueryAttribute() {
return collectionQueryAttribute;
}

public void setCollectionQueryAttribute(Collection<Integer> collectionQueryAttribute) {
this.collectionQueryAttribute = collectionQueryAttribute;
}

public Set<Integer> getSetQueryAttribute() {
return setQueryAttribute;
}

public void setSetQueryAttribute(Set<Integer> setQueryAttribute) {
this.setQueryAttribute = setQueryAttribute;
}

public List<Integer> getListQueryAttribute() {
return listQueryAttribute;
}

public void setListQueryAttribute(List<Integer> listQueryAttribute) {
this.listQueryAttribute = listQueryAttribute;
}

public static String getSparqlQuery() {
return QUERY;
}

@Override
public String toString() {
return "OWLClassWithQueryAttr7{" +
"uri=" + uri +
", collectionQueryAttribute=" + collectionQueryAttribute +
", setQueryAttribute=" + setQueryAttribute +
", listQueryAttribute=" + listQueryAttribute +
'}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Integer> 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<Integer> 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<Integer> 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);
Expand Down

0 comments on commit 4899f6f

Please sign in to comment.