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
19094fcd
"main1/main_text2.py" did not exist on "4d0445e26af1f7cfe9aa49b3406bfbdea4950810"
Commit
19094fcd
authored
Jul 25, 2018
by
Greg Messner
Browse files
Moved RepositoryFileApi tests into their own test class (#224).
parent
09d6df53
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/TestRepositoryApi.java
View file @
19094fcd
...
...
@@ -18,7 +18,6 @@ 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
;
...
...
@@ -56,7 +55,6 @@ 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
;
public
TestRepositoryApi
()
{
...
...
@@ -98,11 +96,6 @@ 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
)
{
}
try
{
gitLabApi
.
getRepositoryApi
().
deleteBranch
(
project
.
getId
(),
TEST_BRANCH_NAME
);
}
catch
(
GitLabApiException
ignore
)
{
...
...
@@ -172,46 +165,6 @@ public class TestRepositoryApi {
file
.
delete
();
}
@Test
public
void
testRawFileViaFile
()
throws
GitLabApiException
,
IOException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
File
file
=
gitLabApi
.
getRepositoryFileApi
().
getRawFile
(
project
.
getId
(),
"master"
,
"README"
,
null
);
assertTrue
(
file
.
length
()
>
0
);
file
.
delete
();
file
=
gitLabApi
.
getRepositoryFileApi
().
getRawFile
(
project
.
getId
(),
"master"
,
"README"
,
new
File
(
"."
));
assertTrue
(
file
.
length
()
>
0
);
file
.
delete
();
}
@Test
public
void
testRepositoryFileViaInputStream
()
throws
GitLabApiException
,
IOException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
InputStream
in
=
gitLabApi
.
getRepositoryFileApi
().
getRawFile
(
project
.
getId
(),
"master"
,
"README"
);
Path
target
=
Files
.
createTempFile
(
TEST_PROJECT_NAME
+
"-README"
,
""
);
Files
.
copy
(
in
,
target
,
StandardCopyOption
.
REPLACE_EXISTING
);
assertTrue
(
target
.
toFile
().
length
()
>
0
);
Files
.
delete
(
target
);
}
@Test
public
void
testRepositoryFileGetFile
()
throws
GitLabApiException
,
IOException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
RepositoryFile
fileInfo
=
gitLabApi
.
getRepositoryFileApi
().
getFileInfo
(
project
.
getId
(),
"README"
,
"master"
);
assertNotNull
(
fileInfo
);
}
@Test
public
void
testCompare
()
throws
GitLabApiException
{
...
...
@@ -230,36 +183,6 @@ public class TestRepositoryApi {
assertNotNull
(
compareResults
);
}
@Test
public
void
testCreateFileAndDeleteFile
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
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()."
);
}
@Test
public
void
testCreateFileWithEmptyContent
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
RepositoryFile
file
=
new
RepositoryFile
();
file
.
setFilePath
(
TEST_FILEPATH
);
file
.
setContent
(
""
);
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()."
);
}
@Test
public
void
testProtectBranch
()
throws
GitLabApiException
{
...
...
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