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.http.Request;
33 import com.jcabi.http.mock.MkAnswer;
34 import com.jcabi.http.mock.MkContainer;
35 import com.jcabi.http.mock.MkGrizzlyContainer;
36 import com.jcabi.http.mock.MkQuery;
37 import com.jcabi.http.request.ApacheRequest;
38 import java.net.HttpURLConnection;
39 import java.net.URI;
40 import javax.json.Json;
41 import javax.json.JsonObject;
42 import org.hamcrest.MatcherAssert;
43 import org.hamcrest.Matchers;
44 import org.junit.After;
45 import org.junit.Before;
46 import org.junit.Rule;
47 import org.junit.Test;
48 import org.mockito.Mockito;
49
50
51
52
53
54
55 public class RtReleaseTest {
56
57
58
59 private static final String EMPTY_JSON = "{}";
60
61
62
63
64
65 @Rule
66 public final transient RandomPort resource = new RandomPort();
67
68
69
70
71 private transient MkContainer container;
72
73
74
75
76 @Before
77 public final void setUp() {
78 this.container = new MkGrizzlyContainer();
79 }
80
81
82
83
84 @After
85 public final void tearDown() {
86 this.container.stop();
87 }
88
89
90
91
92
93 @Test
94 public final void editRelease() throws Exception {
95 this.container.next(
96 new MkAnswer.Simple(HttpURLConnection.HTTP_OK, EMPTY_JSON)
97 ).start(this.resource.port());
98 final RtRelease release = RtReleaseTest.release(this.container.home());
99 final JsonObject json = Json.createObjectBuilder()
100 .add("tag_name", "v1.0.0")
101 .build();
102 release.patch(json);
103 final MkQuery query = this.container.take();
104 MatcherAssert.assertThat(
105 query.method(),
106 Matchers.equalTo(Request.PATCH)
107 );
108 MatcherAssert.assertThat(
109 query.body(),
110 Matchers.equalTo(json.toString())
111 );
112 }
113
114
115
116
117
118 @Test
119 public final void deleteRelease() throws Exception {
120 this.container.next(
121 new MkAnswer.Simple(HttpURLConnection.HTTP_NO_CONTENT, EMPTY_JSON)
122 ).start(this.resource.port());
123 final RtRelease release = RtReleaseTest.release(this.container.home());
124 release.delete();
125 MatcherAssert.assertThat(
126 this.container.take().method(),
127 Matchers.equalTo(Request.DELETE)
128 );
129 }
130
131
132
133
134
135 @Test
136 public final void executePatchRequest() throws Exception {
137 this.container.next(
138 new MkAnswer.Simple(HttpURLConnection.HTTP_OK, EMPTY_JSON)
139 ).start(this.resource.port());
140 final RtRelease release = RtReleaseTest.release(this.container.home());
141 release.patch(Json.createObjectBuilder().add("name", "v1")
142 .build()
143 );
144 MatcherAssert.assertThat(
145 this.container.take().method(),
146 Matchers.equalTo(Request.PATCH)
147 );
148 }
149
150
151
152
153
154
155 private static RtRelease release(final URI uri) {
156 final Repo repo = Mockito.mock(Repo.class);
157 final Coordinates coords = Mockito.mock(Coordinates.class);
158 Mockito.doReturn(coords).when(repo).coordinates();
159 Mockito.doReturn("tstuser").when(coords).user();
160 Mockito.doReturn("tstbranch").when(coords).repo();
161 return new RtRelease(
162 new ApacheRequest(uri),
163 repo,
164 2
165 );
166 }
167
168 }