Merge "Refactor ConvertORTopoToTapiTopoTest"
[transportpce.git] / renderer / src / test / java / org / opendaylight / transportpce / renderer / utils / TransactionUtils.java
index 49ff45b2c9ae57d308e56831c5394d359bef5d5a..62385266ce483b6808f42d5cd532ae06b5b74f97 100644 (file)
@@ -11,7 +11,7 @@ package org.opendaylight.transportpce.renderer.utils;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.transportpce.common.Timeouts;
 import org.opendaylight.transportpce.common.device.DeviceTransaction;
 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
@@ -24,6 +24,11 @@ public final class TransactionUtils {
 
     }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    // deviceTx.put needs the "true" boolean parameter at the end in order to not compromise the Junit test suite
+    // FIXME check if the InstanceIdentifier raw type can be avoided
+    // Raw types use are discouraged since they lack type safety.
+    // Resulting Problems are observed at run time and not at compile time
     public static boolean writeTransaction(DeviceTransactionManager deviceTransactionManager,
                                     String nodeId,
                                     LogicalDatastoreType logicalDatastoreType,
@@ -35,9 +40,9 @@ public final class TransactionUtils {
         if (!deviceTxFuture.get().isPresent()) {
             return false;
         }
-        DeviceTransaction deviceTx = deviceTxFuture.get().get();
-        deviceTx.put(logicalDatastoreType, instanceIdentifier, object, true);
-        deviceTx.submit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT).get();
+        DeviceTransaction deviceTx = deviceTxFuture.get().orElseThrow();
+        deviceTx.merge(logicalDatastoreType, instanceIdentifier, object);
+        deviceTx.commit(Timeouts.DEVICE_WRITE_TIMEOUT, Timeouts.DEVICE_WRITE_TIMEOUT_UNIT).get();
         return true;
     }
 
@@ -48,16 +53,10 @@ public final class TransactionUtils {
             throws ExecutionException, InterruptedException {
         Future<Optional<DeviceTransaction>> deviceTxFuture =
                 deviceTransactionManager.getDeviceTransaction(nodeId);
-        if (!deviceTxFuture.get().isPresent()) {
-            return null;
-        }
-        DeviceTransaction deviceTx = deviceTxFuture.get().get();
-        com.google.common.base.Optional<? extends DataObject> readOpt
+        DeviceTransaction deviceTx = deviceTxFuture.get().orElseThrow(null);
+        Optional<? extends DataObject> readOpt
                 = deviceTx.read(logicalDatastoreType, instanceIdentifier).get();
-        if (!readOpt.isPresent()) {
-            return null;
-        }
-        return readOpt.get();
+        return readOpt.orElseThrow(null);
     }
 
 }