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.github.OAuthScope.Scope;
33  import org.hamcrest.MatcherAssert;
34  import org.hamcrest.Matchers;
35  import org.junit.Assume;
36  import org.junit.Test;
37  
38  /**
39   * Integration case for {@link Github}.
40   * @author Yegor Bugayenko (yegor256@gmail.com)
41   * @version $Id: c004ebf6bcb51f63faff6e788d2bd35dc3b4ed27 $
42   * @checkstyle ClassDataAbstractionCoupling (500 lines)
43   */
44  @OAuthScope(Scope.REPO)
45  public final class RtGithubITCase {
46  
47      /**
48       * RtGithub can authenticate itself.
49       * @throws Exception If some problem inside
50       */
51      @Test
52      public void authenticatesItself() throws Exception {
53          final Github github = new GithubIT().connect();
54          MatcherAssert.assertThat(
55              github.users().self(),
56              Matchers.notNullValue()
57          );
58      }
59  
60      /**
61       * RtGithub can connect anonymously.
62       * @throws Exception If some problem inside
63       */
64      @Test
65      public void connectsAnonymously() throws Exception {
66          final Github github = new RtGithub();
67          MatcherAssert.assertThat(
68              new Issue.Smart(
69                  github.repos().get(
70                      new Coordinates.Simple("jcabi/jcabi-github")
71                  ).issues().get(1)
72              ).title(),
73              Matchers.notNullValue()
74          );
75      }
76  
77      /**
78       * RtGithub can fetch meta information.
79       * @throws Exception If some problem inside
80       */
81      @Test
82      public void fetchesMeta() throws Exception {
83          final Github github = new RtGithub();
84          MatcherAssert.assertThat(
85              github.meta().getJsonArray("hooks"),
86              Matchers.not(Matchers.empty())
87          );
88      }
89  
90      /**
91       * RtGithub can fetch emojis.
92       * @throws Exception If some problem inside
93       */
94      @Test
95      public void fetchesEmojis() throws Exception {
96          final Github github = new RtGithub();
97          MatcherAssert.assertThat(
98              github.emojis().getString("+1"),
99              Matchers.startsWith("https://")
100         );
101     }
102 
103     /**
104      * RtGithub can authenticate with username and password through HTTP Basic.
105      * @throws Exception If some problem inside
106      */
107     @Test
108     public void authenticatesWithUsernameAndPassword() throws Exception {
109         final String user = System.getProperty("failsafe.github.user");
110         final String password = System.getProperty("failsafe.github.password");
111         Assume.assumeThat(user, Matchers.not(Matchers.isEmptyOrNullString()));
112         Assume.assumeThat(
113             password,
114             Matchers.not(Matchers.isEmptyOrNullString())
115         );
116         final Github github = new RtGithub(user, password);
117         MatcherAssert.assertThat(
118             new User.Smart(github.users().self()).login(),
119             Matchers.is(user)
120         );
121     }
122 
123     /**
124      * RtGithub can fetch users.
125      */
126     @Test
127     public void fetchesUsers() {
128         final Github github = new GithubIT().connect();
129         MatcherAssert.assertThat(
130             "Iterating over github.users() should return something",
131             github.users().iterate("").iterator().next(),
132             Matchers.anything()
133         );
134     }
135 
136 }