Skip to content

Commit 0cae95b

Browse files
author
Mark Robinson
committed
Limited testing of GithubService for methods not requiring API calls
1 parent bd7a63a commit 0cae95b

File tree

2 files changed

+109
-11
lines changed

2 files changed

+109
-11
lines changed

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class CWLServiceTest {
2626
public void parseLobSTRDraft3Workflow() throws Exception {
2727

2828
// Mock githubService class to redirect downloads to resources folder
29-
GitHubService githubService = Mockito.mock(GitHubService.class);
29+
GitHubService mockGithubService = Mockito.mock(GitHubService.class);
3030
Answer fileAnswer = new Answer<String>() {
3131
@Override
3232
public String answer(InvocationOnMock invocation) throws Throwable {
@@ -37,11 +37,11 @@ public String answer(InvocationOnMock invocation) throws Throwable {
3737
return FileUtils.readFileToString(workflowFile);
3838
}
3939
};
40-
when(githubService.downloadFile(anyObject())).thenAnswer(fileAnswer);
41-
when(githubService.downloadFile(anyObject(), anyObject())).thenAnswer(fileAnswer);
40+
when(mockGithubService.downloadFile(anyObject())).thenAnswer(fileAnswer);
41+
when(mockGithubService.downloadFile(anyObject(), anyObject())).thenAnswer(fileAnswer);
4242

4343
// Test cwl service
44-
CWLService cwlService = new CWLService(githubService, 5242880);
44+
CWLService cwlService = new CWLService(mockGithubService, 5242880);
4545

4646
// Get workflow from community repo by commit ID so it will not change
4747
GithubDetails lobSTRDraft3Details = new GithubDetails("common-workflow-language",
@@ -61,7 +61,7 @@ public String answer(InvocationOnMock invocation) throws Throwable {
6161
public void parseLobSTRv1Workflow() throws Exception {
6262

6363
// Mock githubService class to redirect downloads to resources folder
64-
GitHubService githubService = Mockito.mock(GitHubService.class);
64+
GitHubService mockGithubService = Mockito.mock(GitHubService.class);
6565
Answer fileAnswer = new Answer<String>() {
6666
@Override
6767
public String answer(InvocationOnMock invocation) throws Throwable {
@@ -72,11 +72,11 @@ public String answer(InvocationOnMock invocation) throws Throwable {
7272
return FileUtils.readFileToString(workflowFile);
7373
}
7474
};
75-
when(githubService.downloadFile(anyObject())).thenAnswer(fileAnswer);
76-
when(githubService.downloadFile(anyObject(), anyObject())).thenAnswer(fileAnswer);
75+
when(mockGithubService.downloadFile(anyObject())).thenAnswer(fileAnswer);
76+
when(mockGithubService.downloadFile(anyObject(), anyObject())).thenAnswer(fileAnswer);
7777

7878
// Test cwl service
79-
CWLService cwlService = new CWLService(githubService, 5242880);
79+
CWLService cwlService = new CWLService(mockGithubService, 5242880);
8080

8181
// Get workflow from community repo by commit ID so it will not change
8282
GithubDetails lobSTRv1Details = new GithubDetails("common-workflow-language",
@@ -137,13 +137,13 @@ private void testLobSTRWorkflow(Workflow lobSTR) throws Exception {
137137
public void getHelloWorkflowOverview() throws Exception {
138138

139139
// Mock githubService class
140-
GitHubService githubService = Mockito.mock(GitHubService.class);
140+
GitHubService mockGithubService = Mockito.mock(GitHubService.class);
141141
File workflowFile = new File("src/test/resources/cwl/hello/hello.cwl");
142-
when(githubService.downloadFile(anyObject()))
142+
when(mockGithubService.downloadFile(anyObject()))
143143
.thenReturn(FileUtils.readFileToString(workflowFile));
144144

145145
// Test cwl service
146-
CWLService cwlService = new CWLService(githubService, 5242880);
146+
CWLService cwlService = new CWLService(mockGithubService, 5242880);
147147

148148
// Get workflow from community repo by commit ID so it will not change
149149
GithubDetails helloDetails = new GithubDetails("common-workflow-language",
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package org.commonwl.view.github;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.test.context.junit4.SpringRunner;
8+
9+
import static org.junit.Assert.assertEquals;
10+
import static org.junit.Assert.assertNotNull;
11+
12+
@RunWith(SpringRunner.class)
13+
@SpringBootTest
14+
public class GithubServiceTest {
15+
16+
17+
/**
18+
* Create a service to test
19+
*/
20+
@Autowired
21+
private GitHubService githubService;
22+
23+
/**
24+
* Details can be extracted from a full Github CWL file URL
25+
*/
26+
@Test
27+
public void detailsFromFileURLFull() throws Exception {
28+
29+
GithubDetails details = githubService.detailsFromFileURL("https://github.com/nlesc-sherlock/deeplearning/blob/master/CWLworkflow/pipeline.cwl");
30+
assertNotNull(details);
31+
assertEquals("nlesc-sherlock", details.getOwner());
32+
assertEquals("deeplearning", details.getRepoName());
33+
assertEquals("master", details.getBranch());
34+
assertEquals("CWLworkflow/pipeline.cwl", details.getPath());
35+
36+
}
37+
38+
/**
39+
* Github CWL file URL at the repository root
40+
*/
41+
@Test
42+
public void detailsFromFileURLAtBase() throws Exception {
43+
44+
GithubDetails details = githubService.detailsFromFileURL("https://github.com/genome/arvados_trial/blob/master/pipeline.cwl");
45+
assertNotNull(details);
46+
assertEquals("genome", details.getOwner());
47+
assertEquals("arvados_trial", details.getRepoName());
48+
assertEquals("master", details.getBranch());
49+
assertEquals("pipeline.cwl", details.getPath());
50+
51+
}
52+
53+
/**
54+
* Details can be extracted from a full Github directory URL
55+
*/
56+
@Test
57+
public void detailsFromDirURLFull() throws Exception {
58+
59+
GithubDetails details = githubService.detailsFromDirURL("https://github.com/common-workflow-language/workflows/tree/visu/workflows/compile");
60+
assertNotNull(details);
61+
assertEquals("common-workflow-language", details.getOwner());
62+
assertEquals("workflows", details.getRepoName());
63+
assertEquals("visu", details.getBranch());
64+
assertEquals("workflows/compile", details.getPath());
65+
66+
}
67+
68+
/**
69+
* No path included in the directory URL
70+
*/
71+
@Test
72+
public void detailsFromDirURLNoPath() throws Exception {
73+
74+
GithubDetails details = githubService.detailsFromDirURL("https://github.com/OBF/GSoC/tree/d46ce365f1a10c4c4d6b0caed51c6f64b84c2f63");
75+
assertNotNull(details);
76+
assertEquals("OBF", details.getOwner());
77+
assertEquals("GSoC", details.getRepoName());
78+
assertEquals("d46ce365f1a10c4c4d6b0caed51c6f64b84c2f63", details.getBranch());
79+
assertEquals("/", details.getPath());
80+
81+
}
82+
83+
/**
84+
* No branch or path included in the directory URL
85+
*/
86+
@Test
87+
public void detailsFromDirURLNoBranchPath() throws Exception {
88+
89+
GithubDetails details = githubService.detailsFromDirURL("https://github.com/common-workflow-language/cwlviewer");
90+
assertNotNull(details);
91+
assertEquals("common-workflow-language", details.getOwner());
92+
assertEquals("cwlviewer", details.getRepoName());
93+
assertEquals("master", details.getBranch());
94+
assertEquals("/", details.getPath());
95+
96+
}
97+
98+
}

0 commit comments

Comments
 (0)