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.aspects.Tv;
33  import com.jcabi.github.OAuthScope.Scope;
34  import javax.json.Json;
35  import javax.json.JsonObject;
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.Test;
42  
43  /**
44   * Test case for {@link RtRelease}.
45   * @author Haris Osmanagic (haris.osmanagic@gmail.com)
46   * @version $Id: 0cf0c15ab98165d4237e273a36dfc244833d8517 $
47   * @since 0.8
48   * @checkstyle MultipleStringLiteralsCheck (200 lines)
49   */
50  @OAuthScope(Scope.REPO)
51  public final class RtReleaseITCase {
52  
53      /**
54       * Test repos.
55       */
56      private static Repos repos;
57  
58      /**
59       * Test repo.
60       */
61      private static Repo repo;
62  
63      /**
64       * RepoRule.
65       * @checkstyle VisibilityModifierCheck (3 lines)
66       */
67      private static RepoRule rule = new RepoRule();
68  
69      /**
70       * Set up test fixtures.
71       * @throws Exception If some errors occurred.
72       */
73      @BeforeClass
74      public static void setUp() throws Exception {
75          final Github github = new GithubIT().connect();
76          repos = github.repos();
77          repo = rule.repo(repos);
78      }
79  
80      /**
81       * Tear down test fixtures.
82       * @throws Exception If some errors occurred.
83       */
84      @AfterClass
85      public static void tearDown() throws Exception {
86          if (repos != null && repo != null) {
87              repos.remove(repo.coordinates());
88          }
89      }
90  
91      /**
92       * RtRelease can edit a release.
93       * @throws Exception If any problems during test execution occur.
94       */
95      @Test
96      public void canEditRelease() throws Exception {
97          final Release release = repo.releases().create(
98              RandomStringUtils.randomAlphanumeric(Tv.TEN)
99          );
100         final JsonObject patch = Json.createObjectBuilder()
101             .add("tag_name", RandomStringUtils.randomAlphanumeric(Tv.TEN))
102             .add("name", "jcabi Github test release")
103             .add("body", "jcabi Github was here!")
104             .build();
105         release.patch(patch);
106         final JsonObject json = repo.releases()
107             .get(release.number()).json();
108         for (final String property : patch.keySet()) {
109             MatcherAssert.assertThat(
110                 json.getString(property),
111                 Matchers.equalTo(patch.getString(property))
112             );
113         }
114     }
115 
116 }