|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2025 Eclipse RDF4J contributors. |
| 3 | + * |
| 4 | + * All rights reserved. This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Distribution License v1.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * http://www.eclipse.org/org/documents/edl-v10.php. |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: BSD-3-Clause |
| 10 | + *******************************************************************************/ |
| 11 | +package org.eclipse.rdf4j.sparqlbuilder.core.query; |
| 12 | + |
| 13 | +import static org.assertj.core.api.Assertions.assertThat; |
| 14 | +import static org.eclipse.rdf4j.sparqlbuilder.core.SparqlBuilder.var; |
| 15 | +import static org.eclipse.rdf4j.sparqlbuilder.rdf.Rdf.iri; |
| 16 | + |
| 17 | +import org.eclipse.rdf4j.sparqlbuilder.core.Variable; |
| 18 | +import org.eclipse.rdf4j.sparqlbuilder.graphpattern.GraphPatterns; |
| 19 | +import org.eclipse.rdf4j.sparqlbuilder.rdf.Iri; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | + |
| 22 | +class ConstructQueryFilterNotExistsTest { |
| 23 | + |
| 24 | + @Test |
| 25 | + void filterNotExistsGraphPatternIsWrappedInBraces() { |
| 26 | + Variable s = var("s"); |
| 27 | + Variable p = var("p"); |
| 28 | + Variable o = var("o"); |
| 29 | + Iri sourceGraph = iri("http://example.com/source"); |
| 30 | + Iri targetGraph = iri("http://example.com/target"); |
| 31 | + |
| 32 | + ConstructQuery query = Queries.CONSTRUCT() |
| 33 | + .construct(GraphPatterns.tp(s, p, o)) |
| 34 | + .where(GraphPatterns.and(s.has(p, o).from(sourceGraph)) |
| 35 | + .filterNotExists(s.has(p, o).from(targetGraph))); |
| 36 | + |
| 37 | + assertThat(query.getQueryString()) |
| 38 | + .contains("FILTER NOT EXISTS { GRAPH <http://example.com/target> { ?s ?p ?o . } }"); |
| 39 | + } |
| 40 | +} |
0 commit comments