2 * Copyright 2016 Huawei Technologies Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.testutils;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.entity.Vnfm;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.HashMap;
28 import static org.junit.Assert.assertEquals;
30 public class JsonUtilTest {
40 public void testMarshal() throws IOException {
42 vnfm.setVersion("V1.0.0");
43 JsonUtil.marshal(vnfm);
44 assertEquals("123",vnfm.getId());
48 public void testUnMarshal() throws IOException {
49 String jsonValue="{\"id\":\"12345\",\"version\":\"V1.0.0\"}";
50 Vnfm actual = JsonUtil.unMarshal(jsonValue,Vnfm.class);
51 assertEquals("V1.0.0",actual.getVersion());
54 public void testUnMarshalWithUnknownField() throws IOException {
55 String jsonValue="{\"id\":\"12345\",\"version\":\"V1.0.0\",\"unknownField\":\"unknownValue\"}";
56 Vnfm actual = JsonUtil.unMarshal(jsonValue,Vnfm.class);
57 assertEquals("V1.0.0",actual.getVersion());
60 public void testUnMarshalForTypeReference() throws IOException {
61 String jsonValue="{\"id\":\"12345\",\"version\":\"V1.0.0\",\"unknownField\":\"unknownValue\"}";
62 Map map = JsonUtil.unMarshal(jsonValue, HashMap.class);
63 assertEquals("V1.0.0",map.get("version"));