@@ -17,7 +17,7 @@ public class TestSnippetsApi {
17
17
18
18
private static final String TEST_HOST_URL ;
19
19
private static final String TEST_PRIVATE_TOKEN ;
20
-
20
+
21
21
static {
22
22
TEST_HOST_URL = TestUtils .getProperty ("TEST_HOST_URL" );
23
23
TEST_PRIVATE_TOKEN = TestUtils .getProperty ("TEST_PRIVATE_TOKEN" );
@@ -29,8 +29,7 @@ public class TestSnippetsApi {
29
29
private static final String TEST_SNIPPET_CONTENT_1 = "test-snippet-content-1" ;
30
30
private static final String TEST_SNIPPET_CONTENT_2 = "test-snippet-content-2" ;
31
31
private static final String TEST_SNIPPET_DESCRIPTION_1 = "test-snippet-description-1" ;
32
-
33
-
32
+
34
33
@ BeforeClass
35
34
public static void setup () {
36
35
@@ -50,95 +49,81 @@ public static void setup() {
50
49
System .err .print (problems );
51
50
}
52
51
}
53
-
54
- @ Test
55
- public void testCreate () throws GitLabApiException {
56
- Snippet snippet = createSnippet (new Snippet (TEST_SNIPPET_TITLE_1 ,
57
- TEST_SNIPPET_FILE_NAME_1 ,
58
- TEST_SNIPPET_CONTENT_1 ));
59
- assertEquals (TEST_SNIPPET_TITLE_1 , snippet .getTitle ());
60
- assertEquals (TEST_SNIPPET_FILE_NAME_1 , snippet .getFileName ());
61
- assertNull (snippet .getContent ());
62
-
63
- deleteSnippet (snippet );
64
- }
65
-
66
- @ Test
67
- public void testDelete () throws GitLabApiException {
68
- Snippet snippet = createSnippet (new Snippet (TEST_SNIPPET_TITLE_1 ,
69
- TEST_SNIPPET_FILE_NAME_1 ,
70
- TEST_SNIPPET_CONTENT_1 ));
71
- deleteSnippet (snippet );
72
-
73
- SnippetsApi api = gitLabApi .getSnippetApi ();
74
- List <Snippet > snippets = api .getSnippets ();
75
- boolean found = snippets .stream ().anyMatch (
76
- s -> s .getId ().equals (snippet .getId ()));
77
- assertFalse (found );
78
- }
79
-
80
- @ Test
81
- public void testList () throws GitLabApiException {
82
- Snippet snippet1 = createSnippet (new Snippet (TEST_SNIPPET_TITLE_1 ,
83
- TEST_SNIPPET_FILE_NAME_1 ,
84
- TEST_SNIPPET_CONTENT_1 ));
85
- Snippet snippet2 = createSnippet (new Snippet (TEST_SNIPPET_TITLE_1 ,
86
- TEST_SNIPPET_FILE_NAME_1 ,
87
- TEST_SNIPPET_CONTENT_2 ));
88
-
89
- SnippetsApi api = gitLabApi .getSnippetApi ();
90
- List <Snippet > snippets = api .getSnippets (true );
91
-
92
- assertTrue (snippets .size () >= 2 );
93
- assertTrue (snippets .stream ().anyMatch (s -> s .getContent ().equals (TEST_SNIPPET_CONTENT_1 )));
94
- assertTrue (snippets .stream ().anyMatch (s -> s .getContent ().equals (TEST_SNIPPET_CONTENT_2 )));
95
-
96
-
97
- deleteSnippet (snippet1 );
98
- deleteSnippet (snippet2 );
99
- }
100
-
101
- @ Test
102
- public void testSnippetContent () throws GitLabApiException {
103
- Snippet snippet = createSnippet (
104
- new Snippet (TEST_SNIPPET_TITLE_1 , TEST_SNIPPET_FILE_NAME_1 , TEST_SNIPPET_CONTENT_1 ));
105
- SnippetsApi api = gitLabApi .getSnippetApi ();
106
- String snippetContent = api .getSnippetContent (snippet .getId ());
107
- assertEquals (TEST_SNIPPET_CONTENT_1 , snippetContent );
108
- deleteSnippet (snippet );
109
- }
110
-
111
- @ Test
112
- public void testRetrieveSnippet () throws GitLabApiException {
113
- Snippet snippet = createSnippet (new Snippet (TEST_SNIPPET_TITLE_1 ,
114
- TEST_SNIPPET_FILE_NAME_1 ,
115
- TEST_SNIPPET_CONTENT_1 ,
116
- Visibility .INTERNAL ,
117
- TEST_SNIPPET_DESCRIPTION_1 ));
118
-
119
- SnippetsApi api = gitLabApi .getSnippetApi ();
120
- Snippet savedSnippet = api .getSnippet (snippet .getId (), true );
121
-
122
- assertEquals (TEST_SNIPPET_TITLE_1 , savedSnippet .getTitle ());
123
- assertEquals (TEST_SNIPPET_FILE_NAME_1 , savedSnippet .getFileName ());
124
- assertEquals (TEST_SNIPPET_CONTENT_1 , savedSnippet .getContent ());
125
- assertEquals (TEST_SNIPPET_DESCRIPTION_1 , savedSnippet .getDescription ());
126
-
127
- deleteSnippet (savedSnippet );
128
- }
129
-
130
- public void deleteSnippet (Snippet snippet ) throws GitLabApiException {
131
- SnippetsApi api = gitLabApi .getSnippetApi ();
132
- api .deleteSnippet (snippet .getId ());
133
- }
134
-
135
- public Snippet createSnippet (Snippet snippet ) throws GitLabApiException {
136
- SnippetsApi api = gitLabApi .getSnippetApi ();
137
- return api .createSnippet (snippet .getTitle (),
138
- snippet .getFileName (),
139
- snippet .getContent (),
140
- snippet .getVisibility (),
141
- snippet .getDescription ());
142
- }
143
-
52
+
53
+ @ Test
54
+ public void testCreate () throws GitLabApiException {
55
+ Snippet snippet = createSnippet (
56
+ new Snippet (TEST_SNIPPET_TITLE_1 , TEST_SNIPPET_FILE_NAME_1 , TEST_SNIPPET_CONTENT_1 ));
57
+ assertEquals (TEST_SNIPPET_TITLE_1 , snippet .getTitle ());
58
+ assertEquals (TEST_SNIPPET_FILE_NAME_1 , snippet .getFileName ());
59
+ assertNull (snippet .getContent ());
60
+
61
+ deleteSnippet (snippet );
62
+ }
63
+
64
+ @ Test
65
+ public void testDelete () throws GitLabApiException {
66
+ Snippet snippet = createSnippet (
67
+ new Snippet (TEST_SNIPPET_TITLE_1 , TEST_SNIPPET_FILE_NAME_1 , TEST_SNIPPET_CONTENT_1 ));
68
+ deleteSnippet (snippet );
69
+
70
+ SnippetsApi api = gitLabApi .getSnippetApi ();
71
+ List <Snippet > snippets = api .getSnippets ();
72
+ boolean found = snippets .stream ().anyMatch (s -> s .getId ().equals (snippet .getId ()));
73
+ assertFalse (found );
74
+ }
75
+
76
+ @ Test
77
+ public void testList () throws GitLabApiException {
78
+ Snippet snippet1 = createSnippet (new Snippet (TEST_SNIPPET_TITLE_1 , TEST_SNIPPET_FILE_NAME_1 , TEST_SNIPPET_CONTENT_1 ));
79
+ Snippet snippet2 = createSnippet (new Snippet (TEST_SNIPPET_TITLE_1 , TEST_SNIPPET_FILE_NAME_1 , TEST_SNIPPET_CONTENT_2 ));
80
+
81
+ SnippetsApi api = gitLabApi .getSnippetApi ();
82
+ List <Snippet > snippets = api .getSnippets (true );
83
+
84
+ assertTrue (snippets .size () >= 2 );
85
+ assertTrue (snippets .stream ().anyMatch (s -> s .getContent ().equals (TEST_SNIPPET_CONTENT_1 )));
86
+ assertTrue (snippets .stream ().anyMatch (s -> s .getContent ().equals (TEST_SNIPPET_CONTENT_2 )));
87
+
88
+ deleteSnippet (snippet1 );
89
+ deleteSnippet (snippet2 );
90
+ }
91
+
92
+ @ Test
93
+ public void testSnippetContent () throws GitLabApiException {
94
+ Snippet snippet = createSnippet (
95
+ new Snippet (TEST_SNIPPET_TITLE_1 , TEST_SNIPPET_FILE_NAME_1 , TEST_SNIPPET_CONTENT_1 ));
96
+ SnippetsApi api = gitLabApi .getSnippetApi ();
97
+ String snippetContent = api .getSnippetContent (snippet .getId ());
98
+ assertEquals (TEST_SNIPPET_CONTENT_1 , snippetContent );
99
+ deleteSnippet (snippet );
100
+ }
101
+
102
+ @ Test
103
+ public void testRetrieveSnippet () throws GitLabApiException {
104
+ Snippet snippet = createSnippet (new Snippet (TEST_SNIPPET_TITLE_1 , TEST_SNIPPET_FILE_NAME_1 ,
105
+ TEST_SNIPPET_CONTENT_1 , Visibility .INTERNAL , TEST_SNIPPET_DESCRIPTION_1 ));
106
+
107
+ SnippetsApi api = gitLabApi .getSnippetApi ();
108
+ Snippet savedSnippet = api .getSnippet (snippet .getId (), true );
109
+
110
+ assertEquals (TEST_SNIPPET_TITLE_1 , savedSnippet .getTitle ());
111
+ assertEquals (TEST_SNIPPET_FILE_NAME_1 , savedSnippet .getFileName ());
112
+ assertEquals (TEST_SNIPPET_CONTENT_1 , savedSnippet .getContent ());
113
+ assertEquals (TEST_SNIPPET_DESCRIPTION_1 , savedSnippet .getDescription ());
114
+
115
+ deleteSnippet (savedSnippet );
116
+ }
117
+
118
+ public void deleteSnippet (Snippet snippet ) throws GitLabApiException {
119
+ SnippetsApi api = gitLabApi .getSnippetApi ();
120
+ api .deleteSnippet (snippet .getId ());
121
+ }
122
+
123
+ public Snippet createSnippet (Snippet snippet ) throws GitLabApiException {
124
+ SnippetsApi api = gitLabApi .getSnippetApi ();
125
+ return api .createSnippet (snippet .getTitle (), snippet .getFileName (), snippet .getContent (),
126
+ snippet .getVisibility (), snippet .getDescription ());
127
+ }
128
+
144
129
}
0 commit comments