b3bf2b8c25219f05a21f1f0535e66b0c1ebe1e93
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * 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, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.adapters.json;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.mock;
25
26 import java.util.Map;
27
28 import org.codehaus.jackson.JsonParser;
29 import org.codehaus.jackson.map.DeserializationContext;
30 import org.codehaus.jackson.map.ObjectMapper;
31 import org.codehaus.jettison.json.JSONException;
32 import org.codehaus.jettison.json.JSONObject;
33 import org.junit.Test;
34
35 public class MapDeserializerTest {
36
37     private static final String MAP_KEY = "keyTest";
38     private static final String MAP_VALUE = "valueTest";
39
40     @Test
41     public void mapWithProperValuesIsReturned() throws Exception {
42         JsonParser parser = new ObjectMapper().getJsonFactory().createJsonParser(getJsonAsString());
43         MapDeserializer testedObject = new MapDeserializer();
44         Map<String, String> params = testedObject.deserialize(parser, mock(DeserializationContext.class));
45         assertThat(params).hasSize(1).containsEntry(MAP_KEY, MAP_VALUE);
46     }
47
48     private String getJsonAsString() throws JSONException {
49         JSONObject child2 = new JSONObject();
50         child2.put("key", MAP_KEY);
51         child2.put("value", MAP_VALUE);
52         JSONObject child1 = new JSONObject();
53         child1.put("child2", child2);
54         JSONObject parent = new JSONObject();
55         parent.put("child1", child1);
56         return parent.toString();
57     }
58 }