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 jakarta.json.JsonObject;
9   import java.io.IOException;
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.Test;
16  
17  /**
18   * Integration testcase for RtTag.
19   * @since 0.8
20   * @checkstyle MultipleStringLiterals (500 lines)
21   */
22  @OAuthScope(OAuthScope.Scope.REPO)
23  final class RtTagITCase {
24  
25      /**
26       * Test repos.
27       */
28      private static Repos repos;
29  
30      /**
31       * Test repo.
32       */
33      private static Repo repo;
34  
35      /**
36       * RepoRule.
37       * @checkstyle VisibilityModifierCheck (3 lines)
38       */
39      private static RepoRule rule = new RepoRule();
40  
41      /**
42       * Set up test fixtures.
43       */
44      @BeforeAll
45      static void setUp() throws IOException {
46          final GitHub github = GitHubIT.connect();
47          RtTagITCase.repos = github.repos();
48          RtTagITCase.repo = RtTagITCase.rule.repo(RtTagITCase.repos);
49      }
50  
51      /**
52       * Tear down test fixtures.
53       */
54      @AfterAll
55      static void tearDown() throws IOException {
56          if (RtTagITCase.repos != null && RtTagITCase.repo != null) {
57              RtTagITCase.repos.remove(RtTagITCase.repo.coordinates());
58          }
59      }
60  
61      @Test
62      void fetchesJson() throws IOException {
63          final String object = "object";
64          final String tag = RandomStringUtils.secure().nextAlphanumeric(10);
65          final References refs = RtTagITCase.repo.git().references();
66          final String sha = refs.get("refs/heads/master").json()
67              .getJsonObject(object).getString("sha");
68          final JsonObject tagger = Json.createObjectBuilder()
69              .add("name", "Scott").add("email", "scott@gmail.com")
70              .add("date", "2013-06-17T14:53:35-07:00").build();
71          try {
72              final String content = "initial version";
73              final String message = "message";
74              MatcherAssert.assertThat(
75                  "Values are not equal",
76                  RtTagITCase.repo.git().tags().create(
77                      Json.createObjectBuilder().add("tag", tag)
78                          .add(message, content)
79                          .add(object, sha).add("type", "commit")
80                          .add("tagger", tagger).build()
81                  ).json().getString(message),
82                  Matchers.is(content)
83              );
84          } finally {
85              refs.remove(
86                  new StringBuilder().append("tags/").append(tag).toString()
87              );
88          }
89      }
90  }