IDEA-131201 github tasks: allow to specify, whether to load all issues or assigned...
[idea/community.git] / plugins / github / test / org / jetbrains / plugins / github / GithubIssuesTest.java
1 /*
2  * Copyright 2000-2013 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.jetbrains.plugins.github;
17
18 import com.intellij.openapi.util.Comparing;
19 import com.intellij.util.Function;
20 import com.intellij.util.containers.ContainerUtil;
21 import org.jetbrains.plugins.github.api.GithubApiUtil;
22 import org.jetbrains.plugins.github.api.GithubConnection;
23 import org.jetbrains.plugins.github.api.GithubIssue;
24 import org.jetbrains.plugins.github.test.GithubTest;
25
26 import java.util.Arrays;
27 import java.util.List;
28
29 /**
30  * @author Aleksey Pivovarov
31  */
32 public class GithubIssuesTest extends GithubTest {
33   private static final String REPO_NAME = "IssuesTest";
34
35   public void testAssigneeIssues1() throws Exception {
36     List<GithubIssue> result = GithubApiUtil.getIssuesAssigned(new GithubConnection(myAuth), myLogin2, REPO_NAME, myLogin1, 100, false);
37     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
38       @Override
39       public Long fun(GithubIssue githubIssue) {
40         return githubIssue.getNumber();
41       }
42     });
43
44     List<Long> expected = Arrays.asList(6L, 7L, 8L);
45
46     assertTrue(Comparing.haveEqualElements(issues, expected));
47   }
48
49   public void testAssigneeIssues2() throws Exception {
50     List<GithubIssue> result = GithubApiUtil.getIssuesAssigned(new GithubConnection(myAuth), myLogin2, REPO_NAME, myLogin2, 100, false);
51     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
52       @Override
53       public Long fun(GithubIssue githubIssue) {
54         return githubIssue.getNumber();
55       }
56     });
57
58     List<Long> expected = Arrays.asList(1L, 2L);
59
60     assertTrue(Comparing.haveEqualElements(issues, expected));
61   }
62
63   public void testAssigneeIssues3() throws Exception {
64     List<GithubIssue> result = GithubApiUtil.getIssuesAssigned(new GithubConnection(myAuth), myLogin2, REPO_NAME, "", 100, false);
65     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
66       @Override
67       public Long fun(GithubIssue githubIssue) {
68         return githubIssue.getNumber();
69       }
70     });
71
72     List<Long> expected = Arrays.asList(1L, 2L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 13L, 14L);
73
74     assertTrue(Comparing.haveEqualElements(issues, expected));
75   }
76
77   public void testAssigneeIssues4() throws Exception {
78     List<GithubIssue> result = GithubApiUtil.getIssuesAssigned(new GithubConnection(myAuth), myLogin2, REPO_NAME, myLogin1, 100, true);
79     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
80       @Override
81       public Long fun(GithubIssue githubIssue) {
82         return githubIssue.getNumber();
83       }
84     });
85
86     List<Long> expected = Arrays.asList(3L, 6L, 7L, 8L);
87
88     assertTrue(Comparing.haveEqualElements(issues, expected));
89   }
90
91   public void testAssigneeIssues5() throws Exception {
92     List<GithubIssue> result = GithubApiUtil.getIssuesAssigned(new GithubConnection(myAuth), myLogin2, REPO_NAME, myLogin2, 100, true);
93     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
94       @Override
95       public Long fun(GithubIssue githubIssue) {
96         return githubIssue.getNumber();
97       }
98     });
99
100     List<Long> expected = Arrays.asList(1L, 2L);
101
102     assertTrue(Comparing.haveEqualElements(issues, expected));
103   }
104
105   public void testAssigneeIssues6() throws Exception {
106     List<GithubIssue> result = GithubApiUtil.getIssuesAssigned(new GithubConnection(myAuth), myLogin2, REPO_NAME, "", 100, true);
107     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
108       @Override
109       public Long fun(GithubIssue githubIssue) {
110         return githubIssue.getNumber();
111       }
112     });
113
114     List<Long> expected = Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L);
115
116     assertTrue(Comparing.haveEqualElements(issues, expected));
117   }
118
119   public void testQueriedIssues1() throws Exception {
120     List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, null, "abracadabra", true);
121     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
122       @Override
123       public Long fun(GithubIssue githubIssue) {
124         return githubIssue.getNumber();
125       }
126     });
127
128     List<Long> expected = Arrays.asList(10L, 12L);
129
130     assertTrue(Comparing.haveEqualElements(issues, expected));
131   }
132
133   public void testQueriedIssues2() throws Exception {
134     List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, null, "commentary", true);
135     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
136       @Override
137       public Long fun(GithubIssue githubIssue) {
138         return githubIssue.getNumber();
139       }
140     });
141
142     List<Long> expected = Arrays.asList(11L);
143
144     assertTrue(Comparing.haveEqualElements(issues, expected));
145   }
146
147   public void testQueriedIssues3() throws Exception {
148     List<GithubIssue> result = GithubApiUtil.getIssuesQueried(new GithubConnection(myAuth), myLogin2, REPO_NAME, null, "abracadabra", false);
149     List<Long> issues = ContainerUtil.map(result, new Function<GithubIssue, Long>() {
150       @Override
151       public Long fun(GithubIssue githubIssue) {
152         return githubIssue.getNumber();
153       }
154     });
155
156     List<Long> expected = Arrays.asList(10L);
157
158     assertTrue(Comparing.haveEqualElements(issues, expected));
159   }
160 }