Skip to content

Commit

Permalink
#331 Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-asprino committed Aug 26, 2024
1 parent fca92cf commit d42b103
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public class SPARQLAnything {

// TODO This should be moved to the engine module
private static void initSPARQLAnythingEngine() {
JenaSystem.init();
// Register the JSON-LD parser factory for extension .json
ReaderRIOTFactory parserFactoryJsonLD = new RiotUtils.ReaderRIOTFactoryJSONLD();
RDFParserRegistry.registerLangTriples(RiotUtils.JSON, parserFactoryJsonLD);
// Setup FX executor
JenaSystem.init();
QC.setFactory(ARQ.getContext(), FacadeX.ExecutorFactory);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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 io.github.sparqlanything.model.IRIArgument;
import org.apache.jena.sys.JenaSystem;
import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.util.Objects;

public class Issue331Test {

@Test
public void test() throws Exception {
JenaSystem.init();
InputStream fakeIn = new ByteArrayInputStream("abc".getBytes());
System.setIn(fakeIn);

String dir = Objects.requireNonNull(getClass().getClassLoader().getResource("")).getFile();
String f = dir.concat("out.ttl");
String f2 = dir.concat("out-1.ttl");
System.out.println(f);
File fileOut = new File(f);
File fileOut2 = new File(f2);

if(fileOut.exists()){
fileOut.delete();
}

String q = "CONSTRUCT {?s ?p ?o} WHERE { SERVICE <x-sparql-anything:> { ?s ?p ?o } }";
SPARQLAnything.callMain(new String[]{"-q", q,"-f", "ttl", "-o", f, "-c", IRIArgument.READ_FROM_STD_IN.toString().concat("=true")});

Assert.assertTrue(fileOut.exists());
Assert.assertFalse(fileOut2.exists());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class IRIArgument {
public static final IRIArgument ANNOTATE_TRIPLES_WITH_SLOT_KEYS = new IRIArgument("annotate-triples-with-slot-keys", "false");

public static final IRIArgument GENERATE_PREDICATE_LABELS = new IRIArgument("generate-predicate-labels", "false");
public static final IRIArgument READ_FROM_STD_IN = new IRIArgument("read-from-std-in", "false");
public static final IRIArgument READ_FROM_STD_IN = new IRIArgument(" ", "false");

private final String name;
private final String defaultValue;
Expand Down

0 comments on commit d42b103

Please sign in to comment.