1
2
3
4
5 package com.jcabi.http.wire;
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.mock.MkQuery;
12 import com.jcabi.http.request.JdkRequest;
13 import com.jcabi.http.response.RestResponse;
14 import jakarta.ws.rs.core.HttpHeaders;
15 import java.net.HttpURLConnection;
16 import org.hamcrest.MatcherAssert;
17 import org.hamcrest.Matchers;
18 import org.junit.jupiter.api.Test;
19
20
21
22
23
24 final class VerboseWireTest {
25
26
27
28
29
30 @Test
31 void logsRequest() throws Exception {
32 final MkContainer container = new MkGrizzlyContainer().next(
33 new MkAnswer.Simple("")
34 ).start();
35 new JdkRequest(container.home())
36 .through(VerboseWire.class)
37 .header(HttpHeaders.USER_AGENT, "it's me")
38 .fetch()
39 .as(RestResponse.class)
40 .assertStatus(HttpURLConnection.HTTP_OK);
41 container.stop();
42 }
43
44
45
46
47
48 @Test
49 void logsRequestBody() throws Exception {
50 final MkContainer container = new MkGrizzlyContainer().next(
51 new MkAnswer.Simple("")
52 ).start();
53 try {
54 new JdkRequest(container.home())
55 .through(VerboseWire.class)
56 .method(Request.POST)
57 .body().set("hello, world!").back()
58 .fetch()
59 .as(RestResponse.class)
60 .assertStatus(HttpURLConnection.HTTP_OK);
61 final MkQuery query = container.take();
62 MatcherAssert.assertThat(
63 "should starts with 'hello,'",
64 query.body(),
65 Matchers.startsWith("hello,")
66 );
67 } finally {
68 container.stop();
69 }
70 }
71
72 }