Split out AAAEncryptionServiceConfigurator
[aaa.git] / aaa-encrypt-service / impl / src / test / java / org / opendaylight / aaa / encrypt / impl / AAAEncryptServiceImplTest.java
index fd558b8413719973018a5c4c936851bfebce8914..f04fb96cc61b2a3354c3f1d19ca2fd7e121521d7 100644 (file)
@@ -7,19 +7,17 @@
  */
 package org.opendaylight.aaa.encrypt.impl;
 
-import static org.mockito.ArgumentMatchers.any;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 
-import java.util.Optional;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.mdsal.binding.api.DataBroker;
-import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.binding.api.ReadWriteTransaction;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.config.aaa.authn.encrypt.service.config.rev160915.AaaEncryptServiceConfig;
 import org.opendaylight.yang.gen.v1.config.aaa.authn.encrypt.service.config.rev160915.AaaEncryptServiceConfigBuilder;
@@ -32,41 +30,42 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 @Deprecated
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class AAAEncryptServiceImplTest {
-
-    private AAAEncryptionServiceImpl impl;
     @Mock
     private DataBroker dataBroker;
+    @Mock
+    private ReadWriteTransaction tx;
+
+    private AAAEncryptionServiceImpl impl;
 
     @Before
     public void setup() {
-        AaaEncryptServiceConfig module = new AaaEncryptServiceConfigBuilder()
+        final var module = new AaaEncryptServiceConfigBuilder()
                 .setCipherTransforms("AES/CBC/PKCS5Padding").setEncryptIterationCount(32768).setEncryptKey("")
                 .setEncryptKeyLength(128).setEncryptMethod("PBKDF2WithHmacSHA1").setEncryptSalt("")
                 .setEncryptType("AES").setPasswordLength(12).build();
 
-        final ReadTransaction rtx = mock(ReadTransaction.class);
-        doReturn(rtx).when(dataBroker).newReadOnlyTransaction();
-        doReturn(FluentFutures.immediateFluentFuture(Optional.of(module))).when(rtx).read(
-            any(LogicalDatastoreType.class), any(InstanceIdentifier.class));
+        doReturn(tx).when(dataBroker).newReadWriteTransaction();
+        doReturn(FluentFutures.immediateTrueFluentFuture()).when(tx)
+            .exists(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(AaaEncryptServiceConfig.class));
 
-        impl = new AAAEncryptionServiceImpl(module, dataBroker);
+        impl = new AAAEncryptionServiceImpl(new AAAEncryptionServiceConfigurator(dataBroker, module));
     }
 
     @Test
     public void testShortString() {
         String before = "shortone";
         String encrypt = impl.encrypt(before);
-        Assert.assertNotEquals(before, encrypt);
+        assertNotEquals(before, encrypt);
         String after = impl.decrypt(encrypt);
-        Assert.assertEquals(before, after);
+        assertEquals(before, after);
     }
 
     @Test
     public void testLongString() {
         String before = "This is a very long string to encrypt for testing 1...2...3";
         String encrypt = impl.encrypt(before);
-        Assert.assertNotEquals(before, encrypt);
+        assertNotEquals(before, encrypt);
         String after = impl.decrypt(encrypt);
-        Assert.assertEquals(before, after);
+        assertEquals(before, after);
     }
 }