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