add license file for CII Badge application
[msb/java-sdk.git] / src / test / java / org / onap / msb / sdk / discovery / util / JacksonJsonUtilTest.java
1 /**
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  * 
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * 
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14
15 package org.onap.msb.sdk.discovery.util;
16
17 import com.fasterxml.jackson.core.type.TypeReference;
18 import java.util.List;
19 import java.util.Map;
20
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.onap.msb.sdk.discovery.entity.NodeAddress;
24
25
26 public class JacksonJsonUtilTest {
27     @Test
28     public void testBeanToJson() {
29         try {
30             NodeAddress address = new NodeAddress("127.0.0.1", "80");
31             String json = JacksonJsonUtil.beanToJson(address);
32             Assert.assertEquals("{\"ip\":\"127.0.0.1\",\"port\":\"80\"}", json);
33         } catch (Exception e) {
34             Assert.fail("Exception" + e.getMessage());
35         }
36     }
37
38     @Test
39     public void testJsonToBean() {
40         try {
41             String json = "{\"ip\":\"127.0.0.1\",\"port\":\"80\"}";
42             NodeAddress address = (NodeAddress) JacksonJsonUtil.jsonToBean(json, NodeAddress.class);
43             Assert.assertEquals("127.0.0.1", address.getIp());
44             Assert.assertEquals("80", address.getPort());
45         } catch (Exception e) {
46             Assert.fail("Exception" + e.getMessage());
47         }
48     }
49 }