1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.github.mock.MkGitHub;
8 import com.jcabi.http.Request;
9 import com.jcabi.http.mock.MkAnswer;
10 import com.jcabi.http.mock.MkContainer;
11 import com.jcabi.http.mock.MkGrizzlyContainer;
12 import com.jcabi.http.request.ApacheRequest;
13 import jakarta.json.Json;
14 import jakarta.json.JsonObject;
15 import java.io.IOException;
16 import java.net.HttpURLConnection;
17 import org.hamcrest.MatcherAssert;
18 import org.hamcrest.Matchers;
19 import org.junit.jupiter.api.Test;
20 import org.junit.jupiter.api.extension.ExtendWith;
21
22
23
24
25
26
27 @ExtendWith(RandomPort.class)
28 final class RtTagsTest {
29
30
31
32
33
34 @Test
35 void createsTag() throws IOException {
36 final MkContainer container = new MkGrizzlyContainer().next(
37 new MkAnswer.Simple(
38 HttpURLConnection.HTTP_CREATED,
39 "{\"sha\":\"0abcd89jcabitest\", \"tag\":\"v.0.1\"}"
40 )
41 ).next(
42 new MkAnswer.Simple(
43 HttpURLConnection.HTTP_CREATED,
44 "{\"ref\":\"refs/heads/feature-a\"}"
45 )
46 ).start(RandomPort.port());
47 final Tags tags = new RtTags(
48 new ApacheRequest(container.home()),
49 new MkGitHub().randomRepo()
50 );
51 final JsonObject tagger = Json.createObjectBuilder()
52 .add("name", "Scott").add("email", "scott@gmail.com")
53 .add("date", "2011-06-17T14:53:35-07:00").build();
54 final JsonObject input = Json.createObjectBuilder()
55 .add("tag", "v.0.1").add("message", "initial version")
56 .add("object", "07cd4r45Test444").add("type", "commit")
57 .add("tagger", tagger).build();
58 try {
59 MatcherAssert.assertThat(
60 "Object is not of expected type",
61 tags.create(input),
62 Matchers.instanceOf(Tag.class)
63 );
64 MatcherAssert.assertThat(
65 "Values are not equal",
66 container.take().method(),
67 Matchers.equalTo(Request.POST)
68 );
69 MatcherAssert.assertThat(
70 "Values are not equal",
71 container.take().method(),
72 Matchers.equalTo(Request.POST)
73 );
74 } finally {
75 container.stop();
76 }
77 }
78 }