23
23
24
24
package org .gitlab4j .api ;
25
25
26
- import org .gitlab4j .api .GitLabApi .ApiVersion ;
27
- import org .gitlab4j .api .models .*;
28
- import org .glassfish .jersey .internal .guava .Lists ;
29
- import org .junit .*;
30
- import org .junit .runners .MethodSorters ;
26
+ import static org .junit .Assert .assertEquals ;
27
+ import static org .junit .Assert .assertNotNull ;
28
+ import static org .junit .Assume .assumeTrue ;
31
29
32
- import javax .ws .rs .core .Response ;
33
30
import java .util .Arrays ;
34
31
import java .util .List ;
35
- import java .util .Map ;
36
- import java .util .Optional ;
37
32
38
- import static org .junit .Assert .*;
39
- import static org .junit .Assume .assumeTrue ;
33
+ import org .gitlab4j .api .GitLabApi .ApiVersion ;
34
+ import org .gitlab4j .api .models .Project ;
35
+ import org .gitlab4j .api .models .Runner ;
36
+ import org .gitlab4j .api .models .RunnerDetail ;
37
+ import org .junit .Before ;
38
+ import org .junit .BeforeClass ;
39
+ import org .junit .FixMethodOrder ;
40
+ import org .junit .Test ;
41
+ import org .junit .runners .MethodSorters ;
40
42
41
43
/**
42
44
* In order for these tests to run you must set the following properties in ~/test-gitlab4j.properties
43
45
* <p>
44
46
* TEST_NAMESPACE
45
- * TEST_PROJECT_NAME
46
47
* TEST_HOST_URL
47
48
* TEST_PRIVATE_TOKEN
48
- * TEST_GROUP_PROJECT
49
49
* <p>
50
50
* If any of the above are NULL, all tests in this class will be skipped.
51
51
* <p>
@@ -56,24 +56,15 @@ public class TestRunnersApi {
56
56
57
57
// The following needs to be set to your test repository
58
58
private static final String TEST_NAMESPACE ;
59
- private static final String TEST_PROJECT_NAME ;
60
59
private static final String TEST_HOST_URL ;
61
60
private static final String TEST_PRIVATE_TOKEN ;
62
- private static final String TEST_GROUP ;
63
- private static final String TEST_GROUP_PROJECT ;
64
61
65
62
static {
66
63
TEST_NAMESPACE = TestUtils .getProperty ("TEST_NAMESPACE" );
67
- TEST_PROJECT_NAME = TestUtils .getProperty ("TEST_PROJECT_NAME" );
68
64
TEST_HOST_URL = TestUtils .getProperty ("TEST_HOST_URL" );
69
65
TEST_PRIVATE_TOKEN = TestUtils .getProperty ("TEST_PRIVATE_TOKEN" );
70
- TEST_GROUP = TestUtils .getProperty ("TEST_GROUP" );
71
- TEST_GROUP_PROJECT = TestUtils .getProperty ("TEST_GROUP_PROJECT" );
72
66
}
73
67
74
- private static final String TEST_PROJECT_NAME_1 = "test-gitlab4j-create-project" ;
75
- private static final String TEST_PROJECT_NAME_2 = "test-gitlab4j-create-project-2" ;
76
- private static final String TEST_PROJECT_NAME_UPDATE = "test-gitlab4j-create-project-update" ;
77
68
private static GitLabApi gitLabApi ;
78
69
79
70
public TestRunnersApi () {
@@ -112,34 +103,25 @@ public static void setup() throws GitLabApiException {
112
103
}
113
104
114
105
allRunners = gitLabApi .getRunnersApi ().getAllRunners ();
115
-
116
106
assertEquals (0 , allRunners .size ());
117
107
}
118
-
119
108
}
120
109
121
110
/**
122
111
* creates a new runner for a random project
123
112
*/
124
- private static void createRunner () throws GitLabApiException {
113
+ private static Runner createRunner () throws GitLabApiException {
125
114
126
- // WHEN
127
115
Project project = gitLabApi .getProjectApi ().getProjects ().get (0 );
128
116
project = gitLabApi .getProjectApi ().getProject (project .getId ());
129
117
String runnersToken = project .getRunnersToken ();
130
118
131
- // THEN
132
- gitLabApi .getRunnersApi ().registerRunner (runnersToken ,
119
+ return (gitLabApi .getRunnersApi ().registerRunner (runnersToken ,
133
120
"Junit registered runner" , true ,
134
121
Arrays .asList ("wow" ), false ,
135
- false , null );
136
-
137
- // ASSERT
138
- List <Runner > allRunners = gitLabApi .getRunnersApi ().getAllRunners ();
139
-
122
+ false , null ));
140
123
}
141
124
142
-
143
125
@ Before
144
126
public void beforeMethod () throws GitLabApiException {
145
127
assumeTrue (gitLabApi != null );
@@ -150,42 +132,34 @@ public void beforeMethod() throws GitLabApiException {
150
132
RunnerDetail runnerDetail = gitLabApi .getRunnersApi ().getRunnerDetail (runner .getId ());
151
133
gitLabApi .getRunnersApi ().deleteRunner (runnerDetail .getToken ());
152
134
}
153
-
154
135
}
155
136
156
137
@ Test
157
138
public void shouldHaveRunnerDetails () throws GitLabApiException {
158
139
159
- createRunner ();
140
+ assertNotNull ( "Runner was not created" , createRunner () );
160
141
161
142
List <Runner > runners = gitLabApi .getRunnersApi ().getAllRunners ();
162
-
163
143
assertEquals (1 , runners .size ());
164
144
assertNotNull ("Description should not be null" , runners .get (0 ).getDescription ());
165
-
166
145
}
167
146
168
147
@ Test
169
148
public void shouldDeleteRunner () throws GitLabApiException {
170
149
171
- createRunner ();
172
- createRunner ();
173
- createRunner ();
150
+ assertNotNull ( "Runner was not created" , createRunner () );
151
+ assertNotNull ( "Runner was not created" , createRunner () );
152
+ assertNotNull ( "Runner was not created" , createRunner () );
174
153
175
154
List <Runner > allRunners = gitLabApi .getRunnersApi ().getAllRunners ();
176
155
assertEquals (3 , allRunners .size ());
177
156
178
-
179
157
for (Runner runner : allRunners ) {
180
158
RunnerDetail runnerDetail = gitLabApi .getRunnersApi ().getRunnerDetail (runner .getId ());
181
159
gitLabApi .getRunnersApi ().deleteRunner (runnerDetail .getToken ());
182
160
}
183
161
184
162
allRunners = gitLabApi .getRunnersApi ().getAllRunners ();
185
163
assertEquals (0 , allRunners .size ());
186
-
187
-
188
164
}
189
-
190
-
191
165
}
0 commit comments