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 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: 38caf0b8118aae623302f0e61c0efe7c576679d3 $
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      */
105     @Test
106     public void identifiesItself() {
107         MatcherAssert.assertThat(
108             repo.coordinates(),
109             Matchers.notNullValue()
110         );
111     }
112 
113     /**
114      * RtRepo can fetch events.
115      * @throws Exception If some problem inside
116      */
117     @Test
118     public void iteratesEvents() throws Exception {
119         final Issue issue = repo.issues().create("Test", "This is a bug");
120         new Issue.Smart(issue).close();
121         MatcherAssert.assertThat(
122             repo.issueEvents().iterate(),
123             Matchers.not(Matchers.emptyIterable())
124         );
125     }
126 
127     /**
128      * RtRepo can tell if it exists.
129      * @throws Exception If something goes wrong.
130      */
131     @Test
132     public void exists() throws Exception {
133         MatcherAssert.assertThat(
134             new Repo.Smart(repo).exists(), Matchers.is(Boolean.TRUE)
135         );
136     }
137 
138     /**
139      * RtRepo can fetch its commits.
140      */
141     @Test
142     public void fetchCommits() {
143         MatcherAssert.assertThat(repo.commits(), Matchers.notNullValue());
144     }
145 
146     /**
147      * RtRepo can fetch assignees.
148      */
149     @Test
150     public void iteratesAssignees() {
151         MatcherAssert.assertThat(
152             repo.assignees().iterate(),
153             Matchers.not(Matchers.emptyIterable())
154         );
155     }
156 
157     /**
158      * RtRepo can fetch languages.
159      * @throws Exception If some problem inside
160      */
161     @Test
162     public void fetchLanguages() throws Exception {
163         MatcherAssert.assertThat(repo.languages(), Matchers.notNullValue());
164     }
165 
166     /**
167      * RtRepo can iterate languages. This test is ignored because of bug
168      * https://github.com/jcabi/jcabi-github/issues/1007 .
169      * @throws Exception If some problem inside
170      */
171     @Test
172     @Ignore
173     public void iteratesLanguages() throws Exception {
174         MatcherAssert.assertThat(
175             repo.languages(),
176             Matchers.not(Matchers.emptyIterable())
177         );
178     }
179 }