Skip to content

Commit f75a2b6

Browse files
author
Mark Robinson
committed
Increase coverage of ROBundleTest
Add file size limit checking and include subdirectory models/ from LobSTR
1 parent 0917590 commit f75a2b6

File tree

1 file changed

+68
-11
lines changed

1 file changed

+68
-11
lines changed

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

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import org.apache.taverna.robundle.Bundle;
55
import org.apache.taverna.robundle.Bundles;
66
import org.apache.taverna.robundle.manifest.Manifest;
7+
import org.apache.taverna.robundle.manifest.PathMetadata;
78
import org.commonwl.view.github.GitHubService;
89
import org.commonwl.view.github.GithubDetails;
910
import org.eclipse.egit.github.core.*;
@@ -15,6 +16,7 @@
1516
import org.mockito.stubbing.Answer;
1617

1718
import java.io.File;
19+
import java.nio.file.Path;
1820
import java.util.ArrayList;
1921
import java.util.List;
2022

@@ -44,6 +46,7 @@ public void generateAndSaveROBundle() throws Exception {
4446
"933bf2a1a1cce32d88f88f136275535da9df0954", "workflows/lobSTR");
4547
ROBundle bundle = new ROBundle(mockGithubService, lobSTRv1Details, "CWL Viewer",
4648
"https://view.commonwl.org", 5242880);
49+
Path bundleRoot = bundle.getBundle().getRoot().resolve("workflow");
4750

4851
// Check bundle exists
4952
assertNotNull(bundle.getBundle());
@@ -53,7 +56,17 @@ public void generateAndSaveROBundle() throws Exception {
5356
assertEquals("CWL Viewer", manifest.getCreatedBy().getName());
5457
assertEquals("https://view.commonwl.org", manifest.getCreatedBy().getUri().toString());
5558
assertEquals("Mark Robinson", manifest.getAuthoredBy().get(0).getName());
56-
assertEquals(10, manifest.getAggregates().size());
59+
assertEquals(12, manifest.getAggregates().size());
60+
61+
// Check cwl aggregation information
62+
PathMetadata cwlAggregate = manifest.getAggregation(
63+
bundleRoot.resolve("lobSTR-workflow.cwl"));
64+
assertEquals("https://raw.githubusercontent.com/common-workflow-language/workflows/933bf2a1a1cce32d88f88f136275535da9df0954/workflows/lobSTR/lobSTR-workflow.cwl",
65+
cwlAggregate.getRetrievedFrom().toString());
66+
assertEquals("Mark Robinson", cwlAggregate.getAuthoredBy().get(0).getName());
67+
assertNull(cwlAggregate.getAuthoredBy().get(0).getOrcid());
68+
assertEquals("text/x-yaml", cwlAggregate.getMediatype());
69+
assertEquals("https://w3id.org/cwl/v1.0", cwlAggregate.getConformsTo().toString());
5770

5871
// Save and check it exists in the temporary folder
5972
bundle.saveToFile(roBundleFolder.getRoot().toPath());
@@ -67,6 +80,31 @@ public void generateAndSaveROBundle() throws Exception {
6780

6881
}
6982

83+
/**
84+
* Test file size limit
85+
*/
86+
@Test
87+
public void filesOverLimit() throws Exception {
88+
89+
// Get mock Github service
90+
GitHubService mockGithubService = getMock();
91+
92+
// Create new RO bundle where all files are external
93+
GithubDetails lobSTRv1Details = new GithubDetails("common-workflow-language", "workflows",
94+
"933bf2a1a1cce32d88f88f136275535da9df0954", "workflows/lobSTR");
95+
ROBundle bundle = new ROBundle(mockGithubService, lobSTRv1Details, "CWL Viewer",
96+
"https://view.commonwl.org", 0);
97+
98+
Manifest manifest = bundle.getBundle().getManifest();
99+
100+
// Check files are externally linked in the aggregate
101+
Path bundleRoot = bundle.getBundle().getRoot().resolve("workflow");
102+
PathMetadata urlAggregate = manifest.getAggregation(
103+
bundleRoot.resolve("lobSTR-demo.url"));
104+
assertEquals("Mark Robinson", urlAggregate.getAuthoredBy().get(0).getName());
105+
106+
}
107+
70108
/**
71109
* Get a mock Github service redirecting file downloads to file system
72110
* and providing translation from the file system to Github API returns
@@ -88,21 +126,40 @@ public String answer(InvocationOnMock invocation) throws Throwable {
88126
when(mockGithubService.downloadFile(anyObject())).thenAnswer(fileAnswer);
89127
when(mockGithubService.downloadFile(anyObject(), anyObject())).thenAnswer(fileAnswer);
90128

91-
// TODO: Also add mock for directories and account for their path
92129
Answer contentsAnswer = new Answer<List<RepositoryContents>>() {
93130
@Override
94131
public List<RepositoryContents> answer(InvocationOnMock invocation) throws Throwable {
95-
File[] fileList = new File("src/test/resources/cwl/lobstr-v1/").listFiles();
132+
Object[] args = invocation.getArguments();
133+
GithubDetails details = (GithubDetails) args[0];
96134

97-
// Add all files from lobstr-v1 directory
98135
List<RepositoryContents> returnList = new ArrayList<>();
99-
for (File thisFile : fileList) {
100-
if (thisFile.isFile()) {
101-
RepositoryContents singleFile = new RepositoryContents();
102-
singleFile.setType(GitHubService.TYPE_FILE);
103-
singleFile.setName(thisFile.getName());
104-
singleFile.setPath("workflows/lobSTR/" + thisFile.getName());
105-
returnList.add(singleFile);
136+
137+
if (!details.getPath().endsWith("models")) {
138+
// Add all files from lobstr-v1 directory
139+
File[] fileList = new File("src/test/resources/cwl/lobstr-v1/").listFiles();
140+
for (File thisFile : fileList) {
141+
RepositoryContents contentsEntry = new RepositoryContents();
142+
if (thisFile.isDirectory()) {
143+
contentsEntry.setType(GitHubService.TYPE_DIR);
144+
contentsEntry.setSize(0);
145+
} else if (thisFile.isFile()) {
146+
contentsEntry.setType(GitHubService.TYPE_FILE);
147+
contentsEntry.setSize(100);
148+
}
149+
contentsEntry.setName(thisFile.getName());
150+
contentsEntry.setPath("workflows/lobSTR/" + thisFile.getName());
151+
returnList.add(contentsEntry);
152+
}
153+
} else {
154+
// Add all files from lobstr-v1/models subdirectory
155+
File[] subDirFileList = new File("src/test/resources/cwl/lobstr-v1/models/").listFiles();
156+
for (File thisFile : subDirFileList) {
157+
RepositoryContents contentsEntry = new RepositoryContents();
158+
contentsEntry.setType(GitHubService.TYPE_FILE);
159+
contentsEntry.setName(thisFile.getName());
160+
contentsEntry.setSize(100);
161+
contentsEntry.setPath("workflows/lobSTR/models/" + thisFile.getName());
162+
returnList.add(contentsEntry);
106163
}
107164
}
108165

0 commit comments

Comments
 (0)