2 * Copyright 2016-2017 ZTE, Inc. and others.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
15 package org.onap.msb.sdk.discovery.util;
17 import com.fasterxml.jackson.core.type.TypeReference;
18 import java.util.List;
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.onap.msb.sdk.discovery.entity.NodeAddress;
26 public class JacksonJsonUtilTest {
28 public void testBeanToJson() {
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());
39 public void testJsonToBean() {
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());