Merge "Reorder modifiers"
[so.git] / adapters / mso-adapters-rest-interface / src / test / java / org / openecomp / mso / adapters / json / MapSerializerTest.java
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.mockito.Mockito.mock;
24 import static org.mockito.Mockito.verify;
25
26 import java.util.HashMap;
27 import java.util.Map;
28 import org.codehaus.jackson.JsonGenerator;
29 import org.codehaus.jackson.map.SerializerProvider;
30 import org.junit.Test;
31
32 public class MapSerializerTest {
33
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";
38
39     @Test
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);
48     }
49
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);
54         return map;
55     }
56 }