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
b3586980
Commit
b3586980
authored
Sep 23, 2017
by
Greg Messner
Browse files
Fixed expected responses for duration related methods.
parent
b1f9763e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/IssuesApi.java
View file @
b3586980
...
@@ -349,7 +349,7 @@ public class IssuesApi extends AbstractApi implements Constants {
...
@@ -349,7 +349,7 @@ public class IssuesApi extends AbstractApi implements Constants {
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"duration"
,
duration
,
true
);
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"duration"
,
duration
,
true
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
.
asMap
(),
"projects"
,
projectId
,
"issues"
,
issueIid
,
"time_estimate"
);
Response
response
=
post
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"issues"
,
issueIid
,
"time_estimate"
);
return
(
response
.
readEntity
(
TimeStats
.
class
));
return
(
response
.
readEntity
(
TimeStats
.
class
));
}
}
...
...
src/test/java/org/gitlab4j/api/TestIssuesApi.java
View file @
b3586980
...
@@ -36,6 +36,7 @@ import javax.ws.rs.core.Response;
...
@@ -36,6 +36,7 @@ import javax.ws.rs.core.Response;
import
org.gitlab4j.api.Constants.IssueState
;
import
org.gitlab4j.api.Constants.IssueState
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.Duration
;
import
org.gitlab4j.api.models.Issue
;
import
org.gitlab4j.api.models.Issue
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.TimeStats
;
import
org.gitlab4j.api.models.TimeStats
;
...
@@ -71,12 +72,11 @@ public class TestIssuesApi {
...
@@ -71,12 +72,11 @@ public class TestIssuesApi {
private
static
GitLabApi
gitLabApi
;
private
static
GitLabApi
gitLabApi
;
private
static
Project
testProject
;
private
static
Project
testProject
;
private
static
final
String
ISSUE_TITLE
=
"Test Issue Title"
;
private
static
final
String
ISSUE_TITLE
=
"Test Issue Title"
;
private
static
final
String
ISSUE_DESCRIPTION
=
"This is a really nice description, not."
;
private
static
final
String
ISSUE_DESCRIPTION
=
"This is a really nice description, not."
;
private
static
Random
randomNumberGenerator
=
new
Random
();
private
static
Random
randomNumberGenerator
=
new
Random
();
public
TestIssuesApi
()
{
public
TestIssuesApi
()
{
super
();
super
();
}
}
...
@@ -99,12 +99,12 @@ public class TestIssuesApi {
...
@@ -99,12 +99,12 @@ public class TestIssuesApi {
if
(
problems
.
isEmpty
())
{
if
(
problems
.
isEmpty
())
{
gitLabApi
=
new
GitLabApi
(
ApiVersion
.
V4
,
TEST_HOST_URL
,
TEST_PRIVATE_TOKEN
);
gitLabApi
=
new
GitLabApi
(
ApiVersion
.
V4
,
TEST_HOST_URL
,
TEST_PRIVATE_TOKEN
);
try
{
try
{
testProject
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
testProject
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
}
catch
(
GitLabApiException
gle
)
{
}
catch
(
GitLabApiException
gle
)
{
}
}
}
else
{
}
else
{
System
.
err
.
print
(
problems
);
System
.
err
.
print
(
problems
);
}
}
...
@@ -128,14 +128,15 @@ public class TestIssuesApi {
...
@@ -128,14 +128,15 @@ public class TestIssuesApi {
try
{
try
{
List
<
Issue
>
issues
=
gitLabApi
.
getIssuesApi
().
getIssues
(
testProject
.
getId
());
List
<
Issue
>
issues
=
gitLabApi
.
getIssuesApi
().
getIssues
(
testProject
.
getId
());
if
(
issues
!=
null
)
{
if
(
issues
!=
null
)
{
for
(
Issue
issue
:
issues
)
{
for
(
Issue
issue
:
issues
)
{
if
(
issue
.
getTitle
().
startsWith
(
ISSUE_TITLE
))
{
if
(
issue
.
getTitle
().
startsWith
(
ISSUE_TITLE
))
{
gitLabApi
.
getIssuesApi
().
deleteIssue
(
testProject
.
getId
(),
issue
.
getIid
());
gitLabApi
.
getIssuesApi
().
deleteIssue
(
testProject
.
getId
(),
issue
.
getIid
());
}
}
}
}
}
}
}
catch
(
GitLabApiException
ignore
)
{}
}
catch
(
GitLabApiException
ignore
)
{
}
}
}
}
}
...
@@ -216,9 +217,10 @@ public class TestIssuesApi {
...
@@ -216,9 +217,10 @@ public class TestIssuesApi {
assertEquals
(
Response
.
Status
.
NOT_FOUND
.
getStatusCode
(),
gle
.
getHttpStatus
());
assertEquals
(
Response
.
Status
.
NOT_FOUND
.
getStatusCode
(),
gle
.
getHttpStatus
());
}
}
}
}
/**
/**
* Simplify creation of issues
* Simplify creation of issues
*
* @return
* @return
* @throws GitLabApiException
* @throws GitLabApiException
*/
*/
...
@@ -226,62 +228,72 @@ public class TestIssuesApi {
...
@@ -226,62 +228,72 @@ public class TestIssuesApi {
Integer
projectId
=
testProject
.
getId
();
Integer
projectId
=
testProject
.
getId
();
String
title
=
getUniqueTitle
();
String
title
=
getUniqueTitle
();
Issue
issue
=
gitLabApi
.
getIssuesApi
().
createIssue
(
projectId
,
title
,
ISSUE_DESCRIPTION
);
Issue
issue
=
gitLabApi
.
getIssuesApi
().
createIssue
(
projectId
,
title
,
ISSUE_DESCRIPTION
);
return
issue
;
return
issue
;
}
}
@Test
@Test
public
void
testGetTimeTrackingStats
()
throws
GitLabApiException
{
public
void
testGetTimeTrackingStats
()
throws
GitLabApiException
{
Issue
issue
=
ensureIssue
();
Issue
issue
=
ensureIssue
();
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
getTimeTrackingStats
(
issue
.
getProjectId
(),
issue
.
getIid
());
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
getTimeTrackingStats
(
issue
.
getProjectId
(),
issue
.
getIid
());
assertEquals
(
new
Integer
(
0
),
timeStats
.
getTimeEstimate
());
assertEquals
(
new
Integer
(
0
),
timeStats
.
getTimeEstimate
());
assertEquals
(
new
Integer
(
0
),
timeStats
.
getTotalTimeSpent
());
assertEquals
(
new
Integer
(
0
),
timeStats
.
getTotalTimeSpent
());
}
}
/**
/**
* Expect the given {@link TimeStats} object to have the values
* Expect the given {@link TimeStats} object to have the values
*
* @param timeStats
* @param timeStats
* @param timeEstimate
* @param timeEstimate
* @param totalTimeSpent
* @param totalTimeSpent
*/
*/
private
void
assertTimeStats
(
TimeStats
timeStats
,
int
timeEstimate
,
int
totalTimeSpent
)
{
private
void
assertTimeStats
(
TimeStats
timeStats
,
int
timeEstimate
,
int
totalTimeSpent
)
{
assertEquals
(
new
Integer
(
timeEstimate
),
timeStats
.
getTimeEstimate
());
assertEquals
(
new
Integer
(
timeEstimate
),
timeStats
.
getTimeEstimate
());
assertEquals
(
new
Integer
(
totalTimeSpent
),
timeStats
.
getTotalTimeSpent
());
assertEquals
(
new
Integer
(
totalTimeSpent
),
timeStats
.
getTotalTimeSpent
());
}
}
@Test
@Test
public
void
testEstimateTime
()
throws
GitLabApiException
{
public
void
testEstimateTime
()
throws
GitLabApiException
{
Issue
issue
=
ensureIssue
();
Issue
issue
=
ensureIssue
();
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
estimateTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
"1h"
);
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
estimateTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
"1h"
);
assertTimeStats
(
timeStats
,
(
60
/* seconds */
*
60
/* minutes */
),
0
);
assertTimeStats
(
timeStats
,
(
60
/* seconds */
*
60
/* minutes */
),
0
);
timeStats
=
gitLabApi
.
getIssuesApi
().
estimateTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
60
*
60
);
assertTimeStats
(
timeStats
,
(
60
/* seconds */
*
60
/* minutes */
),
0
);
timeStats
=
gitLabApi
.
getIssuesApi
().
estimateTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
new
Duration
(
60
*
60
));
assertTimeStats
(
timeStats
,
(
60
/* seconds */
*
60
/* minutes */
),
0
);
}
}
@Test
@Test
public
void
testResetEstimatedTime
()
throws
GitLabApiException
{
public
void
testResetEstimatedTime
()
throws
GitLabApiException
{
Issue
issue
=
ensureIssue
();
Issue
issue
=
ensureIssue
();
gitLabApi
.
getIssuesApi
().
estimateTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
"1h"
);
gitLabApi
.
getIssuesApi
().
estimateTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
"1h"
);
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
resetEstimatedTime
(
issue
.
getProjectId
(),
issue
.
getIid
());
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
resetEstimatedTime
(
issue
.
getProjectId
(),
issue
.
getIid
());
assertTimeStats
(
timeStats
,
0
,
0
);
assertTimeStats
(
timeStats
,
0
,
0
);
}
}
@Test
@Test
public
void
testAddSpentTime
()
throws
GitLabApiException
{
public
void
testAddSpentTime
()
throws
GitLabApiException
{
Issue
issue
=
ensureIssue
();
Issue
issue
=
ensureIssue
();
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
addSpentTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
"1h"
);
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
addSpentTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
"1h"
);
assertTimeStats
(
timeStats
,
0
,
(
60
/* seconds */
*
60
/* minutes */
));
assertTimeStats
(
timeStats
,
0
,
(
60
/* seconds */
*
60
/* minutes */
));
timeStats
=
gitLabApi
.
getIssuesApi
().
addSpentTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
60
*
60
);
assertTimeStats
(
timeStats
,
0
,
60
*
60
*
2
);
timeStats
=
gitLabApi
.
getIssuesApi
().
addSpentTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
new
Duration
(
60
*
60
));
assertTimeStats
(
timeStats
,
0
,
60
*
60
*
3
);
}
}
@Test
@Test
public
void
testResetSpentTime
()
throws
GitLabApiException
{
public
void
testResetSpentTime
()
throws
GitLabApiException
{
Issue
issue
=
ensureIssue
();
Issue
issue
=
ensureIssue
();
gitLabApi
.
getIssuesApi
().
addSpentTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
"1h"
);
gitLabApi
.
getIssuesApi
().
addSpentTime
(
issue
.
getProjectId
(),
issue
.
getIid
(),
"1h"
);
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
resetSpentTime
(
issue
.
getProjectId
(),
issue
.
getIid
());
TimeStats
timeStats
=
gitLabApi
.
getIssuesApi
().
resetSpentTime
(
issue
.
getProjectId
(),
issue
.
getIid
());
assertTimeStats
(
timeStats
,
0
,
0
);
assertTimeStats
(
timeStats
,
0
,
0
);
}
}
}
}
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