2 * Copyright (c) 2016, Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openo.baseservice.roa.util.restclient;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNull;
22 import org.junit.After;
23 import org.junit.AfterClass;
24 import org.junit.Before;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
28 import java.util.HashMap;
37 * @version SDNO 0.5 21-Jun-2016
39 public class TestRestfulParametes {
44 * @throws java.lang.Exception
48 public static void setUpBeforeClass() throws Exception {
54 * @throws java.lang.Exception
58 public static void tearDownAfterClass() throws Exception {
64 * @throws java.lang.Exception
68 public void setUp() throws Exception {
74 * @throws java.lang.Exception
78 public void tearDown() throws Exception {
87 public void testGet() {
88 final RestfulParametes params = new RestfulParametes();
89 assertNull(params.get("param"));
90 final Map<String, String> paramMap = new HashMap<String, String>();
91 params.setParamMap(paramMap);
92 paramMap.put("param", "value");
93 assertEquals("value", params.get("param"));
102 public void testSetRawData() {
103 final RestfulParametes params = new RestfulParametes();
104 final String data = "Sample data.";
105 params.setRawData(data);
106 assertEquals(data, params.getRawData());
115 public void testGetRawData() {
116 final RestfulParametes params = new RestfulParametes();
117 assertNull(params.getRawData());
118 final String data = "Sample data.";
119 params.setRawData(data);
120 assertEquals(data, params.getRawData());
129 public void testPut() {
130 final RestfulParametes params = new RestfulParametes();
131 params.put("somekey", "somevalue");
132 params.put("otherkey", "othervalue");
133 assertEquals("somevalue", params.get("somekey"));
134 assertEquals("othervalue", params.get("otherkey"));
143 public void testPutHttpContextHeaderStringString() {
144 final RestfulParametes params = new RestfulParametes();
145 params.putHttpContextHeader("Context-Encoding", "UTF-8");
146 assertEquals("UTF-8", params.getHttpContextHeader("Context-Encoding"));
155 public void testPutHttpContextHeaderStringInt() {
156 final RestfulParametes params = new RestfulParametes();
157 params.putHttpContextHeader("Expire-At", 1000);
158 assertEquals("1000", params.getHttpContextHeader("Expire-At"));
167 public void testGetHttpContextHeader() {
168 final RestfulParametes params = new RestfulParametes();
169 params.putHttpContextHeader("Expire-At", 1000);
170 params.putHttpContextHeader("Context-Encoding", "UTF-8");
171 assertEquals("1000", params.getHttpContextHeader("Expire-At"));
172 assertEquals("UTF-8", params.getHttpContextHeader("Context-Encoding"));
181 public void testGetParamMap() {
182 final RestfulParametes params = new RestfulParametes();
183 params.put("key", "value");
184 final Map<String, String> map = params.getParamMap();
185 assertEquals("value", map.get("key"));
194 public void testSetParamMap() {
195 final RestfulParametes params = new RestfulParametes();
196 final Map<String, String> map = new HashMap<String, String>();
197 map.put("key", "value");
198 params.setParamMap(map);
199 assertEquals("value", params.get("key"));
209 public void testGetHeaderMap() {
210 final RestfulParametes params = new RestfulParametes();
211 params.putHttpContextHeader("key", "value");
212 final Map<String, String> map = params.getHeaderMap();
213 assertEquals("value", map.get("key"));
222 public void testSetHeaderMap() {
223 final RestfulParametes params = new RestfulParametes();
224 final Map<String, String> map = new HashMap<String, String>();
225 map.put("key", "value");
226 params.setHeaderMap(map);
227 assertEquals("value", params.getHttpContextHeader("key"));