-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...4j-spring/src/test/java/org/eclipse/rdf4j/spring/dao/support/RelationMapBuilderTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 Eclipse RDF4J contributors. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Distribution License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/org/documents/edl-v10.php. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*******************************************************************************/ | ||
package org.eclipse.rdf4j.spring.dao.support; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.eclipse.rdf4j.model.vocabulary.SKOS; | ||
import org.eclipse.rdf4j.spring.RDF4JSpringTestBase; | ||
import org.eclipse.rdf4j.spring.dao.support.RelationMapBuilder; | ||
import org.eclipse.rdf4j.spring.domain.model.EX; | ||
import org.eclipse.rdf4j.spring.support.RDF4JTemplate; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class RelationMapBuilderTests extends RDF4JSpringTestBase { | ||
|
||
@Autowired | ||
RDF4JTemplate rdf4JTemplate; | ||
|
||
@Test | ||
public void testRelationOnly() { | ||
RelationMapBuilder rmb = new RelationMapBuilder(this.rdf4JTemplate, SKOS.BROADER); | ||
assertEquals(normalize( | ||
"SELECT DISTINCT ( ?rel_subject AS ?rel_key ) ( ?rel_object AS ?rel_value )\n" | ||
+ "WHERE { ?rel_subject <http://www.w3.org/2004/02/skos/core#broader> ?rel_object . }"), | ||
normalize(rmb.makeQueryString())); | ||
} | ||
|
||
@Test | ||
public void testRelationWithConstraints() { | ||
RelationMapBuilder rmb = new RelationMapBuilder(this.rdf4JTemplate, EX.creatorOf) | ||
.constraints(RelationMapBuilder._relSubject.isA( | ||
EX.Artist)); | ||
assertEquals(normalize("SELECT DISTINCT ( ?rel_subject AS ?rel_key ) ( ?rel_object AS ?rel_value )\n" | ||
+ "WHERE { ?rel_subject a <http://example.org/Artist> .\n" | ||
+ "?rel_subject <http://example.org/creatorOf> ?rel_object . }"), normalize(rmb.makeQueryString())); | ||
} | ||
|
||
@Test | ||
public void testOptionalRelationWithPattern() { | ||
RelationMapBuilder rmb = new RelationMapBuilder(this.rdf4JTemplate, EX.creatorOf) | ||
.constraints(RelationMapBuilder._relSubject.isA( | ||
EX.Artist)) | ||
.relationIsOptional(); | ||
assertEquals(normalize( | ||
"SELECT DISTINCT ( ?rel_subject AS ?rel_key ) ( ?rel_object AS ?rel_value )\n" | ||
+ "WHERE { ?rel_subject a <http://example.org/Artist> .\n" | ||
+ "OPTIONAL { ?rel_subject <http://example.org/creatorOf> ?rel_object . } }\n"), | ||
normalize(rmb.makeQueryString())); | ||
} | ||
|
||
private String normalize(String s) { | ||
return s.replaceAll("\n", " ").replaceAll("\\s+", " ").trim(); | ||
} | ||
} |