Centralize NetconfNode/InetSocketAddress conversion
[netconf.git] / netconf / netconf-topology / src / test / java / org / opendaylight / netconf / topology / spi / NetconfNodeUtilsTest.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.topology.spi;
9
10 import static org.junit.Assert.assertEquals;
11
12 import org.junit.Test;
13 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeBuilder;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
20 import org.opendaylight.yangtools.yang.common.Uint16;
21
22 public class NetconfNodeUtilsTest {
23     @Test
24     public void testCreateRemoteDeviceId() {
25         final Host host = new Host(new IpAddress(new Ipv4Address("127.0.0.1")));
26         final RemoteDeviceId id = NetconfNodeUtils.toRemoteDeviceId(new NodeId("testing-node"), new NetconfNodeBuilder()
27             .setHost(host)
28             .setPort(new PortNumber(Uint16.valueOf(9999)))
29             .build());
30
31         assertEquals("testing-node", id.getName());
32         assertEquals(host, id.getHost());
33         assertEquals(9999, id.getAddress().getPort());
34     }
35 }