Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
44837b9a
Commit
44837b9a
authored
7 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Added test for createFile() and deleteFile().
parent
0d9ad6fa
main
5.0.x
5.0.x.jdk17
6.x
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/org/gitlab4j/api/TestRepositoryApi.java
+29
-1
src/test/java/org/gitlab4j/api/TestRepositoryApi.java
with
29 additions
and
1 deletion
+29
-1
src/test/java/org/gitlab4j/api/TestRepositoryApi.java
+
29
-
1
View file @
44837b9a
...
...
@@ -18,6 +18,7 @@ import org.gitlab4j.api.models.Branch;
import
org.gitlab4j.api.models.Commit
;
import
org.gitlab4j.api.models.CompareResults
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.RepositoryFile
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
...
...
@@ -53,6 +54,7 @@ public class TestRepositoryApi {
}
private
static
final
String
TEST_BRANCH_NAME
=
"feature/test_branch"
;
private
static
final
String
TEST_FILEPATH
=
"test-file.txt"
;
private
static
GitLabApi
gitLabApi
;
public
TestRepositoryApi
()
{
...
...
@@ -80,7 +82,7 @@ public class TestRepositoryApi {
}
if
(
problems
.
isEmpty
())
{
gitLabApi
=
new
GitLabApi
(
ApiVersion
.
V
4
,
TEST_HOST_URL
,
TEST_PRIVATE_TOKEN
);
gitLabApi
=
new
GitLabApi
(
ApiVersion
.
V
3
,
TEST_HOST_URL
,
TEST_PRIVATE_TOKEN
);
}
else
{
System
.
err
.
print
(
problems
);
}
...
...
@@ -92,7 +94,15 @@ public class TestRepositoryApi {
try
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
try
{
gitLabApi
.
getRepositoryFileApi
().
deleteFile
(
TEST_FILEPATH
,
project
.
getId
(),
TEST_BRANCH_NAME
,
"Cleanup test files."
);
}
catch
(
GitLabApiException
ignore
)
{
}
gitLabApi
.
getRepositoryApi
().
deleteBranch
(
project
.
getId
(),
TEST_BRANCH_NAME
);
}
catch
(
GitLabApiException
ignore
)
{
}
}
...
...
@@ -202,4 +212,22 @@ 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
testCreateAndDeleteFile
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
Branch
branch
=
gitLabApi
.
getRepositoryApi
().
createBranch
(
project
.
getId
(),
TEST_BRANCH_NAME
,
"master"
);
assertNotNull
(
branch
);
RepositoryFile
file
=
new
RepositoryFile
();
file
.
setFilePath
(
TEST_FILEPATH
);
file
.
setContent
(
"This is a test file."
);
RepositoryFile
createdFile
=
gitLabApi
.
getRepositoryFileApi
().
createFile
(
file
,
project
.
getId
(),
TEST_BRANCH_NAME
,
"Testing createFile()."
);
assertNotNull
(
createdFile
);
gitLabApi
.
getRepositoryFileApi
().
deleteFile
(
TEST_FILEPATH
,
project
.
getId
(),
TEST_BRANCH_NAME
,
"Testing deleteFile()."
);
}
}
This diff is collapsed.
Click to expand it.
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
Menu
Explore
Projects
Groups
Snippets