1
1
package org .gitlab4j .api ;
2
2
3
3
import static org .junit .Assert .assertEquals ;
4
+ import static org .junit .Assert .assertFalse ;
4
5
import static org .junit .Assert .assertNotNull ;
5
6
import static org .junit .Assert .assertTrue ;
6
7
import static org .junit .Assume .assumeTrue ;
@@ -54,6 +55,7 @@ public class TestRepositoryApi {
54
55
}
55
56
56
57
private static final String TEST_BRANCH_NAME = "feature/test_branch" ;
58
+ private static final String TEST_PROTECT_BRANCH_NAME = "feature/protect_branch" ;
57
59
private static final String TEST_FILEPATH = "test-file.txt" ;
58
60
private static GitLabApi gitLabApi ;
59
61
@@ -100,8 +102,12 @@ public static void teardown() throws GitLabApiException {
100
102
} catch (GitLabApiException ignore ) {
101
103
}
102
104
103
- gitLabApi .getRepositoryApi ().deleteBranch (project .getId (), TEST_BRANCH_NAME );
104
-
105
+ try {
106
+ gitLabApi .getRepositoryApi ().deleteBranch (project .getId (), TEST_BRANCH_NAME );
107
+ } catch (GitLabApiException ignore ) {
108
+ }
109
+
110
+ gitLabApi .getRepositoryApi ().deleteBranch (project .getId (), TEST_PROTECT_BRANCH_NAME );
105
111
106
112
} catch (GitLabApiException ignore ) {
107
113
}
@@ -212,7 +218,7 @@ public void testCompare() throws GitLabApiException {
212
218
compareResults = gitLabApi .getRepositoryApi ().compare (TEST_NAMESPACE + "/" + TEST_PROJECT_NAME , commits .get (numCommits - 1 ).getId (), commits .get (numCommits - 2 ).getId ());
213
219
assertNotNull (compareResults );
214
220
}
215
-
221
+
216
222
@ Test
217
223
public void testCreateFileAndDeleteFile () throws GitLabApiException {
218
224
@@ -227,4 +233,22 @@ public void testCreateFileAndDeleteFile() throws GitLabApiException {
227
233
228
234
gitLabApi .getRepositoryFileApi ().deleteFile (TEST_FILEPATH , project .getId (), TEST_BRANCH_NAME , "Testing deleteFile()." );
229
235
}
236
+
237
+ @ Test
238
+ public void testProtectBranch () throws GitLabApiException {
239
+
240
+ Project project = gitLabApi .getProjectApi ().getProject (TEST_NAMESPACE , TEST_PROJECT_NAME );
241
+ assertNotNull (project );
242
+
243
+ Branch branch = gitLabApi .getRepositoryApi ().createBranch (project .getId (), TEST_PROTECT_BRANCH_NAME , "master" );
244
+ assertNotNull (branch );
245
+
246
+ Branch protectedBranch = gitLabApi .getRepositoryApi ().protectBranch (project .getId (), TEST_PROTECT_BRANCH_NAME );
247
+ assertNotNull (protectedBranch );
248
+ assertTrue (protectedBranch .getProtected ());
249
+
250
+ Branch unprotectedBranch = gitLabApi .getRepositoryApi ().unprotectBranch (project .getId (), TEST_PROTECT_BRANCH_NAME );
251
+ assertNotNull (unprotectedBranch );
252
+ assertFalse (unprotectedBranch .getProtected ());
253
+ }
230
254
}
0 commit comments