1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 org.apache.commons.lang3.RandomStringUtils;
36 import org.hamcrest.MatcherAssert;
37 import org.hamcrest.Matchers;
38 import org.junit.AfterClass;
39 import org.junit.BeforeClass;
40 import org.junit.Test;
41
42
43
44
45
46
47
48
49
50 @OAuthScope(Scope.REPO)
51 public final class RtReleaseAssetITCase {
52
53
54
55
56 private static Repos repos;
57
58
59
60
61 private static Repo repo;
62
63
64
65
66
67 private static RepoRule rule = new RepoRule();
68
69
70
71
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 repo.releases().create(
79 RandomStringUtils.randomAlphanumeric(Tv.TEN)
80 );
81 }
82
83
84
85
86
87 @AfterClass
88 public static void tearDown() throws Exception {
89 if (repos != null && repo != null) {
90 repos.remove(repo.coordinates());
91 }
92 }
93
94
95
96
97
98 @Test
99 public void fetchAsJSON() throws Exception {
100 final String name = RandomStringUtils.randomAlphanumeric(Tv.TEN);
101 final Release release = repo.releases().create(name);
102 try {
103 MatcherAssert.assertThat(
104 release.json().getInt("id"),
105 Matchers.equalTo(release.number())
106 );
107 } finally {
108 release.delete();
109 }
110 }
111
112
113
114
115
116 @Test
117 public void executePatchRequest() throws Exception {
118 final Release release = repo.releases().create(
119 String.format("v%s", RandomStringUtils.randomAlphanumeric(Tv.TEN))
120 );
121 final String desc = "Description of the release";
122 try {
123 release.patch(Json.createObjectBuilder().add("body", desc).build());
124 MatcherAssert.assertThat(
125 new Release.Smart(release).body(),
126 Matchers.startsWith(desc)
127 );
128 } finally {
129 release.delete();
130 }
131 }
132
133
134
135
136
137 @Test
138 public void removesReleaseAsset() throws Exception {
139 final Releases releases = repo.releases();
140 final String rname = RandomStringUtils.randomAlphanumeric(Tv.TEN);
141 final Release release = releases.create(rname);
142 try {
143 MatcherAssert.assertThat(
144 releases.get(release.number()),
145 Matchers.notNullValue()
146 );
147 } finally {
148 release.delete();
149 }
150 MatcherAssert.assertThat(
151 releases.iterate(),
152 Matchers.not(Matchers.contains(release))
153 );
154 }
155
156 }