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 RtTag. 46 * @author Mihai Andronache (amihaiemil@gmail.com) 47 * @version $Id: 772e291a1bf7e7df54795c9824cc787a132f7dcc $ 48 * @checkstyle MultipleStringLiterals (500 lines) 49 */ 50 @OAuthScope(Scope.REPO) 51 public final class RtTagITCase { 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 * RtTag should return its json representation. 93 * @throws Exception If something goes wrong. 94 */ 95 @Test 96 public void fetchesJson() throws Exception { 97 final String object = "object"; 98 final String message = "message"; 99 final String content = "initial version"; 100 final String tag = RandomStringUtils.randomAlphanumeric(Tv.TEN); 101 final References refs = repo.git().references(); 102 final String sha = refs.get("refs/heads/master").json() 103 .getJsonObject(object).getString("sha"); 104 final JsonObject tagger = Json.createObjectBuilder() 105 .add("name", "Scott").add("email", "scott@gmail.com") 106 .add("date", "2013-06-17T14:53:35-07:00").build(); 107 try { 108 MatcherAssert.assertThat( 109 repo.git().tags().create( 110 Json.createObjectBuilder().add("tag", tag) 111 .add(message, content) 112 .add(object, sha).add("type", "commit") 113 .add("tagger", tagger).build() 114 ).json().getString(message), 115 Matchers.is(content) 116 ); 117 } finally { 118 refs.remove( 119 new StringBuilder().append("tags/").append(tag).toString() 120 ); 121 } 122 } 123 }