Merge branch 'mikhail.golubev/configurable-issues-states'
[idea/community.git] / plugins / tasks / tasks-tests / test / com / intellij / tasks / integration / GitlabIntegrationTest.java
1 package com.intellij.tasks.integration;
2
3 import com.google.gson.Gson;
4 import com.intellij.tasks.TaskManagerTestCase;
5 import com.intellij.tasks.gitlab.GitlabRepository;
6 import com.intellij.tasks.gitlab.GitlabTask;
7 import com.intellij.tasks.gitlab.model.GitlabIssue;
8 import com.intellij.tasks.gitlab.model.GitlabProject;
9 import com.intellij.tasks.impl.LocalTaskImpl;
10 import com.intellij.tasks.impl.TaskUtil;
11 import com.intellij.tasks.impl.gson.GsonUtil;
12
13 import java.util.Collections;
14
15 /**
16  * TODO: install Gitlab on server and add more functional tests
17  * @author Mikhail Golubev
18  */
19 public class GitlabIntegrationTest extends TaskManagerTestCase {
20   private static final Gson GSON = GsonUtil.createDefaultBuilder().create();
21   private GitlabRepository myRepository;
22
23   public void testCommitMessageFormat() throws Exception {
24     String issueJson = "{\n" +
25                        "    \"id\": 1,\n" +
26                        "    \"iid\": 2,\n" +
27                        "    \"project_id\": 3,\n" +
28                        "    \"title\": \"Sample title\",\n" +
29                        "    \"state\": \"opened\",\n" +
30                        "    \"updated_at\": \"2013-11-14T12:30:39Z\",\n" +
31                        "    \"created_at\": \"2013-11-14T12:30:39Z\"\n" +
32                        "}";
33
34     String projectJson = "{\n" +
35                          "   \"id\": 3,\n" +
36                          "   \"name\": \"project-1\"\n" +
37                          "}";
38
39     GitlabIssue issue = GSON.fromJson(issueJson, GitlabIssue.class);
40     GitlabProject project = GSON.fromJson(projectJson, GitlabProject.class);
41
42     myRepository.setProjects(Collections.singletonList(project));
43     myRepository.setShouldFormatCommitMessage(true);
44     myRepository.setCommitMessageFormat("{project} {number} {id} {summary}");
45
46     LocalTaskImpl localTask = new LocalTaskImpl(new GitlabTask(myRepository, issue));
47     String changeListComment = TaskUtil.getChangeListComment(localTask);
48     assertEquals("project-1 2 1 Sample title", changeListComment);
49
50     myRepository.setProjects(Collections.<GitlabProject>emptyList());
51     localTask = new LocalTaskImpl(new GitlabTask(myRepository, issue));
52     changeListComment = TaskUtil.getChangeListComment(localTask);
53     // Project is unknown, so "" is substituted instead
54     assertEquals(" 2 1 Sample title", changeListComment);
55
56   }
57
58   @Override
59   public void setUp() throws Exception {
60     super.setUp();
61     myRepository = new GitlabRepository();
62   }
63 }