View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
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 }