1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.http.Request;
8 import com.jcabi.http.mock.MkAnswer;
9 import com.jcabi.http.mock.MkContainer;
10 import com.jcabi.http.mock.MkGrizzlyContainer;
11 import com.jcabi.http.request.ApacheRequest;
12 import jakarta.json.Json;
13 import java.io.IOException;
14 import java.net.HttpURLConnection;
15 import org.hamcrest.MatcherAssert;
16 import org.hamcrest.Matchers;
17 import org.junit.jupiter.api.Test;
18 import org.junit.jupiter.api.extension.ExtendWith;
19 import org.mockito.Mockito;
20
21
22
23
24
25 @ExtendWith(RandomPort.class)
26 final class RtLabelTest {
27
28
29
30
31
32 @Test
33 void sendHttpRequestAndWriteResponseAsJson() throws IOException {
34 try (
35 MkContainer container = new MkGrizzlyContainer().next(
36 new MkAnswer.Simple(
37 HttpURLConnection.HTTP_OK,
38 "{\"msg\": \"hi\"}"
39 )
40 ).start(RandomPort.port())
41 ) {
42 final RtLabel label = new RtLabel(
43 new ApacheRequest(container.home()),
44 RtLabelTest.repo(),
45 "bug"
46 );
47 MatcherAssert.assertThat(
48 "Values are not equal",
49 label.json().getString("msg"),
50 Matchers.equalTo("hi")
51 );
52 container.stop();
53 }
54 }
55
56 @Test
57 void executePatchRequest() throws IOException {
58 try (
59 MkContainer container = new MkGrizzlyContainer().next(
60 new MkAnswer.Simple(
61 HttpURLConnection.HTTP_OK,
62 "{\"msg\":\"hi\"}"
63 )
64 ).start(RandomPort.port())
65 ) {
66 final RtLabel label = new RtLabel(
67 new ApacheRequest(container.home()),
68 RtLabelTest.repo(),
69 "enhance"
70 );
71 label.patch(
72 Json.createObjectBuilder()
73 .add("content", "hi you!")
74 .build()
75 );
76 MatcherAssert.assertThat(
77 "Values are not equal",
78 container.take().method(),
79 Matchers.equalTo(Request.PATCH)
80 );
81 container.stop();
82 }
83 }
84
85
86
87
88
89 private static Repo repo() {
90 final Repo repo = Mockito.mock(Repo.class);
91 Mockito.doReturn(new Coordinates.Simple("mark", "test"))
92 .when(repo).coordinates();
93 return repo;
94 }
95 }