View Javadoc
1   /**
2    * Copyright (c) 2013-2022, 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 javax.json.Json;
35  import org.apache.commons.codec.binary.Base64;
36  import org.apache.commons.lang3.RandomStringUtils;
37  import org.hamcrest.MatcherAssert;
38  import org.hamcrest.Matchers;
39  import org.junit.AfterClass;
40  import org.junit.BeforeClass;
41  import org.junit.Ignore;
42  import org.junit.Test;
43  
44  /**
45   * Integration case for {@link Github}.
46   * @author Yegor Bugayenko (yegor256@gmail.com)
47   * @version $Id: 803e21fb28eba4ba3e2df4400590e920fe7b2885 $
48   * @checkstyle ClassDataAbstractionCoupling (500 lines)
49   *  See https://developer.github.com/v3/repos/#list-languages for API details
50   */
51  @OAuthScope(Scope.REPO)
52  public final class RtRepoITCase {
53      /**
54       * Test repos.
55       */
56      private static Repos repos;
57  
58      /**
59       * Test repo.
60       */
61      private static Repo repo;
62  
63      /**
64       * Set up test fixtures.
65       * @throws Exception If some errors occurred.
66       */
67      @BeforeClass
68      public static void setUp() throws Exception {
69          final Github github = new GithubIT().connect();
70          repos = github.repos();
71          repo = repos.create(
72              new Repos.RepoCreate(
73                  RandomStringUtils.randomAlphanumeric(Tv.TEN),
74                  false
75              ).withAutoInit(true)
76          );
77          repo.contents().create(
78              Json.createObjectBuilder()
79                  .add("path", "test.java")
80                  .add("message", "Test file for language test")
81                  .add(
82                      "content", Base64.encodeBase64String(
83                          "some content".getBytes()
84                      )
85                  )
86                  .add("ref", "master")
87                  .build()
88          );
89      }
90  
91      /**
92       * Tear down test fixtures.
93       * @throws Exception If some errors occurred.
94       */
95      @AfterClass
96      public static void tearDown() throws Exception {
97          if (repos != null && repo != null) {
98              repos.remove(repo.coordinates());
99          }
100     }
101 
102     /**
103      * RtRepo can identify itself.
104      * @throws Exception If some problem inside
105      */
106     @Test
107     public void identifiesItself() throws Exception {
108         MatcherAssert.assertThat(
109             repo.coordinates(),
110             Matchers.notNullValue()
111         );
112     }
113 
114     /**
115      * RtRepo can fetch events.
116      * @throws Exception If some problem inside
117      */
118     @Test
119     public void iteratesEvents() throws Exception {
120         final Issue issue = repo.issues().create("Test", "This is a bug");
121         new Issue.Smart(issue).close();
122         MatcherAssert.assertThat(
123             repo.issueEvents().iterate(),
124             Matchers.not(Matchers.emptyIterable())
125         );
126     }
127 
128     /**
129      * RtRepo can tell if it exists.
130      * @throws Exception If something goes wrong.
131      */
132     @Test
133     public void exists() throws Exception {
134         MatcherAssert.assertThat(
135             new Repo.Smart(repo).exists(), Matchers.is(Boolean.TRUE)
136         );
137     }
138 
139     /**
140      * RtRepo can fetch its commits.
141      * @throws Exception If some problem inside
142      */
143     @Test
144     public void fetchCommits() throws Exception {
145         MatcherAssert.assertThat(repo.commits(), Matchers.notNullValue());
146     }
147 
148     /**
149      * RtRepo can fetch assignees.
150      * @throws Exception If some problem inside
151      */
152     @Test
153     public void iteratesAssignees() throws Exception {
154         MatcherAssert.assertThat(
155             repo.assignees().iterate(),
156             Matchers.not(Matchers.emptyIterable())
157         );
158     }
159 
160     /**
161      * RtRepo can fetch languages.
162      * @throws Exception If some problem inside
163      */
164     @Test
165     public void fetchLanguages() throws Exception {
166         MatcherAssert.assertThat(repo.languages(), Matchers.notNullValue());
167     }
168 
169     /**
170      * RtRepo can iterate languages. This test is ignored because of bug
171      * https://github.com/jcabi/jcabi-github/issues/1007 .
172      * @throws Exception If some problem inside
173      */
174     @Test
175     @Ignore
176     public void iteratesLanguages() throws Exception {
177         MatcherAssert.assertThat(
178             repo.languages(),
179             Matchers.not(Matchers.emptyIterable())
180         );
181     }
182 }