Update MRI projects for Aluminium
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / util / NetconfSalKeystoreServiceTest.java
index 2b98e5050cfd7d1c14509f8b0bd2d224ebb1ae9d..99fec9d11ea79a2b325335fd3277df135d7d5ea7 100644 (file)
@@ -7,24 +7,25 @@
  */
 package org.opendaylight.netconf.sal.connect.netconf.util;
 
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
+import static org.opendaylight.mdsal.common.api.CommitInfo.emptyFluentFuture;
 
-import com.google.common.util.concurrent.Futures;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.aaa.encrypt.AAAEncryptionService;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.sal.connect.util.NetconfSalKeystoreService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.AddPrivateKeyInput;
@@ -69,7 +70,7 @@ public class NetconfSalKeystoreServiceTest {
 
     @Test
     public void testAddPrivateKey() throws Exception {
-        doReturn(Futures.<Void, TransactionCommitFailedException>immediateCheckedFuture(null)).when(writeTx).submit();
+        doReturn(emptyFluentFuture()).when(writeTx).commit();
         NetconfSalKeystoreService keystoreService = new NetconfSalKeystoreService(dataBroker, encryptionService);
 
         final AddPrivateKeyInput input = getPrivateKeyInput();
@@ -81,7 +82,7 @@ public class NetconfSalKeystoreServiceTest {
 
     @Test
     public void testAddTrustedCertificate() throws Exception {
-        doReturn(Futures.<Void, TransactionCommitFailedException>immediateCheckedFuture(null)).when(writeTx).submit();
+        doReturn(emptyFluentFuture()).when(writeTx).commit();
         NetconfSalKeystoreService keystoreService = new NetconfSalKeystoreService(dataBroker, encryptionService);
 
         final AddTrustedCertificateInput input = getTrustedCertificateInput();
@@ -92,7 +93,7 @@ public class NetconfSalKeystoreServiceTest {
     }
 
     private AddPrivateKeyInput getPrivateKeyInput() throws Exception {
-        final List<PrivateKey> privateKeys = new ArrayList<>();
+        final Map<PrivateKeyKey, PrivateKey> privateKeys = new HashMap<>();
         final Document document = readKeystoreXML();
         final NodeList nodeList = document.getElementsByTagName(XML_ELEMENT_PRIVATE_KEY);
         for (int i = 0; i < nodeList.getLength(); i++) {
@@ -113,20 +114,19 @@ public class NetconfSalKeystoreServiceTest {
                 certChain.add(certNode.getTextContent());
             }
 
-            final PrivateKey privateKey = new PrivateKeyBuilder()
-                    .setKey(new PrivateKeyKey(keyName))
-                    .setName(keyName)
-                    .setData(keyData)
-                    .setCertificateChain(certChain)
-                    .build();
-            privateKeys.add(privateKey);
+            final PrivateKeyKey key = new PrivateKeyKey(keyName);
+            privateKeys.put(key, new PrivateKeyBuilder()
+                .withKey(key)
+                .setData(keyData)
+                .setCertificateChain(certChain)
+                .build());
         }
 
         return new AddPrivateKeyInputBuilder().setPrivateKey(privateKeys).build();
     }
 
     private AddTrustedCertificateInput getTrustedCertificateInput() throws Exception {
-        final List<TrustedCertificate> trustedCertificates = new ArrayList<>();
+        final Map<TrustedCertificateKey, TrustedCertificate> trustedCertificates = new HashMap<>();
         final Document document = readKeystoreXML();
         final NodeList nodeList = document.getElementsByTagName(XML_ELEMENT_TRUSTED_CERT);
         for (int i = 0; i < nodeList.getLength(); i++) {
@@ -138,12 +138,12 @@ public class NetconfSalKeystoreServiceTest {
             final String certName = element.getElementsByTagName(XML_ELEMENT_NAME).item(0).getTextContent();
             final String certData = element.getElementsByTagName(XML_ELEMENT_CERT).item(0).getTextContent();
 
-            final TrustedCertificate certificate = new TrustedCertificateBuilder()
-                    .setKey(new TrustedCertificateKey(certName))
-                    .setName(certName)
-                    .setCertificate(certData)
-                    .build();
-            trustedCertificates.add(certificate);
+            final TrustedCertificateKey key = new TrustedCertificateKey(certName);
+            trustedCertificates.put(key, new TrustedCertificateBuilder()
+                .withKey(key)
+                .setName(certName)
+                .setCertificate(certData)
+                .build());
         }
 
         return new AddTrustedCertificateInputBuilder().setTrustedCertificate(trustedCertificates).build();