*/
package org.opendaylight.netconf.topology.spi;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
-import java.util.Base64;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.aaa.encrypt.AAAEncryptionService;
import org.opendaylight.mdsal.binding.api.DataBroker;
import org.opendaylight.mdsal.binding.api.RpcProviderService;
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;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev240119.credentials.Credentials;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev240119.credentials.credentials.LoginPw;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev240119.credentials.credentials.LoginPwUnencrypted;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev240120.credentials.credentials.LoginPw;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.device.rev240120.credentials.credentials.LoginPwUnencrypted;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev231121.CreateDeviceInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev231121.CreateDeviceInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev231121.NetconfNode;
import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev231121.rpc.credentials.rpc.credentials.login.pw.unencrypted.LoginPasswordUnencryptedBuilder;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
import org.opendaylight.yangtools.concepts.Registration;
+import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.common.Uint16;
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NetconfTopologyRPCProviderTest {
+@ExtendWith(MockitoExtension.class)
+class NetconfTopologyRPCProviderTest {
private static final NodeId NODE_ID = new NodeId("testing-node");
private static final String TOPOLOGY_ID = "testing-topology";
private static final String TEST_PWD = "test";
private NetconfTopologyRPCProvider rpcProvider;
- @Before
- public void setUp() {
- doReturn(ENC_PWD).when(encryptionService).encrypt(TEST_PWD);
- doReturn(rpcReg).when(rpcProviderService).registerRpcImplementations(any());
+ @BeforeEach
+ void setUp() {
+ doReturn(rpcReg).when(rpcProviderService).registerRpcImplementations(any(Rpc[].class));
rpcProvider = new NetconfTopologyRPCProvider(rpcProviderService, dataBroker, encryptionService, TOPOLOGY_ID);
}
@Test
- public void testEncryptPassword() {
+ void testEncryptPassword() throws Exception {
+ doReturn(ENC_PWD.getBytes()).when(encryptionService).encrypt(TEST_PWD.getBytes());
+ final var encryptedPwNode = rpcProvider.encryptPassword(getInput(true));
+ final var loginPw = assertInstanceOf(LoginPw.class, encryptedPwNode.getCredentials());
- final NetconfNode encryptedPwNode = rpcProvider.encryptPassword(getInput(true));
-
- final Credentials credentials = encryptedPwNode.getCredentials();
- assertTrue(credentials instanceof LoginPw);
- final LoginPw loginPw = (LoginPw) credentials;
-
- assertEquals(ENC_PWD, Base64.getEncoder().encodeToString(loginPw.getLoginPassword().getPassword()));
+ assertArrayEquals(ENC_PWD.getBytes(), loginPw.getLoginPassword().getPassword());
}
@Test
- public void testNoEncryption() {
+ void testNoEncryption() {
final NetconfNode encryptedPwNode = rpcProvider.encryptPassword(getInput(false));
-
- final Credentials credentials = encryptedPwNode.getCredentials();
- assertTrue(credentials instanceof LoginPwUnencrypted);
- final LoginPwUnencrypted loginPw = (LoginPwUnencrypted) credentials;
+ final var loginPw = assertInstanceOf(LoginPwUnencrypted.class, encryptedPwNode.getCredentials());
assertEquals(TEST_PWD, loginPw.getLoginPasswordUnencrypted().getPassword());
}