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;
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;
35 public class MapDeserializerTest {
37 private static final String MAP_KEY = "keyTest";
38 private static final String MAP_VALUE = "valueTest";
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);
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();