Skip to content

Commit 1b3d94c

Browse files
committed
Remove test requirement on sparql endpoint
1 parent 4e59fac commit 1b3d94c

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

src/main/java/org/commonwl/view/cwl/RDFService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public String labelFromName(String name) {
305305
* @param queryString The query to be run
306306
* @return The result set of the query
307307
*/
308-
private ResultSet runQuery(ParameterizedSparqlString queryString) {
308+
ResultSet runQuery(ParameterizedSparqlString queryString) {
309309
Query query = QueryFactory.create(queryString.toString());
310310
try (QueryExecution qexec = QueryExecutionFactory.createServiceRequest(rdfService, query)) {
311311
return ResultSetFactory.copyResults(qexec.execSelect());

src/test/java/org/commonwl/view/cwl/CWLServiceTest.java

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,25 @@
1919

2020
package org.commonwl.view.cwl;
2121

22+
import org.apache.jena.query.*;
23+
import org.apache.jena.rdf.model.Model;
24+
import org.apache.jena.rdf.model.ModelFactory;
2225
import org.commonwl.view.github.GitHubService;
2326
import org.commonwl.view.github.GithubDetails;
2427
import org.commonwl.view.workflow.Workflow;
2528
import org.commonwl.view.workflow.WorkflowOverview;
29+
import org.junit.Before;
2630
import org.junit.Rule;
2731
import org.junit.Test;
2832
import org.junit.rules.ExpectedException;
2933
import org.junit.runner.RunWith;
3034
import org.mockito.Mockito;
3135
import org.mockito.invocation.InvocationOnMock;
3236
import org.mockito.stubbing.Answer;
33-
import org.springframework.beans.factory.annotation.Autowired;
3437
import org.springframework.boot.test.context.SpringBootTest;
3538
import org.springframework.test.context.junit4.SpringRunner;
3639

40+
import java.io.ByteArrayInputStream;
3741
import java.io.File;
3842
import java.io.IOException;
3943
import java.util.Map;
@@ -51,9 +55,32 @@ public class CWLServiceTest {
5155
/**
5256
* RDFService for testing
5357
*/
54-
@Autowired
5558
private RDFService rdfService;
5659

60+
@Before
61+
public void setUp() throws Exception {
62+
File packedWorkflowRdf = new File("src/test/resources/cwl/make_to_cwl/dna.ttl");
63+
Model workflowModel = ModelFactory.createDefaultModel();
64+
workflowModel.read(new ByteArrayInputStream(readFileToString(packedWorkflowRdf).getBytes()), null, "TURTLE");
65+
Dataset workflowDataset = DatasetFactory.create();
66+
workflowDataset.addNamedModel("http://madeup.endpoint/github.com/common-workflow-language/workflows/master/workflows/make-to-cwl/dna.cwl", workflowModel);
67+
68+
Answer queryRdf = new Answer<ResultSet>() {
69+
@Override
70+
public ResultSet answer(InvocationOnMock invocation) throws Throwable {
71+
Object[] args = invocation.getArguments();
72+
Query query = QueryFactory.create(args[0].toString());
73+
try (QueryExecution qexec = QueryExecutionFactory.create(query, workflowDataset)) {
74+
return ResultSetFactory.copyResults(qexec.execSelect());
75+
}
76+
}
77+
};
78+
79+
this.rdfService = Mockito.spy(new RDFService("http://madeup.endpoint/"));
80+
Mockito.doAnswer(queryRdf).when(rdfService).runQuery(anyObject());
81+
Mockito.doReturn(true).when(rdfService).graphExists(anyString());
82+
}
83+
5784
/**
5885
* Used for expected IOExceptions for filesize limits
5986
*/

src/test/resources/cwl/make_to_cwl/visualisation.dot

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ digraph workflow {
4141
"combine_sequences" [label="combine_sequences"];
4242
"get_sequences" [label="get_sequences"];
4343
"translate_sequences" [label="translate_sequences"];
44-
"get_sequences" -> "combine_sequences" [label="sequences"];
4544
"default1" -> "combine_sequences" [label="catfilename"];
4645
"default1" [label="\"database.dna\"", fillcolor="#D5AEFC"];
46+
"get_sequences" -> "combine_sequences" [label="sequences"];
4747
"rna" -> "get_sequences" [label="sequence"];
48+
"default2" -> "translate_sequences" [label="filename"];
49+
"default2" [label="\"database.dna\"", fillcolor="#D5AEFC"];
50+
"default3" -> "translate_sequences" [label="from"];
51+
"default3" [label="\"U\"", fillcolor="#D5AEFC"];
52+
"default4" -> "translate_sequences" [label="to"];
53+
"default4" [label="\"T\"", fillcolor="#D5AEFC"];
4854
"combine_sequences" -> "translate_sequences" [label="trinput"];
49-
"default2" -> "translate_sequences" [label="to"];
50-
"default2" [label="\"T\"", fillcolor="#D5AEFC"];
51-
"default3" -> "translate_sequences" [label="filename"];
52-
"default3" [label="\"database.dna\"", fillcolor="#D5AEFC"];
53-
"default4" -> "translate_sequences" [label="from"];
54-
"default4" [label="\"U\"", fillcolor="#D5AEFC"];
5555
"translate_sequences" -> "outfile";
5656
}

0 commit comments

Comments
 (0)