View Javadoc
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.aspects.Tv;
33  import com.jcabi.github.OAuthScope.Scope;
34  import com.jcabi.http.wire.RetryWire;
35  import com.jcabi.immutable.ArrayMap;
36  import java.util.Collections;
37  import org.apache.commons.lang3.RandomStringUtils;
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 Milestones}.
46   * @author Paul Polishchuk (ppol@ua.fm)
47   * @version $Id: 1f31f6d438a724b715f671a9886a218269a3f815 $
48   * @checkstyle MultipleStringLiteralsCheck (500 lines)
49   */
50  @OAuthScope(Scope.REPO)
51  public final class RtMilestonesITCase {
52      /**
53       * Test repos.
54       */
55      private static Repos repos;
56  
57      /**
58       * Test repo.
59       */
60      private static Repo repo;
61  
62      /**
63       * Set up test fixtures.
64       * @throws Exception If some errors occurred.
65       */
66      @BeforeClass
67      public static void setUp() throws Exception {
68          final Github github = new RtGithub(
69              new GithubIT().connect().entry().through(RetryWire.class)
70          );
71          repos = github.repos();
72          repo = new RepoRule().repo(repos);
73      }
74  
75      /**
76       * Tear down test fixtures.
77       * @throws Exception If some errors occurred.
78       */
79      @AfterClass
80      public static void tearDown() throws Exception {
81          if (repos != null && repo != null) {
82              repos.remove(repo.coordinates());
83          }
84      }
85  
86      /**
87       * RtMilestones can iterate milestones.
88       * @throws Exception If some problem inside
89       */
90      @Test
91      public void iteratesIssues() throws Exception {
92          final Milestones milestones = repo.milestones();
93          final Milestone milestone = milestones.create(
94              RandomStringUtils.randomAlphabetic(Tv.TEN)
95          );
96          try {
97              MatcherAssert.assertThat(
98                  milestones.iterate(Collections.singletonMap("state", "all")),
99                  Matchers.hasItem(milestone)
100             );
101         } finally {
102             milestones.remove(milestone.number());
103         }
104     }
105 
106     /**
107      * RtMilestones can create a new milestone.
108      * @throws Exception If some problem inside
109      */
110     @Test
111     public void createsNewMilestone() throws Exception {
112         final Milestones milestones = repo.milestones();
113         final Milestone milestone = milestones.create(
114             RandomStringUtils.randomAlphabetic(Tv.TEN)
115         );
116         try {
117             MatcherAssert.assertThat(
118                 milestones.iterate(Collections.singletonMap("state", "all")),
119                 Matchers.not(Matchers.emptyIterable())
120             );
121         } finally {
122             milestones.remove(milestone.number());
123         }
124     }
125 
126     /**
127      * RtMilestones can remove a milestone.
128      * @throws Exception if some problem inside
129      */
130     @Test
131     public void deleteMilestone() throws Exception {
132         final Milestones milestones = repo.milestones();
133         final Milestone milestone = milestones.create("a milestones");
134         MatcherAssert.assertThat(
135             milestones.iterate(new ArrayMap<>()),
136             Matchers.hasItem(milestone)
137         );
138         milestones.remove(milestone.number());
139         MatcherAssert.assertThat(
140             milestones.iterate(new ArrayMap<>()),
141             Matchers.not(Matchers.hasItem(milestone))
142         );
143     }
144 }
145