2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.adapters.json;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.Mockito.mock;
27 import org.codehaus.jackson.JsonParser;
28 import org.codehaus.jackson.map.DeserializationContext;
29 import org.codehaus.jackson.map.ObjectMapper;
30 import org.json.JSONException;
31 import org.json.JSONObject;
32 import org.junit.Test;
34 public class MapDeserializerTest {
36 private static final String MAP_KEY = "keyTest";
37 private static final String MAP_VALUE = "valueTest";
40 public void mapWithProperValuesIsReturned() throws Exception {
41 JsonParser parser = new ObjectMapper().getJsonFactory().createJsonParser(getJsonAsString());
42 MapDeserializer testedObject = new MapDeserializer();
43 Map<String, String> params = testedObject.deserialize(parser, mock(DeserializationContext.class));
44 assertThat(params).hasSize(1).containsEntry(MAP_KEY, MAP_VALUE);
47 private String getJsonAsString() throws JSONException {
48 JSONObject child2 = new JSONObject();
49 child2.put("key", MAP_KEY);
50 child2.put("value", MAP_VALUE);
51 JSONObject child1 = new JSONObject();
52 child1.put("child2", child2);
53 JSONObject parent = new JSONObject();
54 parent.put("child1", child1);
55 return parent.toString();