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