View Javadoc
1   /*
2    * SPDX-FileCopyrightText: Copyright (c) 2013-2025 Yegor Bugayenko
3    * SPDX-License-Identifier: MIT
4    */
5   package com.jcabi.github;
6   
7   import jakarta.json.Json;
8   import java.io.IOException;
9   import org.apache.commons.codec.binary.Base64;
10  import org.apache.commons.lang3.RandomStringUtils;
11  import org.hamcrest.MatcherAssert;
12  import org.hamcrest.Matchers;
13  import org.junit.jupiter.api.AfterAll;
14  import org.junit.jupiter.api.BeforeAll;
15  import org.junit.jupiter.api.Disabled;
16  import org.junit.jupiter.api.Test;
17  
18  /**
19   * Integration case for {@link GitHub}.
20   * @since 0.1
21   * @checkstyle ClassDataAbstractionCoupling (500 lines)
22   *  See https://developer.github.com/v3/repos/#list-languages for API details
23   */
24  @OAuthScope(OAuthScope.Scope.REPO)
25  final class RtRepoITCase {
26      /**
27       * Test repos.
28       */
29      private static Repos repos;
30  
31      /**
32       * Test repo.
33       */
34      private static Repo repo;
35  
36      /**
37       * Set up test fixtures.
38       */
39      @BeforeAll
40      static void setUp() throws IOException {
41          final GitHub github = GitHubIT.connect();
42          RtRepoITCase.repos = github.repos();
43          RtRepoITCase.repo = RtRepoITCase.repos.create(
44              new Repos.RepoCreate(
45                  RandomStringUtils.secure().nextAlphanumeric(10),
46                  false
47              ).withAutoInit(true)
48          );
49          RtRepoITCase.repo.contents().create(
50              Json.createObjectBuilder()
51                  .add("path", "test.java")
52                  .add("message", "Test file for language test")
53                  .add(
54                      "content", Base64.encodeBase64String(
55                          "some content".getBytes()
56                      )
57                  )
58                  .add("ref", "master")
59                  .build()
60          );
61      }
62  
63      /**
64       * Tear down test fixtures.
65       */
66      @AfterAll
67      static void tearDown() throws IOException {
68          if (RtRepoITCase.repos != null && RtRepoITCase.repo != null) {
69              RtRepoITCase.repos.remove(RtRepoITCase.repo.coordinates());
70          }
71      }
72  
73      @Test
74      void identifiesItself() {
75          MatcherAssert.assertThat(
76              "Value is null",
77              RtRepoITCase.repo.coordinates(),
78              Matchers.notNullValue()
79          );
80      }
81  
82      @Test
83      void iteratesEvents() throws IOException {
84          final Issue issue = RtRepoITCase.repo.issues().create("Test", "This is a bug");
85          new Issue.Smart(issue).close();
86          MatcherAssert.assertThat(
87              "Collection is not empty",
88              RtRepoITCase.repo.issueEvents().iterate(),
89              Matchers.not(Matchers.emptyIterable())
90          );
91      }
92  
93      @Test
94      void exists() throws IOException {
95          MatcherAssert.assertThat(
96              "Values are not equal",
97              new Repo.Smart(RtRepoITCase.repo).exists(), Matchers.is(Boolean.TRUE)
98          );
99      }
100 
101     @Test
102     void fetchCommits() {
103         MatcherAssert.assertThat(
104             "Value is null",
105             RtRepoITCase.repo.commits(),
106             Matchers.notNullValue()
107         );
108     }
109 
110     @Test
111     void iteratesAssignees() {
112         MatcherAssert.assertThat(
113             "Collection is not empty",
114             RtRepoITCase.repo.assignees().iterate(),
115             Matchers.not(Matchers.emptyIterable())
116         );
117     }
118 
119     @Test
120     void fetchLanguages() throws IOException {
121         MatcherAssert.assertThat(
122             "Value is null",
123             RtRepoITCase.repo.languages(),
124             Matchers.notNullValue()
125         );
126     }
127 
128     /**
129      * RtRepo can iterate languages. This test is ignored because of bug
130      * https://github.com/jcabi/jcabi-github/issues/1007 .
131      */
132     @Test
133     @Disabled
134     void iteratesLanguages() throws IOException {
135         MatcherAssert.assertThat(
136             "Collection is not empty",
137             RtRepoITCase.repo.languages(),
138             Matchers.not(Matchers.emptyIterable())
139         );
140     }
141 }