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
31 package com.jcabi.github;
32
33 import com.jcabi.aspects.Tv;
34 import com.jcabi.github.OAuthScope.Scope;
35 import javax.json.Json;
36 import javax.json.JsonObject;
37 import org.apache.commons.lang3.RandomStringUtils;
38 import org.hamcrest.MatcherAssert;
39 import org.hamcrest.Matchers;
40 import org.junit.AfterClass;
41 import org.junit.BeforeClass;
42 import org.junit.Test;
43
44 /**
45 * Integration testcase for RtTags.
46 * @author Mihai Andronache (amihaiemil@gmail.com)
47 * @version $Id: 0d6565beb5a9d4a62315f900a60923fc7cf2188e $
48 * @checkstyle MultipleStringLiterals (500 lines)
49 */
50 @OAuthScope(Scope.REPO)
51 public final class RtTagsITCase {
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 * RtTags creates a tag.
93 * @throws Exception If something goes wrong.
94 */
95 @Test
96 public void createsTag() throws Exception {
97 final References refs = repo.git().references();
98 final String sha = refs.get("refs/heads/master").json()
99 .getJsonObject("object").getString("sha");
100 final String tag = RandomStringUtils.randomAlphanumeric(Tv.FIVE);
101 final JsonObject tagger = Json.createObjectBuilder()
102 .add("name", "Scott").add("email", "scott@gmail.com")
103 .add("date", "2013-06-17T14:53:35-07:00").build();
104 MatcherAssert.assertThat(
105 repo.git().tags().create(
106 Json.createObjectBuilder()
107 .add("tag", tag).add("message", "initial version")
108 .add("object", sha).add("type", "commit")
109 .add("tagger", tagger).build()
110 ), Matchers.notNullValue()
111 );
112 refs.remove(
113 new StringBuilder().append("tags/").append(tag).toString()
114 );
115 }
116 }