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
b46754c4
Commit
b46754c4
authored
Sep 17, 2017
by
Greg Messner
Browse files
Added more get commits by path tests.
parent
7ea980e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/TestCommitsApi.java
View file @
b46754c4
...
...
@@ -2,12 +2,15 @@ package org.gitlab4j.api;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
java.util.Date
;
import
java.util.List
;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.Comment
;
import
org.gitlab4j.api.models.Commit
;
...
...
@@ -37,6 +40,7 @@ public class TestCommitsApi {
private
static
final
String
TEST_NAMESPACE
;
private
static
final
String
TEST_HOST_URL
;
private
static
final
String
TEST_PRIVATE_TOKEN
;
private
static
final
String
TEST_PROJECT_SUBDIRECTORY_PATH
=
"src/main/docs/test-project.txt"
;
static
{
TEST_NAMESPACE
=
TestUtils
.
getProperty
(
"TEST_NAMESPACE"
);
TEST_PROJECT_NAME
=
TestUtils
.
getProperty
(
"TEST_PROJECT_NAME"
);
...
...
@@ -148,14 +152,51 @@ public class TestCommitsApi {
assertTrue
(
pager
.
getTotalItems
()
>
0
);
}
@Test
public
void
testCommitsSinceWithPath
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
List
<
Commit
>
commits
=
gitLabApi
.
getCommitsApi
().
getCommits
(
project
.
getId
(),
null
,
new
Date
(
0
),
new
Date
(),
TEST_PROJECT_SUBDIRECTORY_PATH
);
assertNotNull
(
commits
);
assertTrue
(
commits
.
size
()
>
0
);
}
@Test
public
void
testCommitsByPath
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
CommitsApi
commitsApi
=
gitLabApi
.
getCommitsApi
();
List
<
Commit
>
commits
=
commitsApi
.
getCommits
(
project
.
getId
(),
"master"
,
"README"
);
List
<
Commit
>
commits
=
commitsApi
.
getCommits
(
project
.
getId
(),
"master"
,
null
);
assertNotNull
(
commits
);
assertTrue
(
commits
.
size
()
>
0
);
commits
=
commitsApi
.
getCommits
(
project
.
getId
(),
"master"
,
"README"
);
assertNotNull
(
commits
);
assertTrue
(
commits
.
size
()
>
0
);
commitsApi
=
gitLabApi
.
getCommitsApi
();
commits
=
commitsApi
.
getCommits
(
project
.
getId
(),
"master"
,
"README.md"
);
assertNotNull
(
commits
);
assertTrue
(
commits
.
size
()
>
0
);
commits
=
commitsApi
.
getCommits
(
project
.
getId
(),
"master"
,
TEST_PROJECT_SUBDIRECTORY_PATH
);
assertNotNull
(
commits
);
assertTrue
(
commits
.
size
()
>
0
);
}
@Test
public
void
testCommitsByPathNotFound
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
try
{
List
<
Commit
>
commits
=
gitLabApi
.
getCommitsApi
().
getCommits
(
project
.
getId
(),
"master"
,
"this-file-does-not-exist.an-extension"
);
assertTrue
(
commits
==
null
||
commits
.
isEmpty
());
}
catch
(
GitLabApiException
gle
)
{
assertEquals
(
Response
.
Status
.
NOT_FOUND
,
gle
.
getHttpStatus
());
}
}
}
\ No newline at end of file
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