1 /**
2 * Copyright (c) 2013-2023, jcabi.com
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met: 1) Redistributions of source code must retain the above
8 * copyright notice, this list of conditions and the following
9 * disclaimer. 2) Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution. 3) Neither the name of the jcabi.com nor
13 * the names of its contributors may be used to endorse or promote
14 * products derived from this software without specific prior written
15 * permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
19 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 package com.jcabi.github;
31
32 import com.jcabi.github.OAuthScope.Scope;
33 import com.jcabi.immutable.ArrayMap;
34 import java.util.Date;
35 import java.util.EnumMap;
36 import java.util.HashSet;
37 import java.util.Set;
38 import org.hamcrest.MatcherAssert;
39 import org.hamcrest.Matchers;
40 import org.junit.AfterClass;
41 import org.junit.BeforeClass;
42 import org.junit.Test;
43
44 /**
45 * Integration case for {@link Github}.
46 * @author Yegor Bugayenko (yegor256@gmail.com)
47 * @version $Id: 5b943ab946c51ffba1bbe9659f971818558e9673 $
48 */
49 @OAuthScope(Scope.REPO)
50 public final class RtIssuesITCase {
51 /**
52 * Test repos.
53 */
54 private static Repos repos;
55
56 /**
57 * Test repo.
58 */
59 private static Repo repo;
60
61 /**
62 * Set up test fixtures.
63 * @throws Exception If some errors occurred.
64 */
65 @BeforeClass
66 public static void setUp() throws Exception {
67 final Github github = new GithubIT().connect();
68 repos = github.repos();
69 repo = new RepoRule().repo(repos);
70 }
71
72 /**
73 * Tear down test fixtures.
74 * @throws Exception If some errors occurred.
75 */
76 @AfterClass
77 public static void tearDown() throws Exception {
78 if (repos != null && repo != null) {
79 repos.remove(repo.coordinates());
80 }
81 }
82
83 /**
84 * RtIssues can iterate issues.
85 * @throws Exception If some problem inside
86 */
87 @Test
88 public void iteratesIssues() throws Exception {
89 final Iterable<Issue.Smart> issues = new Smarts<>(
90 new Bulk<>(
91 repo.issues().iterate(
92 new ArrayMap<String, String>().with("sort", "comments")
93 )
94 )
95 );
96 for (final Issue.Smart issue : issues) {
97 MatcherAssert.assertThat(
98 issue.title(),
99 Matchers.notNullValue()
100 );
101 }
102 }
103
104 /**
105 * RtIssues can search issues within a repository.
106 * @throws Exception If some problem inside
107 */
108 @Test
109 public void searchesIssues() throws Exception {
110 final String targetLabel = "bug";
111 final EnumMap<Issues.Qualifier, String> qualifiers =
112 new EnumMap<>(Issues.Qualifier.class);
113 qualifiers.put(Issues.Qualifier.LABELS, targetLabel);
114 final Iterable<Issue.Smart> issues = new Smarts<>(
115 new Bulk<>(
116 repo.issues().search(
117 Issues.Sort.UPDATED,
118 Search.Order.ASC,
119 qualifiers
120 )
121 )
122 );
123 Date prevUpdated = null;
124 final Set<String> labelNames = new HashSet<>();
125 for (final Issue.Smart issue : issues) {
126 MatcherAssert.assertThat(
127 issue.title(),
128 Matchers.notNullValue()
129 );
130 if (prevUpdated != null) {
131 MatcherAssert.assertThat(
132 issue.updatedAt(),
133 Matchers.lessThanOrEqualTo(prevUpdated)
134 );
135 }
136 prevUpdated = issue.updatedAt();
137 labelNames.clear();
138 for (final Label label : issue.roLabels().iterate()) {
139 labelNames.add(label.name());
140 }
141 MatcherAssert.assertThat(
142 labelNames,
143 Matchers.contains(targetLabel)
144 );
145 }
146 }
147 }