SVNFM codehaus jackson vulnerability fix
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / testutils / JsonUtilTest.java
1 /*
2  * Copyright 2016 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.testutils;
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.entity.Vnfm;
22
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import static org.junit.Assert.assertEquals;
29
30 public class JsonUtilTest {
31
32     Vnfm vnfm;
33
34     @Before
35     public void setUp(){
36         vnfm = new Vnfm();
37     }
38
39     @Test
40     public void testMarshal() throws IOException {
41         vnfm.setId("123");
42         vnfm.setVersion("V1.0.0");
43         JsonUtil.marshal(vnfm);
44         assertEquals("123",vnfm.getId());
45     }
46
47     @Test
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());
52     }
53     @Test
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());
58     }
59     @Test
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"));
64     }
65 }