Jian Li | dea0fdb | 2018-04-02 19:02:48 +0900 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.openstacknetworking.util; |
| 17 | |
| 18 | import com.fasterxml.jackson.databind.node.ObjectNode; |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.apache.commons.io.IOUtils; |
| 21 | import org.junit.After; |
| 22 | import org.junit.Before; |
| 23 | import org.junit.Test; |
| 24 | import org.openstack4j.model.network.NetFloatingIP; |
| 25 | import org.openstack4j.openstack.networking.domain.NeutronFloatingIP; |
| 26 | |
| 27 | import java.io.IOException; |
| 28 | import java.io.InputStream; |
| 29 | import java.nio.charset.StandardCharsets; |
| 30 | |
| 31 | public 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 | } |