Skip to content

Commit 0e9e008

Browse files
committed
RO bundle permalink testing
1 parent 03903b5 commit 0e9e008

File tree

2 files changed

+45
-69
lines changed

2 files changed

+45
-69
lines changed

src/main/java/org/commonwl/view/researchobject/ROBundleService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,13 @@ private void addFilesToBundle(GitDetails gitDetails, Bundle bundle, Path bundleP
248248

249249
} else {
250250
try {
251-
// Where to store the new file in bundle
251+
// Where to store the new file
252252
Path bundleFilePath = bundlePath.resolve(file.getName());
253+
Path gitPath = Paths.get(gitDetails.getPath()).resolve(file.getName());
253254

254255
// Get direct URL permalink
255256
URI rawURI = new URI("https://w3id.org/cwl/v/git/" + workflow.getLastCommit() +
256-
"/" + workflow.getRetrievedFrom().getPath() + "?format=raw");
257+
"/" + gitPath + "?format=raw");
257258

258259
// Variable to store file contents and aggregation
259260
String fileContent = null;
@@ -300,7 +301,6 @@ private void addFilesToBundle(GitDetails gitDetails, Bundle bundle, Path bundleP
300301
}
301302

302303
try {
303-
Path gitPath = Paths.get(gitDetails.getPath()).resolve(file.getName());
304304
String url = workflow.getRetrievedFrom()
305305
.getUrl(workflow.getLastCommit()).replace("https://", "");
306306

src/test/java/org/commonwl/view/researchobject/ROBundleServiceTest.java

Lines changed: 42 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,16 @@
5353

5454
public class ROBundleServiceTest {
5555

56-
private static Git gitRepo;
56+
private static ROBundleService roBundleService;
57+
private static ROBundleService roBundleServiceZeroSizeLimit;
5758

5859
@Before
5960
public void setUp() throws Exception {
6061
Repository mockRepo = Mockito.mock(Repository.class);
6162
when(mockRepo.getWorkTree()).thenReturn(new File("src/test/resources/cwl/"));
6263

63-
gitRepo = Mockito.mock(Git.class);
64+
Git gitRepo = Mockito.mock(Git.class);
6465
when(gitRepo.getRepository()).thenReturn(mockRepo);
65-
}
66-
67-
/**
68-
* Use a temporary directory for testing
69-
*/
70-
@Rule
71-
public TemporaryFolder roBundleFolder = new TemporaryFolder();
72-
73-
/**
74-
* Generate a Research Object bundle from lobstr and check it
75-
*/
76-
@Test
77-
public void generateAndSaveROBundle() throws Exception {
7866

7967
// Get mock Git service
8068
GitService mockGitService = Mockito.mock(GitService.class);
@@ -106,23 +94,42 @@ public void generateAndSaveROBundle() throws Exception {
10694
when(mockRdfService.getModel(anyObject(), anyObject()))
10795
.thenReturn("@prefix cwl: <https://w3id.org/cwl/cwl#> .".getBytes());
10896

97+
// Create new RO bundle
98+
roBundleService = new ROBundleService(roBundleFolder.getRoot().toPath(),
99+
"CWL Viewer", "https://view.commonwl.org", 5242880,
100+
mockGraphvizService, mockGitService, mockRdfService,
101+
Mockito.mock(GitSemaphore.class), mockCwlTool);
102+
roBundleServiceZeroSizeLimit = new ROBundleService(roBundleFolder.getRoot().toPath(),
103+
"CWL Viewer", "https://view.commonwl.org", 0,
104+
mockGraphvizService, mockGitService, mockRdfService,
105+
Mockito.mock(GitSemaphore.class), mockCwlTool);
106+
}
107+
108+
/**
109+
* Use a temporary directory for testing
110+
*/
111+
@Rule
112+
public TemporaryFolder roBundleFolder = new TemporaryFolder();
113+
114+
/**
115+
* Generate a Research Object bundle from lobstr and check it
116+
*/
117+
@Test
118+
public void generateAndSaveROBundle() throws Exception {
119+
109120
// Workflow details
110-
GitDetails lobSTRv1Details = new GitDetails("https://github.com/common-workflow-language/workflows.git",
121+
GitDetails lobSTRdraft3Details = new GitDetails("https://github.com/common-workflow-language/workflows.git",
111122
"933bf2a1a1cce32d88f88f136275535da9df0954", "workflows/lobSTR/lobSTR-workflow.cwl");
112-
Workflow lobSTRv1 = Mockito.mock(Workflow.class);
113-
when(lobSTRv1.getID()).thenReturn("testID");
114-
when(lobSTRv1.getRetrievedFrom()).thenReturn(lobSTRv1Details);
123+
Workflow lobSTRdraft3 = Mockito.mock(Workflow.class);
124+
when(lobSTRdraft3.getID()).thenReturn("testID");
125+
when(lobSTRdraft3.getRetrievedFrom()).thenReturn(lobSTRdraft3Details);
115126

116127
// RO details
117-
GitDetails lobSTRv1RODetails = new GitDetails("https://github.com/common-workflow-language/workflows.git",
128+
GitDetails lobSTRdraft3RODetails = new GitDetails("https://github.com/common-workflow-language/workflows.git",
118129
"933bf2a1a1cce32d88f88f136275535da9df0954", "lobstr-draft3/");
119130

120131
// Create new RO bundle
121-
ROBundleService bundleService = new ROBundleService(roBundleFolder.getRoot().toPath(),
122-
"CWL Viewer", "https://view.commonwl.org", 5242880,
123-
mockGraphvizService, mockGitService, mockRdfService,
124-
Mockito.mock(GitSemaphore.class), mockCwlTool);
125-
Bundle bundle = bundleService.createBundle(lobSTRv1, lobSTRv1RODetails);
132+
Bundle bundle = roBundleService.createBundle(lobSTRdraft3, lobSTRdraft3RODetails);
126133
Path bundleRoot = bundle.getRoot().resolve("workflow");
127134

128135
// Check bundle exists
@@ -138,7 +145,7 @@ public void generateAndSaveROBundle() throws Exception {
138145
// Check cwl aggregation information
139146
PathMetadata cwlAggregate = manifest.getAggregation(
140147
bundleRoot.resolve("lobSTR-workflow.cwl"));
141-
assertEquals("https://w3id.org/cwl/v/git/null/workflows/lobSTR/lobSTR-workflow.cwl?format=raw",
148+
assertEquals("https://w3id.org/cwl/v/git/null/lobstr-draft3/lobSTR-workflow.cwl?format=raw",
142149
cwlAggregate.getRetrievedFrom().toString());
143150
assertEquals("Mark Robinson", cwlAggregate.getAuthoredBy().get(0).getName());
144151
assertEquals("mailto:[email protected]", cwlAggregate.getAuthoredBy().get(0).getUri().toString());
@@ -165,7 +172,7 @@ public void generateAndSaveROBundle() throws Exception {
165172
history.get(0).toString());
166173

167174
// Save and check it exists in the temporary folder
168-
bundleService.saveToFile(bundle);
175+
roBundleService.saveToFile(bundle);
169176
File[] fileList = roBundleFolder.getRoot().listFiles();
170177
assertTrue(fileList.length == 1);
171178
for (File ro : fileList) {
@@ -182,58 +189,27 @@ public void generateAndSaveROBundle() throws Exception {
182189
@Test
183190
public void filesOverLimit() throws Exception {
184191

185-
// Get mock Git service
186-
GitService mockGitService = Mockito.mock(GitService.class);
187-
when(mockGitService.getRepository(anyObject(), anyBoolean())).thenReturn(gitRepo);
188-
189-
Set<HashableAgent> authors = new HashSet<>();
190-
authors.add(new HashableAgent("Mark Robinson", null, new URI("mailto:[email protected]")));
191-
when(mockGitService.getAuthors(anyObject(), anyObject()))
192-
.thenReturn(authors);
193-
194-
// Mock Graphviz service
195-
GraphVizService mockGraphvizService = Mockito.mock(GraphVizService.class);
196-
when(mockGraphvizService.getGraph(anyString(), anyString(), anyString()))
197-
.thenReturn(new File("src/test/resources/graphviz/testVis.png"))
198-
.thenReturn(new File("src/test/resources/graphviz/testVis.svg"));
199-
200-
// Mock CWLTool
201-
CWLTool mockCwlTool = Mockito.mock(CWLTool.class);
202-
when(mockCwlTool.getPackedVersion(anyString()))
203-
.thenReturn("cwlVersion: v1.0");
204-
when(mockCwlTool.getRDF(anyString()))
205-
.thenReturn("@prefix cwl: <https://w3id.org/cwl/cwl#> .");
206-
207-
// Mock RDF Service
208-
ResultSet emptyResult = Mockito.mock(ResultSet.class);
209-
when(emptyResult.hasNext()).thenReturn(false);
210-
RDFService mockRdfService = Mockito.mock(RDFService.class);
211-
when(mockRdfService.getAuthors(anyString(), anyString())).thenReturn(emptyResult);
212-
213192
// Workflow details
214-
GitDetails lobSTRv1Details = new GitDetails("https://github.com/common-workflow-language/workflows.git",
193+
GitDetails lobSTRdraft3Details = new GitDetails("https://github.com/common-workflow-language/workflows.git",
215194
"933bf2a1a1cce32d88f88f136275535da9df0954", "workflows/lobSTR/lobSTR-workflow.cwl");
216-
Workflow lobSTRv1 = Mockito.mock(Workflow.class);
217-
when(lobSTRv1.getID()).thenReturn("testID");
218-
when(lobSTRv1.getRetrievedFrom()).thenReturn(lobSTRv1Details);
195+
Workflow lobSTRdraft3 = Mockito.mock(Workflow.class);
196+
when(lobSTRdraft3.getID()).thenReturn("testID");
197+
when(lobSTRdraft3.getRetrievedFrom()).thenReturn(lobSTRdraft3Details);
219198

220199
// RO details
221-
GitDetails lobSTRv1RODetails = new GitDetails("https://github.com/common-workflow-language/workflows.git",
222-
"933bf2a1a1cce32d88f88f136275535da9df0954", "lobstr-draft3/lobSTR-workflow.cwl");
200+
GitDetails lobSTRdraft3RoDetails = new GitDetails("https://github.com/common-workflow-language/workflows.git",
201+
"933bf2a1a1cce32d88f88f136275535da9df0954", "lobstr-draft3/");
223202

224203
// Create new RO bundle
225-
ROBundleService bundleService = new ROBundleService(roBundleFolder.getRoot().toPath(),
226-
"CWL Viewer", "https://view.commonwl.org", 0, mockGraphvizService,
227-
mockGitService, mockRdfService, Mockito.mock(GitSemaphore.class), mockCwlTool);
228-
Bundle bundle = bundleService.createBundle(lobSTRv1, lobSTRv1RODetails);
204+
Bundle bundle = roBundleServiceZeroSizeLimit.createBundle(lobSTRdraft3, lobSTRdraft3RoDetails);
229205

230206
Manifest manifest = bundle.getManifest();
231207

232208
// Check files are externally linked in the aggregate
233209
assertEquals(14, manifest.getAggregates().size());
234210

235211
PathMetadata urlAggregate = manifest.getAggregation(
236-
new URI("https://raw.githubusercontent.com/common-workflow-language/workflows/933bf2a1a1cce32d88f88f136275535da9df0954/lobstr-draft3/lobSTR-workflow.cwl/models/illumina_v3.pcrfree.stepmodel"));
212+
new URI("https://w3id.org/cwl/v/git/null/lobstr-draft3/models/illumina_v3.pcrfree.stepmodel?format=raw"));
237213
assertEquals("Mark Robinson", urlAggregate.getAuthoredBy().get(0).getName());
238214

239215
}

0 commit comments

Comments
 (0)