Commit b4f66d28 authored by Greg Messner's avatar Greg Messner
Browse files

Added more tests for TodosApi (#441).

parent 85e273d6
......@@ -89,6 +89,7 @@ import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.SshKey;
import org.gitlab4j.api.models.SystemHook;
import org.gitlab4j.api.models.Tag;
import org.gitlab4j.api.models.Todo;
import org.gitlab4j.api.models.TreeItem;
import org.gitlab4j.api.models.Trigger;
import org.gitlab4j.api.models.User;
......@@ -511,6 +512,12 @@ public class TestGitLabApiBeans {
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
public void testTree() throws Exception {
List<TreeItem> tree = unmarshalResourceList(TreeItem.class, "tree.json");
......
/*
* 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;
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.User;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.List;
import java.util.Random;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeNotNull;
......@@ -46,6 +29,11 @@ import static org.junit.Assume.assumeNotNull;
public class TestTodosApi extends AbstractIntegrationTest {
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() {
super();
......@@ -53,8 +41,35 @@ public class TestTodosApi extends AbstractIntegrationTest {
@BeforeClass
public static void setup() {
// Must setup the connection to the GitLab test server and get the test Project instance
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
......@@ -62,19 +77,77 @@ public class TestTodosApi extends AbstractIntegrationTest {
assumeNotNull(gitLabApi);
}
private static String getUniqueTitle() {
return (ISSUE_TITLE + " - " + (randomNumberGenerator.nextInt() + 1));
}
@Test
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
public void testMarkAsDone() throws GitLabApiException {
gitLabApi.getTodosApi().markAsDone();
public void testMarkAllAsDone() 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);
List<Todo> todos = gitLabApi.getTodosApi().getTodos();
gitLabApi.getTodosApi().markAllAsDone();
todos = gitLabApi.getTodosApi().getPendingTodos();
assertNotNull(todos);
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);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment