Merge branch 'mikhail.golubev/configurable-issues-states'
[idea/community.git] / plugins / tasks / tasks-tests / test / com / intellij / tasks / integration / YouTrackIntegrationTest.java
1 package com.intellij.tasks.integration;
2
3 import com.intellij.tasks.CustomTaskState;
4 import com.intellij.tasks.Task;
5 import com.intellij.tasks.TaskManagerTestCase;
6 import com.intellij.tasks.youtrack.YouTrackRepository;
7 import com.intellij.tasks.youtrack.YouTrackRepositoryType;
8 import com.intellij.util.Function;
9 import com.intellij.util.containers.ContainerUtil;
10 import org.jdom.Element;
11
12 import java.util.List;
13 import java.util.Set;
14
15 /**
16  * @author Mikhail Golubev
17  */
18 public class YouTrackIntegrationTest extends TaskManagerTestCase {
19   private static final String YOUTRACK_4_TEST_SERVER_URL = "http://trackers-tests.labs.intellij.net:8067";
20
21   private static final String REQUEST_WITH_CUSTOM_STATES_ID = "YT4CS-1";
22   private static final CustomTaskState NORTH_STATE = new CustomTaskState("North", "North");
23   private static final CustomTaskState SUBMITTED_STATE = new CustomTaskState("Submitted", "Submitted");
24
25   private YouTrackRepository myRepository;
26
27   public void testCustomTaskStates() throws Exception {
28     final Task task = myRepository.findTask(REQUEST_WITH_CUSTOM_STATES_ID);
29     assertNotNull(task);
30
31     final Set<CustomTaskState> states = myRepository.getAvailableTaskStates(task);
32     final List<String> stateNames = ContainerUtil.map(states, new Function<CustomTaskState, String>() {
33       @Override
34       public String fun(CustomTaskState state) {
35         return state.getPresentableName();
36       }
37     });
38     assertContainsElements(stateNames, "North", "South");
39
40     // ? -> North
41     myRepository.setTaskState(task, NORTH_STATE);
42     Element element = myRepository.fetchRequestAsElement(REQUEST_WITH_CUSTOM_STATES_ID);
43     assertEquals("North", element.getAttributeValue("state"));
44
45     // North -> Submitted
46     myRepository.setTaskState(task, SUBMITTED_STATE);
47     element = myRepository.fetchRequestAsElement(REQUEST_WITH_CUSTOM_STATES_ID);
48     assertEquals("Submitted", element.getAttributeValue("state"));
49   }
50
51   @Override
52   protected void setUp() throws Exception {
53     super.setUp();
54     myRepository = new YouTrackRepository(new YouTrackRepositoryType());
55     myRepository.setUrl(YOUTRACK_4_TEST_SERVER_URL);
56     myRepository.setUsername("buildtest");
57     myRepository.setPassword("buildtest");
58   }
59 }