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
3c710091
Commit
3c710091
authored
Feb 18, 2017
by
Greg Messner
Browse files
Added tests for getRepositoryArchive().
parent
194821f1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/com/messners/gitlab/api/TestGitLabApi.java
View file @
3c710091
...
@@ -4,6 +4,12 @@ import static org.junit.Assert.assertTrue;
...
@@ -4,6 +4,12 @@ import static org.junit.Assert.assertTrue;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.StandardCopyOption
;
import
java.util.List
;
import
java.util.List
;
import
org.junit.AfterClass
;
import
org.junit.AfterClass
;
...
@@ -22,11 +28,11 @@ import com.messners.gitlab.api.models.Project;
...
@@ -22,11 +28,11 @@ import com.messners.gitlab.api.models.Project;
* TEST_HOST_URL
* TEST_HOST_URL
* TEST_PRIVATE_TOKEN
* TEST_PRIVATE_TOKEN
*
*
* If any of the above are NULL, all tests in this class will be skipped.
If running from mvn simply
* If any of the above are NULL, all tests in this class will be skipped. If running from mvn simply
* use a command line similar to:
* use a command line similar to:
*
*
* mvn test -DTEST_PRIVATE_TOKEN=your_private_token -DTEST_HOST_URL=https://gitlab.com \
* mvn test -DTEST_PRIVATE_TOKEN=your_private_token -DTEST_HOST_URL=https://gitlab.com \
*
-DTEST_NAMESPACE=your_namespace -DTEST_PROJECT_NAME=test-project
* -DTEST_NAMESPACE=your_namespace -DTEST_PROJECT_NAME=test-project
*
*
*/
*/
public
class
TestGitLabApi
{
public
class
TestGitLabApi
{
...
@@ -80,8 +86,11 @@ public class TestGitLabApi {
...
@@ -80,8 +86,11 @@ public class TestGitLabApi {
@AfterClass
@AfterClass
public
static
void
teardown
()
throws
GitLabApiException
{
public
static
void
teardown
()
throws
GitLabApiException
{
if
(
gitLabApi
!=
null
)
{
if
(
gitLabApi
!=
null
)
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
try
{
gitLabApi
.
getRepositoryApi
().
deleteBranch
(
project
.
getId
(),
TEST_BRANCH_NAME
);
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
gitLabApi
.
getRepositoryApi
().
deleteBranch
(
project
.
getId
(),
TEST_BRANCH_NAME
);
}
catch
(
GitLabApiException
ignore
)
{
}
}
}
}
}
...
@@ -110,4 +119,34 @@ public class TestGitLabApi {
...
@@ -110,4 +119,34 @@ public class TestGitLabApi {
Branch
branch
=
gitLabApi
.
getRepositoryApi
().
createBranch
(
project
.
getId
(),
TEST_BRANCH_NAME
,
"master"
);
Branch
branch
=
gitLabApi
.
getRepositoryApi
().
createBranch
(
project
.
getId
(),
TEST_BRANCH_NAME
,
"master"
);
assertNotNull
(
branch
);
assertNotNull
(
branch
);
}
}
@Test
public
void
testRepositoryArchiveViaInputStream
()
throws
GitLabApiException
,
IOException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
InputStream
in
=
gitLabApi
.
getRepositoryApi
().
getRepositoryArchive
(
project
.
getId
(),
"master"
);
Path
target
=
Files
.
createTempFile
(
TEST_PROJECT_NAME
+
"-"
,
".tar.gz"
);
Files
.
copy
(
in
,
target
,
StandardCopyOption
.
REPLACE_EXISTING
);
assertTrue
(
target
.
toFile
().
length
()
>
0
);
Files
.
delete
(
target
);
}
@Test
public
void
testRepositoryArchiveViaFile
()
throws
GitLabApiException
,
IOException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
File
file
=
gitLabApi
.
getRepositoryApi
().
getRepositoryArchive
(
project
.
getId
(),
"master"
,
null
);
assertTrue
(
file
.
length
()
>
0
);
file
.
delete
();
file
=
gitLabApi
.
getRepositoryApi
().
getRepositoryArchive
(
project
.
getId
(),
"master"
,
new
File
(
"."
));
assertTrue
(
file
.
length
()
>
0
);
file
.
delete
();
}
}
}
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