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 package org.apache.hc.core5.testing.framework;
29
30 import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.BODY;
31 import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.CONTENT_TYPE;
32 import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.HEADERS;
33 import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.METHOD;
34 import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.PROTOCOL_VERSION;
35 import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.QUERY;
36 import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.REQUEST;
37 import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.RESPONSE;
38 import static org.apache.hc.core5.testing.framework.ClientPOJOAdapter.STATUS;
39
40 import java.util.HashMap;
41 import java.util.Map;
42
43 import org.junit.jupiter.api.Assertions;
44 import org.junit.jupiter.api.Test;
45
46 public class TestFrameworkTest {
47 @Test
48 public void defaults() throws Exception {
49 final FrameworkTest test = new FrameworkTest();
50 final Map<String, Object> request = test.initRequest();
51
52 Assertions.assertNotNull(request, "request should not be null");
53 Assertions.assertEquals(request.get(METHOD), "GET", "Default method should be GET");
54
55 Assertions.assertEquals(TestingFramework.DEFAULT_REQUEST_BODY,
56 request.get(BODY), "Default request body expected.");
57
58 Assertions.assertEquals(TestingFramework.DEFAULT_REQUEST_CONTENT_TYPE,
59 request.get(CONTENT_TYPE), "Default request content type expected.");
60
61 Assertions.assertEquals(TestingFramework.DEFAULT_REQUEST_QUERY,
62 request.get(QUERY), "Default request query parameters expected.");
63
64 Assertions.assertEquals(TestingFramework.DEFAULT_REQUEST_HEADERS,
65 request.get(HEADERS), "Default request headers expected.");
66
67 Assertions.assertEquals(TestingFramework.DEFAULT_REQUEST_PROTOCOL_VERSION,
68 request.get(PROTOCOL_VERSION), "Default protocol version expected.");
69
70 final Map<String, Object> responseExpectations = test.initResponseExpectations();
71 Assertions.assertNotNull(responseExpectations, "responseExpectations should not be null");
72 Assertions.assertEquals(TestingFramework.DEFAULT_RESPONSE_STATUS,
73 responseExpectations.get(STATUS), "Default status expected.");
74
75 Assertions.assertEquals(TestingFramework.DEFAULT_RESPONSE_BODY,
76 responseExpectations.get(BODY), "Default body expected.");
77
78 Assertions.assertEquals(TestingFramework.DEFAULT_RESPONSE_CONTENT_TYPE,
79 responseExpectations.get(CONTENT_TYPE), "Default response content type expected.");
80
81 Assertions.assertEquals(TestingFramework.DEFAULT_RESPONSE_HEADERS,
82 responseExpectations.get(HEADERS), "Default headers expected.");
83 }
84
85 @Test
86 public void changeStatus() throws Exception {
87 final Map<String, Object> testMap = new HashMap<>();
88 final Map<String, Object> response = new HashMap<>();
89 testMap.put(RESPONSE, response);
90 response.put(STATUS, 201);
91
92 final FrameworkTest test = new FrameworkTest(testMap);
93 final Map<String, Object> responseExpectations = test.initResponseExpectations();
94
95 Assertions.assertEquals(201, responseExpectations.get(STATUS), "Status unexpected.");
96 }
97
98 @Test
99 public void changeMethod() throws Exception {
100 final Map<String, Object> testMap = new HashMap<>();
101 final Map<String, Object> request = new HashMap<>();
102 testMap.put(REQUEST, request);
103 request.put(METHOD, "POST");
104
105 final FrameworkTest test = new FrameworkTest(testMap);
106 final Map<String, Object> requestExpectations = test.initRequest();
107
108 Assertions.assertEquals("POST", requestExpectations.get(METHOD), "Method unexpected.");
109 }
110 }