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.mockito.Mockito.mock;
24 import static org.mockito.Mockito.verify;
26 import java.util.HashMap;
29 import org.codehaus.jackson.JsonGenerator;
30 import org.codehaus.jackson.map.SerializerProvider;
31 import org.junit.Test;
33 public class MapSerializerTest {
35 private static final String JSON_FIELD_NAME_1 = "testKey1";
36 private static final String JSON_VALUE_1 = "testValue1";
37 private static final String JSON_FIELD_NAME_2 = "testKey2";
38 private static final String JSON_VALUE_2 = "testValue2";
41 public void serializationWritesTheProperFieldsToJson() throws Exception {
42 JsonGenerator jsonGeneratorMock = mock(JsonGenerator.class);
43 MapSerializer testedObject = new MapSerializer();
44 testedObject.serialize(prepareMap(), jsonGeneratorMock, mock(SerializerProvider.class));
45 verify(jsonGeneratorMock).writeStringField("key", JSON_FIELD_NAME_1);
46 verify(jsonGeneratorMock).writeStringField("value", JSON_VALUE_1);
47 verify(jsonGeneratorMock).writeStringField("key", JSON_FIELD_NAME_2);
48 verify(jsonGeneratorMock).writeStringField("value", JSON_VALUE_2);
51 private Map<String, String> prepareMap() {
52 Map<String, String> map = new HashMap<>();
53 map.put(JSON_FIELD_NAME_1, JSON_VALUE_1);
54 map.put(JSON_FIELD_NAME_2, JSON_VALUE_2);