From c9be0a11c57251c8586a3cdfc5401654e1dba21d Mon Sep 17 00:00:00 2001 From: Filip Tehlar Date: Wed, 17 Sep 2014 12:39:29 +0200 Subject: [PATCH] BUG-1521 netconf-util line coverage Change-Id: I90fc67622d95fa1b1e06fcf3c10a4d0ea40000c4 Signed-off-by: Filip Tehlar --- .../netconf/util/osgi/NetconfConfigUtil.java | 23 ----- .../AbstractLastNetconfOperationTest.java | 69 +++++++++++++++ .../mapping/AbstractNetconfOperationTest.java | 75 +++++++++++++++++ ...AbstractSingletonNetconfOperationTest.java | 43 ++++++++++ ...tconfHelloMessageAdditionalHeaderTest.java | 42 ++++++++++ .../messages/NetconfHelloMessageTest.java | 40 +++++++++ .../messages/NetconfMessageHeaderTest.java | 27 ++++++ .../util/messages/NetconfMessageUtilTest.java | 36 ++++++++ .../messages/SendErrorExceptionUtilTest.java | 62 ++++++++++++++ .../util/osgi/NetconfConfigUtilTest.java | 84 +++++++++++++++++++ 10 files changed, 478 insertions(+), 23 deletions(-) create mode 100644 opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractLastNetconfOperationTest.java create mode 100644 opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperationTest.java create mode 100644 opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractSingletonNetconfOperationTest.java create mode 100644 opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfHelloMessageAdditionalHeaderTest.java create mode 100644 opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfHelloMessageTest.java create mode 100644 opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageHeaderTest.java create mode 100644 opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageUtilTest.java create mode 100644 opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtilTest.java create mode 100644 opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtilTest.java diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java index 333fea3493..c77e0d7da2 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtil.java @@ -53,29 +53,6 @@ public final class NetconfConfigUtil { } } - /** - * Get extracted address or default. - * - * @throws java.lang.IllegalStateException if neither address is present. - */ - private static InetSocketAddress getNetconfAddress(final InetSocketAddress defaultAddress, Optional extractedAddress, InfixProp infix) { - InetSocketAddress inetSocketAddress; - - if (extractedAddress.isPresent() == false) { - logger.debug("Netconf {} address not found, falling back to default {}", infix, defaultAddress); - - if (defaultAddress == null) { - logger.warn("Netconf {} address not found, default address not provided", infix); - throw new IllegalStateException("Netconf " + infix + " address not found, default address not provided"); - } - inetSocketAddress = defaultAddress; - } else { - inetSocketAddress = extractedAddress.get(); - } - - return inetSocketAddress; - } - public static String getPrivateKeyPath(final BundleContext context) { return getPropertyValue(context, getPrivateKeyKey()); } diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractLastNetconfOperationTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractLastNetconfOperationTest.java new file mode 100644 index 0000000000..62633dd3f2 --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractLastNetconfOperationTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.util.mapping; + +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; +import org.opendaylight.controller.netconf.util.xml.XmlElement; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +public class AbstractLastNetconfOperationTest { + class LastNetconfOperationImplTest extends AbstractLastNetconfOperation { + + boolean handleWithNoSubsequentOperationsRun; + + protected LastNetconfOperationImplTest(String netconfSessionIdForReporting) { + super(netconfSessionIdForReporting); + handleWithNoSubsequentOperationsRun = false; + } + + @Override + protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws NetconfDocumentedException { + handleWithNoSubsequentOperationsRun = true; + return null; + } + + @Override + protected String getOperationName() { + return ""; + } + } + + LastNetconfOperationImplTest netconfOperation; + + @Before + public void setUp() throws Exception { + netconfOperation = new LastNetconfOperationImplTest(""); + } + + @Test + public void testNetconfOperation() throws Exception { + netconfOperation.handleWithNoSubsequentOperations(null, null); + assertTrue(netconfOperation.handleWithNoSubsequentOperationsRun); + assertEquals(HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY, netconfOperation.getHandlingPriority()); + } + + @Test(expected = NetconfDocumentedException.class) + public void testHandle() throws Exception { + NetconfOperationChainedExecution operation = mock(NetconfOperationChainedExecution.class); + doReturn("").when(operation).toString(); + + doReturn(false).when(operation).isExecutionTermination(); + netconfOperation.handle(null, null, operation); + } +} diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperationTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperationTest.java new file mode 100644 index 0000000000..ea4a6e61f2 --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractNetconfOperationTest.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.util.mapping; + +import java.io.IOException; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; +import org.opendaylight.controller.netconf.mapping.api.NetconfOperationChainedExecution; +import org.opendaylight.controller.netconf.util.test.XmlFileLoader; +import org.opendaylight.controller.netconf.util.xml.XmlElement; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; + +public class AbstractNetconfOperationTest { + + class NetconfOperationImpl extends AbstractNetconfOperation { + + public boolean handleRun; + + protected NetconfOperationImpl(String netconfSessionIdForReporting) { + super(netconfSessionIdForReporting); + this.handleRun = false; + } + + @Override + protected String getOperationName() { + return null; + } + + @Override + protected Element handle(Document document, XmlElement message, NetconfOperationChainedExecution subsequentOperation) throws NetconfDocumentedException { + this.handleRun = true; + try { + return XmlUtil.readXmlToElement(""); + } catch (SAXException | IOException e) { + throw new RuntimeException(e); + } + } + } + + private NetconfOperationImpl netconfOperation; + private NetconfOperationChainedExecution operation; + + @Before + public void setUp() throws Exception { + netconfOperation = new NetconfOperationImpl("str"); + operation = mock(NetconfOperationChainedExecution.class); + } + + @Test + public void testAbstractNetconfOperation() throws Exception { + Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/edit_config.xml"); + assertEquals(netconfOperation.getNetconfSessionIdForReporting(), "str"); + assertNotNull(netconfOperation.canHandle(helloMessage)); + assertEquals(netconfOperation.getHandlingPriority(), HandlingPriority.HANDLE_WITH_DEFAULT_PRIORITY); + + netconfOperation.handle(helloMessage, operation); + assertTrue(netconfOperation.handleRun); + } +} diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractSingletonNetconfOperationTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractSingletonNetconfOperationTest.java new file mode 100644 index 0000000000..d1310de3e2 --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/mapping/AbstractSingletonNetconfOperationTest.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.util.mapping; + +import org.junit.Test; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.mapping.api.HandlingPriority; +import org.opendaylight.controller.netconf.util.xml.XmlElement; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import static org.junit.Assert.assertEquals; + +public class AbstractSingletonNetconfOperationTest { + class SingletonNCOperationImpl extends AbstractSingletonNetconfOperation { + + protected SingletonNCOperationImpl(String netconfSessionIdForReporting) { + super(netconfSessionIdForReporting); + } + + @Override + protected Element handleWithNoSubsequentOperations(Document document, XmlElement operationElement) throws NetconfDocumentedException { + return null; + } + + @Override + protected String getOperationName() { + return null; + } + } + + @Test + public void testAbstractSingletonNetconfOperation() throws Exception { + SingletonNCOperationImpl operation = new SingletonNCOperationImpl(""); + assertEquals(operation.getHandlingPriority(), HandlingPriority.HANDLE_WITH_MAX_PRIORITY); + } +} diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfHelloMessageAdditionalHeaderTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfHelloMessageAdditionalHeaderTest.java new file mode 100644 index 0000000000..95c91243af --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfHelloMessageAdditionalHeaderTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.util.messages; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class NetconfHelloMessageAdditionalHeaderTest { + + + private String customHeader = "[user;1.1.1.1:40;tcp;client;]"; + private NetconfHelloMessageAdditionalHeader header; + + @Before + public void setUp() throws Exception { + header = new NetconfHelloMessageAdditionalHeader("user", "1.1.1.1", "40", "tcp", "client"); + } + + @Test + public void testGetters() throws Exception { + assertEquals(header.getAddress(), "1.1.1.1"); + assertEquals(header.getUserName(), "user"); + assertEquals(header.getPort(), "40"); + assertEquals(header.getTransport(), "tcp"); + assertEquals(header.getSessionIdentifier(), "client"); + } + + @Test + public void testStaticConstructor() throws Exception { + NetconfHelloMessageAdditionalHeader h = NetconfHelloMessageAdditionalHeader.fromString(customHeader); + assertEquals(h.toString(), header.toString()); + assertEquals(h.toFormattedString(), header.toFormattedString()); + } +} diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfHelloMessageTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfHelloMessageTest.java new file mode 100644 index 0000000000..c39ac8eb10 --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfHelloMessageTest.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.util.messages; + + +import com.google.common.base.Optional; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.mockito.internal.util.collections.Sets; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class NetconfHelloMessageTest { + + Set caps; + + @Before + public void setUp() throws Exception { + caps = Sets.newSet("cap1"); + } + + @Test + public void testConstructor() throws Exception { + NetconfHelloMessageAdditionalHeader additionalHeader = new NetconfHelloMessageAdditionalHeader("name","host","1","transp","id"); + NetconfHelloMessage message = NetconfHelloMessage.createClientHello(caps, Optional.of(additionalHeader)); + assertTrue(message.isHelloMessage(message)); + assertEquals(Optional.of(additionalHeader), message.getAdditionalHeader()); + + NetconfHelloMessage serverMessage = NetconfHelloMessage.createServerHello(caps, 100L); + assertTrue(serverMessage.isHelloMessage(serverMessage)); + } +} diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageHeaderTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageHeaderTest.java new file mode 100644 index 0000000000..cca89aed59 --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageHeaderTest.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.util.messages; + +import com.google.common.base.Charsets; +import java.util.Arrays; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +public class NetconfMessageHeaderTest { + @Test + public void testGet() throws Exception { + NetconfMessageHeader header = new NetconfMessageHeader(10); + assertEquals(header.getLength(), 10); + + byte[] expectedValue = "\n#10\n".getBytes(Charsets.US_ASCII); + assertArrayEquals(expectedValue, header.toBytes()); + } +} diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageUtilTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageUtilTest.java new file mode 100644 index 0000000000..2af34e957e --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/NetconfMessageUtilTest.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.util.messages; + +import java.util.Collection; +import org.junit.Test; +import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.util.test.XmlFileLoader; +import org.w3c.dom.Document; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class NetconfMessageUtilTest { + @Test + public void testNetconfMessageUtil() throws Exception { + Document okMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml"); + assertTrue(NetconfMessageUtil.isOKMessage(new NetconfMessage(okMessage))); + assertFalse(NetconfMessageUtil.isErrorMessage(new NetconfMessage(okMessage))); + + Document errorMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/communicationError/testClientSendsRpcReply_expectedResponse.xml"); + assertTrue(NetconfMessageUtil.isErrorMessage(new NetconfMessage(errorMessage))); + assertFalse(NetconfMessageUtil.isOKMessage(new NetconfMessage(errorMessage))); + + Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/client_hello.xml"); + Collection caps = NetconfMessageUtil.extractCapabilitiesFromHello(new NetconfMessage(helloMessage).getDocument()); + assertTrue(caps.contains("urn:ietf:params:netconf:base:1.0")); + assertTrue(caps.contains("urn:ietf:params:netconf:base:1.1")); + } +} diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtilTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtilTest.java new file mode 100644 index 0000000000..c8d562cb9c --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtilTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.util.messages; + +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.util.concurrent.GenericFutureListener; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.netconf.api.NetconfDocumentedException; +import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.api.NetconfSession; +import org.opendaylight.controller.netconf.util.test.XmlFileLoader; +import org.w3c.dom.Document; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.*; + +public class SendErrorExceptionUtilTest { + + NetconfSession netconfSession; + ChannelFuture channelFuture; + Channel channel; + private NetconfDocumentedException exception; + + @Before + public void setUp() throws Exception { + netconfSession = mock(NetconfSession.class); + channelFuture = mock(ChannelFuture.class); + channel = mock(Channel.class); + doReturn(channelFuture).when(netconfSession).sendMessage(any(NetconfMessage.class)); + doReturn(channelFuture).when(channelFuture).addListener(any(GenericFutureListener.class)); + doReturn(channelFuture).when(channel).writeAndFlush(any(NetconfMessage.class)); + exception = new NetconfDocumentedException("err"); + } + + @Test + public void testSendErrorMessage1() throws Exception { + SendErrorExceptionUtil.sendErrorMessage(netconfSession, exception); + verify(channelFuture, times(1)).addListener(any(GenericFutureListener.class)); + verify(netconfSession, times(1)).sendMessage(any(NetconfMessage.class)); + } + + @Test + public void testSendErrorMessage2() throws Exception { + SendErrorExceptionUtil.sendErrorMessage(channel, exception); + verify(channelFuture, times(1)).addListener(any(GenericFutureListener.class)); + } + + @Test + public void testSendErrorMessage3() throws Exception { + Document helloMessage = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc.xml"); + SendErrorExceptionUtil.sendErrorMessage(netconfSession, exception, new NetconfMessage(helloMessage)); + verify(channelFuture, times(1)).addListener(any(GenericFutureListener.class)); + } +} diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtilTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtilTest.java new file mode 100644 index 0000000000..741d0d2452 --- /dev/null +++ b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/osgi/NetconfConfigUtilTest.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.util.osgi; + +import com.google.common.base.Optional; +import io.netty.channel.local.LocalAddress; +import java.net.InetSocketAddress; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.controller.netconf.util.NetconfUtil; +import org.osgi.framework.BundleContext; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +public class NetconfConfigUtilTest { + + private BundleContext bundleContext; + + @Before + public void setUp() throws Exception { + bundleContext = mock(BundleContext.class); + } + + @Test + public void testNetconfConfigUtil() throws Exception { + assertEquals(NetconfConfigUtil.getNetconfLocalAddress(), new LocalAddress("netconf")); + + doReturn("").when(bundleContext).getProperty("netconf.connectionTimeoutMillis"); + assertEquals(NetconfConfigUtil.extractTimeoutMillis(bundleContext), 5000); + + doReturn("a").when(bundleContext).getProperty("netconf.connectionTimeoutMillis"); + assertEquals(NetconfConfigUtil.extractTimeoutMillis(bundleContext), 5000); + } + + @Test + public void testgetPrivateKeyKey() throws Exception { + assertEquals(NetconfConfigUtil.getPrivateKeyKey(), "netconf.ssh.pk.path"); + } + + @Test + public void testgetNetconfServerAddressKey() throws Exception { + NetconfConfigUtil.InfixProp prop = NetconfConfigUtil.InfixProp.tcp; + assertEquals(NetconfConfigUtil.getNetconfServerAddressKey(prop), "netconf.tcp.address"); + } + + @Test + public void testExtractNetconfServerAddress() throws Exception { + NetconfConfigUtil.InfixProp prop = NetconfConfigUtil.InfixProp.tcp; + doReturn("").when(bundleContext).getProperty(anyString()); + assertEquals(NetconfConfigUtil.extractNetconfServerAddress(bundleContext, prop), Optional.absent()); + } + + @Test + public void testExtractNetconfServerAddress2() throws Exception { + NetconfConfigUtil.InfixProp prop = NetconfConfigUtil.InfixProp.tcp; + doReturn("1.1.1.1").when(bundleContext).getProperty("netconf.tcp.address"); + doReturn("20").when(bundleContext).getProperty("netconf.tcp.port"); + Optional inetSocketAddressOptional = NetconfConfigUtil.extractNetconfServerAddress(bundleContext, prop); + assertTrue(inetSocketAddressOptional.isPresent()); + assertEquals(inetSocketAddressOptional.get(), new InetSocketAddress("1.1.1.1", 20)); + } + + @Test + public void testGetPrivateKeyPath() throws Exception { + doReturn("path").when(bundleContext).getProperty("netconf.ssh.pk.path"); + assertEquals(NetconfConfigUtil.getPrivateKeyPath(bundleContext), "path"); + } + + @Test(expected = IllegalStateException.class) + public void testGetPrivateKeyPath2() throws Exception { + doReturn(null).when(bundleContext).getProperty("netconf.ssh.pk.path"); + assertEquals(NetconfConfigUtil.getPrivateKeyPath(bundleContext), "path"); + } +} -- 2.36.6