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.Assert;
44  import org.junit.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          Assert.assertNotNull("request should not be null", request);
53          Assert.assertEquals("Default method should be GET", "GET", request.get(METHOD));
54  
55          Assert.assertEquals("Default request body expected.",
56                  TestingFramework.DEFAULT_REQUEST_BODY,
57                  request.get(BODY));
58  
59          Assert.assertEquals("Default request content type expected.",
60                  TestingFramework.DEFAULT_REQUEST_CONTENT_TYPE,
61                  request.get(CONTENT_TYPE));
62  
63          Assert.assertEquals("Default request query parameters expected.",
64                              TestingFramework.DEFAULT_REQUEST_QUERY,
65                              request.get(QUERY));
66  
67          Assert.assertEquals("Default request headers expected.",
68                              TestingFramework.DEFAULT_REQUEST_HEADERS,
69                              request.get(HEADERS));
70  
71          Assert.assertEquals("Default protocol version expected.",
72                  TestingFramework.DEFAULT_REQUEST_PROTOCOL_VERSION,
73                  request.get(PROTOCOL_VERSION));
74  
75          final Map<String, Object> responseExpectations = test.initResponseExpectations();
76          Assert.assertNotNull("responseExpectations should not be null", responseExpectations);
77          Assert.assertEquals("Default status expected.", TestingFramework.DEFAULT_RESPONSE_STATUS,
78                              responseExpectations.get(STATUS));
79  
80          Assert.assertEquals("Default body expected.", TestingFramework.DEFAULT_RESPONSE_BODY,
81                              responseExpectations.get(BODY));
82  
83          Assert.assertEquals("Default response content type expected.", TestingFramework.DEFAULT_RESPONSE_CONTENT_TYPE,
84                  responseExpectations.get(CONTENT_TYPE));
85  
86          Assert.assertEquals("Default headers expected.", TestingFramework.DEFAULT_RESPONSE_HEADERS,
87                              responseExpectations.get(HEADERS));
88      }
89  
90      @Test
91      public void changeStatus() throws Exception {
92          final Map<String, Object> testMap = new HashMap<>();
93          final Map<String, Object> response = new HashMap<>();
94          testMap.put(RESPONSE, response);
95          response.put(STATUS, 201);
96  
97          final FrameworkTest test = new FrameworkTest(testMap);
98          final Map<String, Object> responseExpectations = test.initResponseExpectations();
99  
100         Assert.assertEquals("Status unexpected.", 201, responseExpectations.get(STATUS));
101     }
102 
103     @Test
104     public void changeMethod() throws Exception {
105         final Map<String, Object> testMap = new HashMap<>();
106         final Map<String, Object> request = new HashMap<>();
107         testMap.put(REQUEST, request);
108         request.put(METHOD, "POST");
109 
110         final FrameworkTest test = new FrameworkTest(testMap);
111         final Map<String, Object> requestExpectations = test.initRequest();
112 
113         Assert.assertEquals("Method unexpected.", "POST", requestExpectations.get(METHOD));
114     }
115 }