1
2
3
4
5 package com.jcabi.github;
6
7 import com.jcabi.http.mock.MkAnswer;
8 import com.jcabi.http.mock.MkContainer;
9 import com.jcabi.http.mock.MkGrizzlyContainer;
10 import com.jcabi.http.request.ApacheRequest;
11 import jakarta.json.Json;
12 import java.io.IOException;
13 import java.net.HttpURLConnection;
14 import org.hamcrest.MatcherAssert;
15 import org.hamcrest.Matchers;
16 import org.junit.jupiter.api.Test;
17 import org.junit.jupiter.api.extension.ExtendWith;
18
19
20
21
22
23 @ExtendWith(RandomPort.class)
24 final class RtJsonTest {
25
26
27
28
29 @Test
30 void sendHttpRequest() throws IOException {
31 try (
32 MkContainer container = new MkGrizzlyContainer().next(
33 new MkAnswer.Simple(
34 HttpURLConnection.HTTP_OK,
35 "{\"body\":\"hi\"}"
36 )
37 ).start(RandomPort.port())
38 ) {
39 final RtJson json = new RtJson(new ApacheRequest(container.home()));
40 MatcherAssert.assertThat(
41 "Values are not equal",
42 json.fetch().getString("body"),
43 Matchers.equalTo("hi")
44 );
45 container.stop();
46 }
47 }
48
49 @Test
50 void executePatchRequest() throws IOException {
51 try (
52 MkContainer container = new MkGrizzlyContainer().next(
53 new MkAnswer.Simple(
54 HttpURLConnection.HTTP_OK,
55 "{\"body\":\"hj\"}"
56 )
57 ).start(RandomPort.port())
58 ) {
59 final RtJson json = new RtJson(new ApacheRequest(container.home()));
60 json.patch(
61 Json.createObjectBuilder()
62 .add("content", "hi you!")
63 .build()
64 );
65 MatcherAssert.assertThat(
66 "Values are not equal",
67 container.take().method(),
68 Matchers.equalTo("PATCH")
69 );
70 container.stop();
71 }
72 }
73 }