From f1f61eda2b6a2c2976e7e1d8f8f8de6cb17f7be7 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Thu, 17 Dec 2020 00:39:22 +0100 Subject: [PATCH] Hide NetconfTopologyRPCProvider.encryptPassword() This method is exposed for testing, move its correspoding test to the same package, reducing the method's visibility. Change-Id: I1bdb2d893e8343e16e96797c95e59f27e43aa7bb Signed-off-by: Robert Varga --- .../util/NetconfTopologyRPCProvider.java | 10 ++++---- .../util/NetconfTopologyRPCProviderTest.java | 24 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) rename netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/{netconf => }/util/NetconfTopologyRPCProviderTest.java (88%) diff --git a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java index b7a1489ae9..cd188e1dbd 100644 --- a/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java +++ b/netconf/sal-netconf-connector/src/main/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProvider.java @@ -64,7 +64,7 @@ public class NetconfTopologyRPCProvider implements NetconfNodeTopologyService { @Override public ListenableFuture> createDevice(final CreateDeviceInput input) { - final NetconfNode node = this.encryptPassword(input); + final NetconfNode node = encryptPassword(input); final SettableFuture> futureResult = SettableFuture.create(); final NodeId nodeId = new NodeId(input.getNodeId()); writeToConfigDS(node, nodeId, futureResult); @@ -72,14 +72,12 @@ public class NetconfTopologyRPCProvider implements NetconfNodeTopologyService { } @VisibleForTesting - public NetconfNode encryptPassword(final CreateDeviceInput input) { + NetconfNode encryptPassword(final CreateDeviceInput input) { final NetconfNodeBuilder builder = new NetconfNodeBuilder(); builder.fieldsFrom(input); - final Credentials credentials = handleEncryption(input.getCredentials()); - builder.setCredentials(credentials); - - return builder.build(); + return builder.setCredentials(handleEncryption(input.getCredentials())) + .build(); } private Credentials handleEncryption(final Credentials credentials) { diff --git a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfTopologyRPCProviderTest.java b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProviderTest.java similarity index 88% rename from netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfTopologyRPCProviderTest.java rename to netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProviderTest.java index f29b96f819..0247e995b8 100644 --- a/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/netconf/util/NetconfTopologyRPCProviderTest.java +++ b/netconf/sal-netconf-connector/src/test/java/org/opendaylight/netconf/sal/connect/util/NetconfTopologyRPCProviderTest.java @@ -5,7 +5,7 @@ * 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.netconf.sal.connect.netconf.util; +package org.opendaylight.netconf.sal.connect.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -18,7 +18,6 @@ import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import org.opendaylight.aaa.encrypt.AAAEncryptionService; import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.netconf.sal.connect.util.NetconfTopologyRPCProvider; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress; import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address; @@ -49,7 +48,7 @@ public class NetconfTopologyRPCProviderTest { @Mock private AAAEncryptionService encryptionService; - private NetconfTopologyRPCProvider rpcProvider ; + private NetconfTopologyRPCProvider rpcProvider; @Before public void setUp() { @@ -58,7 +57,7 @@ public class NetconfTopologyRPCProviderTest { } @Test - public void testEncryptPassword() throws Exception { + public void testEncryptPassword() { final NetconfNode encryptedPwNode = rpcProvider.encryptPassword(getInput(true)); @@ -70,7 +69,7 @@ public class NetconfTopologyRPCProviderTest { } @Test - public void testNoEncryption() throws Exception { + public void testNoEncryption() { final NetconfNode encryptedPwNode = rpcProvider.encryptPassword(getInput(false)); final Credentials credentials = encryptedPwNode.getCredentials(); @@ -91,12 +90,13 @@ public class NetconfTopologyRPCProviderTest { new LoginPasswordUnencryptedBuilder().setUsername("test").setPassword(TEST_PWD).build()).build(); } - builder.setCredentials(credentials); - builder.setHost(new Host(new IpAddress(new Ipv4Address("10.18.16.188")))); - builder.setPort(new PortNumber(Uint16.valueOf(830))); - builder.setTcpOnly(Boolean.FALSE); - builder.setNodeId(NODE_ID.toString()); - return builder.build(); + return builder + .setCredentials(credentials) + .setHost(new Host(new IpAddress(new Ipv4Address("10.18.16.188")))) + .setPort(new PortNumber(Uint16.valueOf(830))) + .setTcpOnly(Boolean.FALSE) + // FIXME: do we really want 'toString()' here? + .setNodeId(NODE_ID.toString()) + .build(); } - } -- 2.36.6