19
19
20
20
package org .commonwl .view .cwl ;
21
21
22
+ import org .apache .jena .query .*;
23
+ import org .apache .jena .rdf .model .Model ;
24
+ import org .apache .jena .rdf .model .ModelFactory ;
22
25
import org .commonwl .view .github .GitHubService ;
23
26
import org .commonwl .view .github .GithubDetails ;
24
27
import org .commonwl .view .workflow .Workflow ;
25
28
import org .commonwl .view .workflow .WorkflowOverview ;
29
+ import org .junit .Before ;
26
30
import org .junit .Rule ;
27
31
import org .junit .Test ;
28
32
import org .junit .rules .ExpectedException ;
29
33
import org .junit .runner .RunWith ;
30
34
import org .mockito .Mockito ;
31
35
import org .mockito .invocation .InvocationOnMock ;
32
36
import org .mockito .stubbing .Answer ;
33
- import org .springframework .beans .factory .annotation .Autowired ;
34
37
import org .springframework .boot .test .context .SpringBootTest ;
35
38
import org .springframework .test .context .junit4 .SpringRunner ;
36
39
40
+ import java .io .ByteArrayInputStream ;
37
41
import java .io .File ;
38
42
import java .io .IOException ;
39
43
import java .util .Map ;
@@ -51,9 +55,32 @@ public class CWLServiceTest {
51
55
/**
52
56
* RDFService for testing
53
57
*/
54
- @ Autowired
55
58
private RDFService rdfService ;
56
59
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
+
57
84
/**
58
85
* Used for expected IOExceptions for filesize limits
59
86
*/
0 commit comments