Improve the code coverage
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / common / restclient / TestRestfulParametes.java
1 /*
2  * Copyright 2017 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertNull;
21
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import org.junit.After;
26 import org.junit.AfterClass;
27 import org.junit.Before;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30
31 /**
32  * <br/>
33  * <p>
34  * </p>
35  * 
36  * @author
37  * @version
38  */
39 public class TestRestfulParametes {
40
41     /**
42      * <br/>
43      * 
44      * @throws java.lang.Exception
45      * @since
46      */
47     @BeforeClass
48     public static void setUpBeforeClass() throws Exception {
49     }
50
51     /**
52      * <br/>
53      * 
54      * @throws java.lang.Exception
55      * @since
56      */
57     @AfterClass
58     public static void tearDownAfterClass() throws Exception {
59     }
60
61     /**
62      * <br/>
63      * 
64      * @throws java.lang.Exception
65      * @since
66      */
67     @Before
68     public void setUp() throws Exception {
69     }
70
71     /**
72      * <br/>
73      * 
74      * @throws java.lang.Exception
75      * @since
76      */
77     @After
78     public void tearDown() throws Exception {
79     }
80
81     /**
82      * <br/>
83      * 
84      * @since
85      */
86     @Test
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"));
94     }
95
96     /**
97      * <br/>
98      * 
99      * @since
100      */
101     @Test
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());
107     }
108
109     /**
110      * <br/>
111      * 
112      * @since
113      */
114     @Test
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());
121     }
122
123     /**
124      * <br/>
125      * 
126      * @since
127      */
128     @Test
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"));
135     }
136
137     /**
138      * <br/>
139      * 
140      * @since
141      */
142     @Test
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"));
147     }
148
149     /**
150      * <br/>
151      * 
152      * @since
153      */
154     @Test
155     public void testPutHttpContextHeaderStringInt() {
156         final RestfulParametes params = new RestfulParametes();
157         params.putHttpContextHeader("Expire-At", 1000);
158         assertEquals("1000", params.getHttpContextHeader("Expire-At"));
159     }
160
161     /**
162      * <br/>
163      * 
164      * @since
165      */
166     @Test
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"));
173     }
174
175     /**
176      * <br/>
177      * 
178      * @since
179      */
180     @Test
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"));
186     }
187
188     /**
189      * <br/>
190      * 
191      * @since
192      */
193     @Test
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"));
200
201     }
202
203     /**
204      * <br/>
205      * 
206      * @since
207      */
208     @Test
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"));
214     }
215
216     /**
217      * <br/>
218      * 
219      * @since
220      */
221     @Test
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"));
228     }
229 }