4
4
import org .apache .taverna .robundle .Bundle ;
5
5
import org .apache .taverna .robundle .Bundles ;
6
6
import org .apache .taverna .robundle .manifest .Manifest ;
7
+ import org .apache .taverna .robundle .manifest .PathMetadata ;
7
8
import org .commonwl .view .github .GitHubService ;
8
9
import org .commonwl .view .github .GithubDetails ;
9
10
import org .eclipse .egit .github .core .*;
15
16
import org .mockito .stubbing .Answer ;
16
17
17
18
import java .io .File ;
19
+ import java .nio .file .Path ;
18
20
import java .util .ArrayList ;
19
21
import java .util .List ;
20
22
@@ -44,6 +46,7 @@ public void generateAndSaveROBundle() throws Exception {
44
46
"933bf2a1a1cce32d88f88f136275535da9df0954" , "workflows/lobSTR" );
45
47
ROBundle bundle = new ROBundle (mockGithubService , lobSTRv1Details , "CWL Viewer" ,
46
48
"https://view.commonwl.org" , 5242880 );
49
+ Path bundleRoot = bundle .getBundle ().getRoot ().resolve ("workflow" );
47
50
48
51
// Check bundle exists
49
52
assertNotNull (bundle .getBundle ());
@@ -53,7 +56,17 @@ public void generateAndSaveROBundle() throws Exception {
53
56
assertEquals ("CWL Viewer" , manifest .getCreatedBy ().getName ());
54
57
assertEquals ("https://view.commonwl.org" , manifest .getCreatedBy ().getUri ().toString ());
55
58
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 ());
57
70
58
71
// Save and check it exists in the temporary folder
59
72
bundle .saveToFile (roBundleFolder .getRoot ().toPath ());
@@ -67,6 +80,31 @@ public void generateAndSaveROBundle() throws Exception {
67
80
68
81
}
69
82
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
+
70
108
/**
71
109
* Get a mock Github service redirecting file downloads to file system
72
110
* and providing translation from the file system to Github API returns
@@ -88,21 +126,40 @@ public String answer(InvocationOnMock invocation) throws Throwable {
88
126
when (mockGithubService .downloadFile (anyObject ())).thenAnswer (fileAnswer );
89
127
when (mockGithubService .downloadFile (anyObject (), anyObject ())).thenAnswer (fileAnswer );
90
128
91
- // TODO: Also add mock for directories and account for their path
92
129
Answer contentsAnswer = new Answer <List <RepositoryContents >>() {
93
130
@ Override
94
131
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 ];
96
134
97
- // Add all files from lobstr-v1 directory
98
135
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 );
106
163
}
107
164
}
108
165
0 commit comments