2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.netconf.topology.spi;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
13 import java.util.NoSuchElementException;
14 import org.junit.Test;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.DomainName;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
17 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress;
18 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231121.credentials.credentials.LoginPwUnencryptedBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev231121.credentials.credentials.login.pw.unencrypted.LoginPasswordUnencryptedBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev231121.NetconfNodeBuilder;
23 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
24 import org.opendaylight.yangtools.yang.common.Decimal64;
25 import org.opendaylight.yangtools.yang.common.Uint16;
26 import org.opendaylight.yangtools.yang.common.Uint32;
28 public class NetconfNodeUtilsTest {
30 public void testCreateRemoteDeviceId() {
31 final var host = new Host(new IpAddress(new Ipv4Address("127.0.0.1")));
32 final var id = NetconfNodeUtils.toRemoteDeviceId(new NodeId("testing-node"), new NetconfNodeBuilder()
34 .setPort(new PortNumber(Uint16.valueOf(9999)))
37 assertEquals("testing-node", id.name());
38 assertEquals(host, id.host());
39 assertEquals(9999, id.address().getPort());
43 public void toInetSocketAddressRequiresHostPort() {
44 // Creates a netconfNode without specifying a Port and Host.
45 final var builder = new NetconfNodeBuilder()
46 .setReconnectOnChangedSchema(true)
49 .setSleepFactor(Decimal64.valueOf("1.5"))
50 .setConcurrentRpcLimit(Uint16.ONE)
51 // One reconnection attempt
52 .setMaxConnectionAttempts(Uint32.TWO)
53 .setDefaultRequestTimeoutMillis(Uint32.valueOf(1000))
54 .setBetweenAttemptsTimeoutMillis(Uint16.valueOf(100))
55 .setKeepaliveDelay(Uint32.valueOf(1000))
56 .setConnectionTimeoutMillis(Uint32.valueOf(1000))
57 .setCredentials(new LoginPwUnencryptedBuilder()
58 .setLoginPasswordUnencrypted(new LoginPasswordUnencryptedBuilder()
59 .setUsername("testuser")
60 .setPassword("testpassword")
64 assertEquals("Value of host is not present", assertThrows(NoSuchElementException.class,
65 () -> NetconfNodeUtils.toInetSocketAddress(builder.build())).getMessage());
67 builder.setHost(new Host(new DomainName("testhost")));
68 assertEquals("Value of port is not present", assertThrows(NoSuchElementException.class,
69 () -> NetconfNodeUtils.toInetSocketAddress(builder.build())).getMessage());