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
31 package com.jcabi.github;
32
33 import com.jcabi.github.mock.MkGithub;
34 import com.jcabi.http.Request;
35 import com.jcabi.http.mock.MkAnswer;
36 import com.jcabi.http.mock.MkContainer;
37 import com.jcabi.http.mock.MkGrizzlyContainer;
38 import com.jcabi.http.request.ApacheRequest;
39 import java.net.HttpURLConnection;
40 import javax.json.Json;
41 import javax.json.JsonObject;
42 import org.hamcrest.MatcherAssert;
43 import org.hamcrest.Matchers;
44 import org.junit.Rule;
45 import org.junit.Test;
46
47
48
49
50
51
52
53 public final class RtTagsTest {
54
55
56
57
58
59 @Rule
60 public final transient RandomPort resource = new RandomPort();
61
62
63
64
65
66
67 @Test
68 public void createsTag() throws Exception {
69 final MkContainer container = new MkGrizzlyContainer().next(
70 new MkAnswer.Simple(
71 HttpURLConnection.HTTP_CREATED,
72 "{\"sha\":\"0abcd89jcabitest\",\"tag\":\"v.0.1\"}"
73 )
74 ).next(
75 new MkAnswer.Simple(
76 HttpURLConnection.HTTP_CREATED,
77 "{\"ref\":\"refs/heads/feature-a\"}"
78 )
79 ).start(this.resource.port());
80 final Tags tags = new RtTags(
81 new ApacheRequest(container.home()),
82 new MkGithub().randomRepo()
83 );
84 final JsonObject tagger = Json.createObjectBuilder()
85 .add("name", "Scott").add("email", "scott@gmail.com")
86 .add("date", "2011-06-17T14:53:35-07:00").build();
87 final JsonObject input = Json.createObjectBuilder()
88 .add("tag", "v.0.1").add("message", "initial version")
89 .add("object", "07cd4r45Test444").add("type", "commit")
90 .add("tagger", tagger).build();
91 try {
92 MatcherAssert.assertThat(
93 tags.create(input),
94 Matchers.instanceOf(Tag.class)
95 );
96 MatcherAssert.assertThat(
97 container.take().method(),
98 Matchers.equalTo(Request.POST)
99 );
100 MatcherAssert.assertThat(
101 container.take().method(),
102 Matchers.equalTo(Request.POST)
103 );
104 } finally {
105 container.stop();
106 }
107 }
108 }