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 RtTags.
19   * @since 0.15
20   * @checkstyle MultipleStringLiterals (500 lines)
21   */
22  @OAuthScope(OAuthScope.Scope.REPO)
23  final class RtTagsITCase {
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          RtTagsITCase.repos = github.repos();
48          RtTagsITCase.repo = RtTagsITCase.rule.repo(RtTagsITCase.repos);
49      }
50  
51      /**
52       * Tear down test fixtures.
53       */
54      @AfterAll
55      static void tearDown() throws IOException {
56          if (RtTagsITCase.repos != null && RtTagsITCase.repo != null) {
57              RtTagsITCase.repos.remove(RtTagsITCase.repo.coordinates());
58          }
59      }
60  
61      @Test
62      void createsTag() throws IOException {
63          final References refs = RtTagsITCase.repo.git().references();
64          final String sha = refs.get("refs/heads/master").json()
65              .getJsonObject("object").getString("sha");
66          final String tag = RandomStringUtils.secure().nextAlphanumeric(5);
67          final JsonObject tagger = Json.createObjectBuilder()
68              .add("name", "Scott").add("email", "scott@gmail.com")
69              .add("date", "2013-06-17T14:53:35-07:00").build();
70          MatcherAssert.assertThat(
71              "Value is null",
72              RtTagsITCase.repo.git().tags().create(
73                  Json.createObjectBuilder()
74                      .add("tag", tag).add("message", "initial version")
75                      .add("object", sha).add("type", "commit")
76                      .add("tagger", tagger).build()
77              ), Matchers.notNullValue()
78          );
79          refs.remove(
80              new StringBuilder().append("tags/").append(tag).toString()
81          );
82      }
83  }