1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.immutable.ArrayMap;
8 import java.io.IOException;
9 import java.util.Date;
10 import java.util.EnumMap;
11 import java.util.HashSet;
12 import java.util.Set;
13 import org.hamcrest.MatcherAssert;
14 import org.hamcrest.Matchers;
15 import org.junit.jupiter.api.AfterAll;
16 import org.junit.jupiter.api.BeforeAll;
17 import org.junit.jupiter.api.Test;
18
19
20
21
22
23 @OAuthScope(OAuthScope.Scope.REPO)
24 final class RtIssuesITCase {
25
26
27
28 private static Repos repos;
29
30
31
32
33 private static Repo repo;
34
35
36
37
38 @BeforeAll
39 static void setUp() throws IOException {
40 final GitHub github = GitHubIT.connect();
41 RtIssuesITCase.repos = github.repos();
42 RtIssuesITCase.repo = new RepoRule().repo(RtIssuesITCase.repos);
43 }
44
45
46
47
48 @AfterAll
49 static void tearDown() throws IOException {
50 if (RtIssuesITCase.repos != null && RtIssuesITCase.repo != null) {
51 RtIssuesITCase.repos.remove(RtIssuesITCase.repo.coordinates());
52 }
53 }
54
55 @Test
56 void iteratesIssues() throws IOException {
57 final Iterable<Issue.Smart> issues = new Smarts<>(
58 new Bulk<>(
59 RtIssuesITCase.repo.issues().iterate(
60 new ArrayMap<String, String>().with("sort", "comments")
61 )
62 )
63 );
64 for (final Issue.Smart issue : issues) {
65 MatcherAssert.assertThat(
66 "Value is null",
67 issue.title(),
68 Matchers.notNullValue()
69 );
70 }
71 }
72
73 @Test
74 void searchesIssues() throws IOException {
75 final String target = "bug";
76 final EnumMap<Issues.Qualifier, String> qualifiers =
77 new EnumMap<>(Issues.Qualifier.class);
78 qualifiers.put(Issues.Qualifier.LABELS, target);
79 final Iterable<Issue.Smart> issues = new Smarts<>(
80 new Bulk<>(
81 RtIssuesITCase.repo.issues().search(
82 Issues.Sort.UPDATED,
83 Search.Order.ASC,
84 qualifiers
85 )
86 )
87 );
88 Date previous = null;
89 final Set<String> labels = new HashSet<>();
90 for (final Issue.Smart issue : issues) {
91 MatcherAssert.assertThat(
92 "Value is null",
93 issue.title(),
94 Matchers.notNullValue()
95 );
96 if (previous != null) {
97 MatcherAssert.assertThat(
98 "Value is not less than expected",
99 issue.updatedAt(),
100 Matchers.lessThanOrEqualTo(previous)
101 );
102 }
103 previous = issue.updatedAt();
104 labels.clear();
105 for (final Label label : issue.roLabels().iterate()) {
106 labels.add(label.name());
107 }
108 MatcherAssert.assertThat(
109 "Assertion failed",
110 labels,
111 Matchers.contains(target)
112 );
113 }
114 }
115 }