1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.http.wire.RetryWire;
8 import com.jcabi.immutable.ArrayMap;
9 import java.io.IOException;
10 import java.util.Collections;
11 import org.apache.commons.lang3.RandomStringUtils;
12 import org.hamcrest.MatcherAssert;
13 import org.hamcrest.Matchers;
14 import org.junit.jupiter.api.AfterAll;
15 import org.junit.jupiter.api.BeforeAll;
16 import org.junit.jupiter.api.Test;
17
18
19
20
21
22
23 @OAuthScope(OAuthScope.Scope.REPO)
24 final class RtMilestonesITCase {
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 = new RtGitHub(
41 GitHubIT.connect().entry().through(RetryWire.class)
42 );
43 RtMilestonesITCase.repos = github.repos();
44 RtMilestonesITCase.repo = new RepoRule().repo(RtMilestonesITCase.repos);
45 }
46
47
48
49
50 @AfterAll
51 static void tearDown() throws IOException {
52 if (RtMilestonesITCase.repos != null && RtMilestonesITCase.repo != null) {
53 RtMilestonesITCase.repos.remove(RtMilestonesITCase.repo.coordinates());
54 }
55 }
56
57 @Test
58 void iteratesIssues() throws IOException {
59 final Milestones milestones = RtMilestonesITCase.repo.milestones();
60 final Milestone milestone = milestones.create(
61 RandomStringUtils.secure().nextAlphabetic(10)
62 );
63 try {
64 MatcherAssert.assertThat(
65 "Collection does not contain expected item",
66 milestones.iterate(Collections.singletonMap("state", "all")),
67 Matchers.hasItem(milestone)
68 );
69 } finally {
70 milestones.remove(milestone.number());
71 }
72 }
73
74 @Test
75 void createsNewMilestone() throws IOException {
76 final Milestones milestones = RtMilestonesITCase.repo.milestones();
77 final Milestone milestone = milestones.create(
78 RandomStringUtils.secure().nextAlphabetic(10)
79 );
80 try {
81 MatcherAssert.assertThat(
82 "Collection is not empty",
83 milestones.iterate(Collections.singletonMap("state", "all")),
84 Matchers.not(Matchers.emptyIterable())
85 );
86 } finally {
87 milestones.remove(milestone.number());
88 }
89 }
90
91 @Test
92 void deleteMilestone() throws IOException {
93 final Milestones milestones = RtMilestonesITCase.repo.milestones();
94 final Milestone milestone = milestones.create("a milestones");
95 MatcherAssert.assertThat(
96 "Collection does not contain expected item",
97 milestones.iterate(new ArrayMap<>()),
98 Matchers.hasItem(milestone)
99 );
100 milestones.remove(milestone.number());
101 MatcherAssert.assertThat(
102 "Collection does not contain expected item",
103 milestones.iterate(new ArrayMap<>()),
104 Matchers.not(Matchers.hasItem(milestone))
105 );
106 }
107 }