blob: a6c4bc3fda8e653d185b4df8d7b162e52f461854 [file] [log] [blame]
Jian Lidea0fdb2018-04-02 19:02:48 +09001/*
2 * Copyright 2018-present Open Networking Foundation
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 */
16package org.onosproject.openstacknetworking.util;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import com.google.common.testing.EqualsTester;
20import org.apache.commons.io.IOUtils;
21import org.junit.After;
22import org.junit.Before;
23import org.junit.Test;
24import org.openstack4j.model.network.NetFloatingIP;
25import org.openstack4j.openstack.networking.domain.NeutronFloatingIP;
26
27import java.io.IOException;
28import java.io.InputStream;
29import java.nio.charset.StandardCharsets;
30
31public final class OpenstackNetworkingUtilTest {
32
33 private NetFloatingIP floatingIp;
34
35 @Before
36 public void setUp() {
37 floatingIp = NeutronFloatingIP.builder()
38 .floatingNetworkId("floatingNetworkingId")
39 .portId("portId")
40 .build();
41 }
42
43 @After
44 public void tearDown() {
45 }
46
47 /**
48 * Tests the floatingIp translation.
49 */
50 @Test
51 public void testFloatingIp() throws IOException {
52 ObjectNode floatingIpNode =
53 OpenstackNetworkingUtil.modelEntityToJson(floatingIp, NeutronFloatingIP.class);
54 InputStream is = IOUtils.toInputStream(floatingIpNode.toString(), StandardCharsets.UTF_8.name());
55 NetFloatingIP floatingIp2 = (NetFloatingIP)
56 OpenstackNetworkingUtil.jsonToModelEntity(is, NeutronFloatingIP.class);
57 new EqualsTester().addEqualityGroup(floatingIp, floatingIp2).testEquals();
58 }
59}