Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
0e33be2d
Commit
0e33be2d
authored
Nov 29, 2017
by
Greg Messner
Browse files
Added tests for protectBranch() and unprotectBranch() (#101)
parent
837e1ab3
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/TestRepositoryApi.java
View file @
0e33be2d
package
org.gitlab4j.api
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
...
...
@@ -54,6 +55,7 @@ public class TestRepositoryApi {
}
private
static
final
String
TEST_BRANCH_NAME
=
"feature/test_branch"
;
private
static
final
String
TEST_PROTECT_BRANCH_NAME
=
"feature/protect_branch"
;
private
static
final
String
TEST_FILEPATH
=
"test-file.txt"
;
private
static
GitLabApi
gitLabApi
;
...
...
@@ -100,8 +102,12 @@ public class TestRepositoryApi {
}
catch
(
GitLabApiException
ignore
)
{
}
gitLabApi
.
getRepositoryApi
().
deleteBranch
(
project
.
getId
(),
TEST_BRANCH_NAME
);
try
{
gitLabApi
.
getRepositoryApi
().
deleteBranch
(
project
.
getId
(),
TEST_BRANCH_NAME
);
}
catch
(
GitLabApiException
ignore
)
{
}
gitLabApi
.
getRepositoryApi
().
deleteBranch
(
project
.
getId
(),
TEST_PROTECT_BRANCH_NAME
);
}
catch
(
GitLabApiException
ignore
)
{
}
...
...
@@ -212,7 +218,7 @@ public class TestRepositoryApi {
compareResults
=
gitLabApi
.
getRepositoryApi
().
compare
(
TEST_NAMESPACE
+
"/"
+
TEST_PROJECT_NAME
,
commits
.
get
(
numCommits
-
1
).
getId
(),
commits
.
get
(
numCommits
-
2
).
getId
());
assertNotNull
(
compareResults
);
}
@Test
public
void
testCreateFileAndDeleteFile
()
throws
GitLabApiException
{
...
...
@@ -227,4 +233,22 @@ public class TestRepositoryApi {
gitLabApi
.
getRepositoryFileApi
().
deleteFile
(
TEST_FILEPATH
,
project
.
getId
(),
TEST_BRANCH_NAME
,
"Testing deleteFile()."
);
}
@Test
public
void
testProtectBranch
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
Branch
branch
=
gitLabApi
.
getRepositoryApi
().
createBranch
(
project
.
getId
(),
TEST_PROTECT_BRANCH_NAME
,
"master"
);
assertNotNull
(
branch
);
Branch
protectedBranch
=
gitLabApi
.
getRepositoryApi
().
protectBranch
(
project
.
getId
(),
TEST_PROTECT_BRANCH_NAME
);
assertNotNull
(
protectedBranch
);
assertTrue
(
protectedBranch
.
getProtected
());
Branch
unprotectedBranch
=
gitLabApi
.
getRepositoryApi
().
unprotectBranch
(
project
.
getId
(),
TEST_PROTECT_BRANCH_NAME
);
assertNotNull
(
unprotectedBranch
);
assertFalse
(
unprotectedBranch
.
getProtected
());
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment