-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33515fa
commit 8b0f6a9
Showing
3 changed files
with
81 additions
and
27 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
73 changes: 73 additions & 0 deletions
73
sparql-anything-cli/src/test/java/io/github/sparqlanything/cli/CLITest.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,73 @@ | ||
/* | ||
* Copyright (c) 2024 SPARQL Anything Contributors @ http://github.com/sparql-anything | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.github.sparqlanything.cli; | ||
|
||
import org.apache.commons.csv.CSVFormat; | ||
import org.apache.commons.csv.CSVParser; | ||
import org.apache.commons.csv.CSVRecord; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.StringReader; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public class CLITest { | ||
|
||
@Test | ||
public void inlineQuery() throws Exception { | ||
String f = Objects.requireNonNull(getClass().getClassLoader().getResource("books.xml")).toURI().toString(); | ||
String q = "SELECT * { ?s ?p ?o OPTIONAL {?s a ?c} }"; | ||
query(f, q); | ||
} | ||
|
||
private static void query(String f, String q) throws Exception { | ||
String out = SPARQLAnything.callMain(new String[]{"-q", q, "-c", "location=" + f, "-f", "CSV"}); | ||
CSVParser parser = new CSVParser(new StringReader(out), CSVFormat.DEFAULT); | ||
Set<String> actualSet = new HashSet<>(); | ||
for (CSVRecord record : parser) { | ||
actualSet.add(record.get(3)); | ||
} | ||
Set<String> expectedSet = new HashSet<>(); | ||
expectedSet.add("c"); | ||
expectedSet.add("http://sparql.xyz/facade-x/ns/root"); | ||
expectedSet.add("http://sparql.xyz/facade-x/data/catalog"); | ||
expectedSet.add("http://sparql.xyz/facade-x/data/book"); | ||
expectedSet.add("http://sparql.xyz/facade-x/data/author"); | ||
expectedSet.add("http://sparql.xyz/facade-x/data/price"); | ||
expectedSet.add("http://sparql.xyz/facade-x/data/title"); | ||
expectedSet.add("http://sparql.xyz/facade-x/data/genre"); | ||
expectedSet.add("http://sparql.xyz/facade-x/data/publish_date"); | ||
Assert.assertEquals(expectedSet, actualSet); | ||
} | ||
|
||
|
||
@Test | ||
public void infileQuery() throws Exception { | ||
String f = Objects.requireNonNull(getClass().getClassLoader().getResource("books.xml")).toURI().toString(); | ||
String queryFile = Objects.requireNonNull(getClass().getClassLoader().getResource("CLITestOnFileQuery.sparql")).toURI().toString(); | ||
query(f, queryFile); | ||
} | ||
|
||
@Test | ||
public void remoteQuery() throws Exception { | ||
String f = Objects.requireNonNull(getClass().getClassLoader().getResource("books.xml")).toURI().toString(); | ||
String queryFile = "https://sparql-anything.cc/examples/CLITestOnFileQuery.sparql"; | ||
query(f, queryFile); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
sparql-anything-cli/src/test/resources/CLITestOnFileQuery.sparql
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 @@ | ||
SELECT * { ?s ?p ?o OPTIONAL {?s a ?c} } |