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 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: e06d59069d444f019573d19604d26e36add09553 $ 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 * @throws Exception if a problem occurs 55 */ 56 @Test 57 public void canSearchForRepos() throws Exception { 58 MatcherAssert.assertThat( 59 new GithubIT().connect() 60 .search().repos("repo", "stars", Search.Order.DESC), 61 Matchers.not(Matchers.emptyIterableOf(Repo.class)) 62 ); 63 } 64 65 /** 66 * RtSearch can fetch multiple pages of a large result (more than 25 items). 67 * 68 * @throws Exception if a problem occurs 69 */ 70 @Test 71 public void canFetchMultiplePages() throws Exception { 72 final Iterator<Repo> iter = new GithubIT().connect().search().repos( 73 "java", "", Search.Order.DESC 74 ).iterator(); 75 int count = 0; 76 while (iter.hasNext() && count < Tv.HUNDRED) { 77 iter.next().coordinates(); 78 count += 1; 79 } 80 MatcherAssert.assertThat( 81 count, 82 Matchers.greaterThanOrEqualTo(Tv.HUNDRED) 83 ); 84 } 85 86 /** 87 * RtSearch can search for issues. 88 * 89 * @throws Exception if a problem occurs 90 */ 91 @Test 92 public void canSearchForIssues() throws Exception { 93 final EnumMap<Search.Qualifier, String> qualifiers = 94 new EnumMap<>(Search.Qualifier.class); 95 qualifiers.put(Search.Qualifier.LABEL, "bug"); 96 MatcherAssert.assertThat( 97 new GithubIT().connect().search().issues( 98 "qualifiers", 99 "updated", 100 Search.Order.DESC, 101 qualifiers 102 ), 103 Matchers.not(Matchers.emptyIterableOf(Issue.class)) 104 ); 105 } 106 107 /** 108 * RtSearch can search for users. 109 * 110 * @throws Exception if a problem occurs 111 */ 112 @Test 113 public void canSearchForUsers() throws Exception { 114 MatcherAssert.assertThat( 115 new GithubIT().connect() 116 .search().users("jcabi", "joined", Search.Order.DESC), 117 Matchers.not(Matchers.emptyIterableOf(User.class)) 118 ); 119 } 120 121 /** 122 * RtSearch can search for contents. 123 * 124 * @throws Exception if a problem occurs 125 * @see <a href="https://developer.github.com/v3/search/#search-code">Search API</a> for details 126 */ 127 @Test 128 public void canSearchForContents() throws Exception { 129 MatcherAssert.assertThat( 130 new GithubIT().connect().search().codes( 131 "addClass repo:jquery/jquery", "joined", Search.Order.DESC 132 ), 133 Matchers.not(Matchers.emptyIterableOf(Content.class)) 134 ); 135 } 136 137 }