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
b4f66d28
Commit
b4f66d28
authored
Oct 01, 2019
by
Greg Messner
Browse files
Added more tests for TodosApi (#441).
parent
85e273d6
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/gitlab4j/api/TestGitLabApiBeans.java
View file @
b4f66d28
...
@@ -89,6 +89,7 @@ import org.gitlab4j.api.models.Snippet;
...
@@ -89,6 +89,7 @@ import org.gitlab4j.api.models.Snippet;
import
org.gitlab4j.api.models.SshKey
;
import
org.gitlab4j.api.models.SshKey
;
import
org.gitlab4j.api.models.SystemHook
;
import
org.gitlab4j.api.models.SystemHook
;
import
org.gitlab4j.api.models.Tag
;
import
org.gitlab4j.api.models.Tag
;
import
org.gitlab4j.api.models.Todo
;
import
org.gitlab4j.api.models.TreeItem
;
import
org.gitlab4j.api.models.TreeItem
;
import
org.gitlab4j.api.models.Trigger
;
import
org.gitlab4j.api.models.Trigger
;
import
org.gitlab4j.api.models.User
;
import
org.gitlab4j.api.models.User
;
...
@@ -511,6 +512,12 @@ public class TestGitLabApiBeans {
...
@@ -511,6 +512,12 @@ public class TestGitLabApiBeans {
assertTrue
(
compareJson
(
sshKey
,
"sshkey.json"
));
assertTrue
(
compareJson
(
sshKey
,
"sshkey.json"
));
}
}
@Test
public
void
testTodos
()
throws
Exception
{
List
<
Todo
>
todos
=
unmarshalResourceList
(
Todo
.
class
,
"todos.json"
);
assertTrue
(
compareJson
(
todos
,
"todos.json"
));
}
@Test
@Test
public
void
testTree
()
throws
Exception
{
public
void
testTree
()
throws
Exception
{
List
<
TreeItem
>
tree
=
unmarshalResourceList
(
TreeItem
.
class
,
"tree.json"
);
List
<
TreeItem
>
tree
=
unmarshalResourceList
(
TreeItem
.
class
,
"tree.json"
);
...
...
src/test/java/org/gitlab4j/api/TestTodosApi.java
View file @
b4f66d28
/*
* The MIT License (MIT)
*
* Copyright (c) 2017 Greg Messner <greg@messners.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package
org.gitlab4j.api
;
package
org.gitlab4j.api
;
import
org.gitlab4j.api.Constants.TodoState
;
import
org.gitlab4j.api.models.Issue
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.Todo
;
import
org.gitlab4j.api.models.Todo
;
import
org.gitlab4j.api.models.User
;
import
org.junit.AfterClass
;
import
org.junit.Before
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.experimental.categories.Category
;
import
org.junit.experimental.categories.Category
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Random
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assume
.
assumeNotNull
;
import
static
org
.
junit
.
Assume
.
assumeNotNull
;
...
@@ -46,6 +29,11 @@ import static org.junit.Assume.assumeNotNull;
...
@@ -46,6 +29,11 @@ import static org.junit.Assume.assumeNotNull;
public
class
TestTodosApi
extends
AbstractIntegrationTest
{
public
class
TestTodosApi
extends
AbstractIntegrationTest
{
private
static
GitLabApi
gitLabApi
;
private
static
GitLabApi
gitLabApi
;
private
static
Project
testProject
;
private
static
final
String
ISSUE_TITLE
=
"Test Issue Title for Todo"
;
private
static
final
String
ISSUE_DESCRIPTION
=
"This is a really nice todo description, not."
;
private
static
Random
randomNumberGenerator
=
new
Random
();
public
TestTodosApi
()
{
public
TestTodosApi
()
{
super
();
super
();
...
@@ -53,8 +41,35 @@ public class TestTodosApi extends AbstractIntegrationTest {
...
@@ -53,8 +41,35 @@ public class TestTodosApi extends AbstractIntegrationTest {
@BeforeClass
@BeforeClass
public
static
void
setup
()
{
public
static
void
setup
()
{
// Must setup the connection to the GitLab test server and get the test Project instance
// Must setup the connection to the GitLab test server and get the test Project instance
gitLabApi
=
baseTestSetup
();
gitLabApi
=
baseTestSetup
();
testProject
=
getTestProject
();
deleteAllTestIssues
();
}
@AfterClass
public
static
void
teardown
()
throws
GitLabApiException
{
deleteAllTestIssues
();
}
private
static
void
deleteAllTestIssues
()
{
if
(
gitLabApi
!=
null
)
{
try
{
List
<
Issue
>
issues
=
gitLabApi
.
getIssuesApi
().
getIssues
(
testProject
.
getId
());
if
(
issues
!=
null
)
{
for
(
Issue
issue
:
issues
)
{
if
(
issue
.
getTitle
().
startsWith
(
ISSUE_TITLE
))
{
gitLabApi
.
getIssuesApi
().
deleteIssue
(
testProject
.
getId
(),
issue
.
getIid
());
}
}
}
}
catch
(
GitLabApiException
ignore
)
{
}
}
}
}
@Before
@Before
...
@@ -62,19 +77,77 @@ public class TestTodosApi extends AbstractIntegrationTest {
...
@@ -62,19 +77,77 @@ public class TestTodosApi extends AbstractIntegrationTest {
assumeNotNull
(
gitLabApi
);
assumeNotNull
(
gitLabApi
);
}
}
private
static
String
getUniqueTitle
()
{
return
(
ISSUE_TITLE
+
" - "
+
(
randomNumberGenerator
.
nextInt
()
+
1
));
}
@Test
@Test
public
void
testGetTodos
()
throws
GitLabApiException
{
public
void
testGetTodos
()
throws
GitLabApiException
{
List
<
Todo
>
todos
=
gitLabApi
.
getTodosApi
().
getTodos
();
assertNotNull
(
todos
);
Issue
issue
=
gitLabApi
.
getIssuesApi
().
createIssue
(
testProject
,
getUniqueTitle
(),
ISSUE_DESCRIPTION
);
User
currentUser
=
gitLabApi
.
getUserApi
().
getCurrentUser
();
gitLabApi
.
getIssuesApi
().
assignIssue
(
testProject
,
issue
.
getIid
(),
currentUser
.
getId
());
List
<
Todo
>
todos
=
gitLabApi
.
getTodosApi
().
getPendingTodos
();
assertTrue
(
todos
.
size
()
>
0
);
boolean
found
=
false
;
for
(
Todo
todo
:
todos
)
{
if
(
todo
.
isIssueTodo
()
&&
((
Issue
)
todo
.
getTarget
()).
getIid
().
intValue
()
==
issue
.
getIid
())
{
found
=
true
;
break
;
}
}
assertTrue
(
found
);
}
}
@Test
@Test
public
void
testMarkAsDone
()
throws
GitLabApiException
{
public
void
testMarkAllAsDone
()
throws
GitLabApiException
{
gitLabApi
.
getTodosApi
().
markAsDone
();
Issue
issue
=
gitLabApi
.
getIssuesApi
().
createIssue
(
testProject
,
getUniqueTitle
(),
ISSUE_DESCRIPTION
);
User
currentUser
=
gitLabApi
.
getUserApi
().
getCurrentUser
();
gitLabApi
.
getIssuesApi
().
assignIssue
(
testProject
,
issue
.
getIid
(),
currentUser
.
getId
());
List
<
Todo
>
todos
=
gitLabApi
.
getTodosApi
().
getPendingTodos
();
assertTrue
(
todos
.
size
()
>
0
);
List
<
Todo
>
todos
=
gitLabApi
.
getTodosApi
().
getTodos
();
gitLabApi
.
getTodosApi
().
markAllAsDone
();
todos
=
gitLabApi
.
getTodosApi
().
getPendingTodos
();
assertNotNull
(
todos
);
assertNotNull
(
todos
);
assertEquals
(
0
,
todos
.
size
());
assertEquals
(
0
,
todos
.
size
());
}
}
@Test
public
void
testMarkAsDone
()
throws
GitLabApiException
{
Issue
issue
=
gitLabApi
.
getIssuesApi
().
createIssue
(
testProject
,
getUniqueTitle
(),
ISSUE_DESCRIPTION
);
User
currentUser
=
gitLabApi
.
getUserApi
().
getCurrentUser
();
gitLabApi
.
getIssuesApi
().
assignIssue
(
testProject
,
issue
.
getIid
(),
currentUser
.
getId
());
List
<
Todo
>
todos
=
gitLabApi
.
getTodosApi
().
getPendingTodos
();
assertTrue
(
todos
.
size
()
>
0
);
Integer
foundId
=
null
;
for
(
Todo
todo
:
todos
)
{
if
(
todo
.
isIssueTodo
()
&&
((
Issue
)
todo
.
getTarget
()).
getIid
().
intValue
()
==
issue
.
getIid
())
{
foundId
=
todo
.
getId
();
break
;
}
}
assertNotNull
(
foundId
);
gitLabApi
.
getTodosApi
().
markAsDone
(
foundId
);
todos
=
gitLabApi
.
getTodosApi
().
getDoneTodos
();
assertTrue
(
todos
.
size
()
>
0
);
foundId
=
null
;
for
(
Todo
todo
:
todos
)
{
if
(
todo
.
getState
()
==
TodoState
.
DONE
&&
todo
.
isIssueTodo
()
&&
((
Issue
)
todo
.
getTarget
()).
getIid
().
intValue
()
==
issue
.
getIid
())
{
foundId
=
todo
.
getId
();
break
;
}
}
assertNotNull
(
foundId
);
}
}
}
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