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 java.util.EnumMap;
35  import java.util.Iterator;
36  import org.hamcrest.MatcherAssert;
37  import org.hamcrest.Matchers;
38  import org.junit.Test;
39  
40  /**
41   * Test case for {@link RtSearch}.
42   *
43   * @author Carlos Miranda (miranda.cma@gmail.com)
44   * @version $Id: c40293c4c2cd6fe7ea16156bab1a1a2b9cd9c6e5 $
45   * @checkstyle MultipleStringLiterals (140 lines)
46   */
47  @OAuthScope({ Scope.REPO, Scope.USER })
48  @SuppressWarnings("PMD.AvoidDuplicateLiterals")
49  public final class RtSearchITCase {
50  
51      /**
52       * RtSearch can search for repos.
53       *
54       */
55      @Test
56      public void canSearchForRepos() {
57          MatcherAssert.assertThat(
58              new GithubIT().connect()
59                  .search().repos("repo", "stars", Search.Order.DESC),
60              Matchers.not(Matchers.emptyIterableOf(Repo.class))
61          );
62      }
63  
64      /**
65       * RtSearch can fetch multiple pages of a large result (more than 25 items).
66       *
67       */
68      @Test
69      public void canFetchMultiplePages() {
70          final Iterator<Repo> iter = new GithubIT().connect().search().repos(
71              "java", "", Search.Order.DESC
72          ).iterator();
73          int count = 0;
74          while (iter.hasNext() && count < Tv.HUNDRED) {
75              iter.next().coordinates();
76              count += 1;
77          }
78          MatcherAssert.assertThat(
79              count,
80              Matchers.greaterThanOrEqualTo(Tv.HUNDRED)
81          );
82      }
83  
84      /**
85       * RtSearch can search for issues.
86       *
87       */
88      @Test
89      public void canSearchForIssues() {
90          final EnumMap<Search.Qualifier, String> qualifiers =
91              new EnumMap<>(Search.Qualifier.class);
92          qualifiers.put(Search.Qualifier.LABEL, "bug");
93          MatcherAssert.assertThat(
94              new GithubIT().connect().search().issues(
95                  "qualifiers",
96                  "updated",
97                  Search.Order.DESC,
98                  qualifiers
99              ),
100             Matchers.not(Matchers.emptyIterableOf(Issue.class))
101         );
102     }
103 
104     /**
105      * RtSearch can search for users.
106      *
107      */
108     @Test
109     public void canSearchForUsers() {
110         MatcherAssert.assertThat(
111             new GithubIT().connect()
112                 .search().users("jcabi", "joined", Search.Order.DESC),
113             Matchers.not(Matchers.emptyIterableOf(User.class))
114         );
115     }
116 
117     /**
118      * RtSearch can search for contents.
119      *
120      * @see <a href="https://developer.github.com/v3/search/#search-code">Search API</a> for details
121      */
122     @Test
123     public void canSearchForContents() {
124         MatcherAssert.assertThat(
125             new GithubIT().connect().search().codes(
126                 "addClass repo:jquery/jquery", "joined", Search.Order.DESC
127             ),
128             Matchers.not(Matchers.emptyIterableOf(Content.class))
129         );
130     }
131 
132 }