Remove static TransactionChainHandler instance 09/71109/4
authorTom Pantelis <tompantelis@gmail.com>
Thu, 19 Apr 2018 14:17:47 +0000 (10:17 -0400)
committerTom Pantelis <tompantelis@gmail.com>
Fri, 20 Apr 2018 00:54:03 +0000 (20:54 -0400)
RestConnectorProvider maintained a static instance in order
to reset the DOMTransactionChain statically. The reset logic
was moved to TransactionChainHandler and call sites in the
static Utils were modified to pass the TransactionChainHandler via
the TransactionVarsWrapper and call reset. This allows the static
instance to be removed. The TransactionChainHandler singleton is now
created via blueprint.

Change-Id: I483ac83103286146bc636b7f1e6ba0df70f2f5a6
Signed-off-by: Tom Pantelis <tompantelis@gmail.com>
20 files changed:
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandler.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/TransactionVarsWrapper.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/TransactionUtil.java
restconf/restconf-nb-rfc8040/src/main/resources/org/opendaylight/blueprint/restconf-bp.xml
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProviderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040ImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/DeleteDataTransactionUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PatchDataTransactionUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PostDataTransactionUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/PutDataTransactionUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/utils/ReadDataTransactionUtilTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java

index 7e251ef4e57d1cd54675d26362b292c176353bf0..4cf3aa1636e4b2e0bddf49608a20ee53df7660a2 100644 (file)
@@ -9,19 +9,12 @@
 package org.opendaylight.restconf.nb.rfc8040;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import java.util.Set;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
@@ -42,25 +35,6 @@ public class RestConnectorProvider<T extends ServiceWrapper> implements Restconf
 
     private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
 
-    public static final TransactionChainListener TRANSACTION_CHAIN_LISTENER = new TransactionChainListener() {
-        @Override
-        public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
-                final AsyncTransaction<?, ?> transaction, final Throwable cause) {
-            LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
-            resetTransactionChainForAdapaters(chain);
-            throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
-        }
-
-        @Override
-        public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
-            LOG.trace("TransactionChain({}) {} SUCCESSFUL", chain);
-        }
-    };
-
-    @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
-    private static volatile TransactionChainHandler transactionChainHandler;
-    @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
-    private static volatile DOMDataBroker dataBroker;
     @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
     private static volatile DOMMountPointServiceHandler mountPointServiceHandler;
 
@@ -68,58 +42,42 @@ public class RestConnectorProvider<T extends ServiceWrapper> implements Restconf
     private final DOMNotificationService notificationService;
     private final DOMMountPointService mountPointService;
     private final DOMSchemaService domSchemaService;
-    private final Builder<Object> servicesProperties;
+    private final TransactionChainHandler transactionChainHandler;
+    private final DOMDataBroker dataBroker;
 
     private ListenerRegistration<SchemaContextListener> listenerRegistration;
     private SchemaContextHandler schemaCtxHandler;
-    private T wrapperServices;
-
-    // FIXME: refactor this class and its users to interact via builder pattern, where individual
-    // services are injected and then the provider is created
-    public RestConnectorProvider(final DOMDataBroker domDataBroker,
-            final DOMSchemaService domSchemaService, final DOMRpcService rpcService,
-            final DOMNotificationService notificationService, final DOMMountPointService mountPointService) {
-        this(domDataBroker, domSchemaService, rpcService, notificationService, mountPointService, null);
-    }
+    private final T wrapperServices;
 
     public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
             final DOMRpcService rpcService, final DOMNotificationService notificationService,
-            final DOMMountPointService mountPointService, final T wrapperServices) {
-        this.servicesProperties = ImmutableSet.<Object>builder();
+            final DOMMountPointService mountPointService, final TransactionChainHandler transactionChainHandler,
+            final T wrapperServices) {
         this.wrapperServices = wrapperServices;
         this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
         this.rpcService = Preconditions.checkNotNull(rpcService);
         this.notificationService = Preconditions.checkNotNull(notificationService);
         this.mountPointService = Preconditions.checkNotNull(mountPointService);
-
-        RestConnectorProvider.dataBroker = Preconditions.checkNotNull(domDataBroker);
+        this.transactionChainHandler = Preconditions.checkNotNull(transactionChainHandler);
+        this.dataBroker = Preconditions.checkNotNull(domDataBroker);
     }
 
     public synchronized void start() {
         mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
-        servicesProperties.add(mountPointServiceHandler);
 
         final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
-        servicesProperties.add(brokerHandler);
-
-        RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(dataBroker
-                .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER));
-        servicesProperties.add(transactionChainHandler);
 
         this.schemaCtxHandler = new SchemaContextHandler(transactionChainHandler);
-        servicesProperties.add(schemaCtxHandler);
         this.listenerRegistration = domSchemaService.registerSchemaContextListener(this.schemaCtxHandler);
 
         final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
-        servicesProperties.add(rpcServiceHandler);
 
         final NotificationServiceHandler notificationServiceHandler =
                 new NotificationServiceHandler(notificationService);
-        servicesProperties.add(notificationServiceHandler);
 
         if (wrapperServices != null) {
             wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
-                    RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler,
+                    transactionChainHandler, brokerHandler, rpcServiceHandler,
                     notificationServiceHandler, domSchemaService);
         }
     }
@@ -128,21 +86,6 @@ public class RestConnectorProvider<T extends ServiceWrapper> implements Restconf
         return mountPointServiceHandler;
     }
 
-    /**
-     * After {@link TransactionChain} failed, this updates {@link TransactionChainHandler} with new transaction chain.
-     *
-     * @param chain
-     *             old {@link TransactionChain}
-     */
-    public static void resetTransactionChainForAdapaters(final TransactionChain<?, ?> chain) {
-        LOG.trace("Resetting TransactionChain({})", chain);
-        chain.close();
-        RestConnectorProvider.transactionChainHandler.update(
-                Preconditions.checkNotNull(dataBroker).createTransactionChain(
-                        RestConnectorProvider.TRANSACTION_CHAIN_LISTENER)
-        );
-    }
-
     /**
      * Get current {@link DOMMountPointService} from {@link DOMMountPointServiceHandler}.
      * @return {@link DOMMountPointService}
@@ -158,17 +101,6 @@ public class RestConnectorProvider<T extends ServiceWrapper> implements Restconf
             this.listenerRegistration.close();
         }
 
-        // close transaction chain
-        if (transactionChainHandler != null && transactionChainHandler.get() != null) {
-            transactionChainHandler.get().close();
-        }
-
-        transactionChainHandler = null;
         mountPointServiceHandler = null;
-        dataBroker = null;
-    }
-
-    public final synchronized Set<Object> getServicesProperties() {
-        return servicesProperties.build();
     }
 }
index 51b7790fd34913a586e8a4a4adfa54e2466ee927..65534bf16fad720bf29b703cde7b70a3edaeabe2 100644 (file)
@@ -15,7 +15,6 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.MonitoringModule;
 import org.opendaylight.restconf.nb.rfc8040.utils.mapping.RestconfMappingNodeUtil;
@@ -108,7 +107,7 @@ public class SchemaContextHandler implements SchemaContextListenerHandler {
               https://bugs.opendaylight.org/show_bug.cgi?id=7728
             */
             LOG.warn("Ignoring that another cluster node is already putting the same data to DS.", e);
-            RestConnectorProvider.resetTransactionChainForAdapaters(this.transactionChainHandler.get());
+            this.transactionChainHandler.reset();
         }
     }
 }
index 573dc36e0144d2cf8bc2dbb80e89b5372934cea8..81cdb08d96bb29c45271f5d7f7dfb1796e95b958 100644 (file)
@@ -8,37 +8,65 @@
 
 package org.opendaylight.restconf.nb.rfc8040.handlers;
 
-import com.google.common.base.Preconditions;
+import java.util.Objects;
+import javax.annotation.Nullable;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChain;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
  * Implementation of {@link TransactionChainHandler}.
  *
  */
-public class TransactionChainHandler implements Handler<DOMTransactionChain> {
+public class TransactionChainHandler implements Handler<DOMTransactionChain>, AutoCloseable {
+    private static final Logger LOG = LoggerFactory.getLogger(TransactionChainHandler.class);
 
-    private DOMTransactionChain transactionChain;
+    private final TransactionChainListener transactionChainListener = new TransactionChainListener() {
+        @Override
+        public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+                final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+            LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
+            reset();
+            throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
+        }
+
+        @Override
+        public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
+            LOG.trace("TransactionChain({}) {} SUCCESSFUL", chain);
+        }
+    };
+
+    @Nullable
+    private final DOMDataBroker dataBroker;
+    private volatile DOMTransactionChain transactionChain;
 
     /**
      * Prepare transaction chain service for Restconf services.
-     *
-     * @param transactionChain Transaction chain
      */
-    public TransactionChainHandler(final DOMTransactionChain transactionChain) {
-        Preconditions.checkNotNull(transactionChain);
-        this.transactionChain = transactionChain;
+    public TransactionChainHandler(final DOMDataBroker dataBroker) {
+        this.dataBroker = Objects.requireNonNull(dataBroker);
+        transactionChain = Objects.requireNonNull(dataBroker.createTransactionChain(transactionChainListener));
     }
 
     @Override
-    @SuppressWarnings("checkstyle:hiddenField")
-    public void update(final DOMTransactionChain transactionChain) {
-        Preconditions.checkNotNull(transactionChain);
-        this.transactionChain = transactionChain;
+    public DOMTransactionChain get() {
+        return this.transactionChain;
+    }
+
+    public synchronized void reset() {
+        LOG.trace("Resetting TransactionChain({})", transactionChain);
+        transactionChain.close();
+        transactionChain = dataBroker.createTransactionChain(transactionChainListener);
     }
 
     @Override
-    public DOMTransactionChain get() {
-        return this.transactionChain;
+    public synchronized void close() {
+        transactionChain.close();
     }
 }
index 08f129478a3e7e45117da886e4ff6150b897997c..de9291627516999edd92e3229f25eb3bc7ccb505 100644 (file)
@@ -19,13 +19,13 @@ import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
 import java.util.Map.Entry;
+import java.util.Objects;
 import javax.annotation.Nonnull;
 import javax.ws.rs.Path;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.context.WriterParameters;
@@ -33,7 +33,6 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
@@ -75,10 +74,10 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                                    final TransactionChainHandler transactionChainHandler,
             final DOMMountPointServiceHandler mountPointServiceHandler,
             final RestconfStreamsSubscriptionService delegRestconfSubscrService) {
-        this.schemaContextHandler = schemaContextHandler;
-        this.transactionChainHandler = transactionChainHandler;
-        this.mountPointServiceHandler = mountPointServiceHandler;
-        this.delegRestconfSubscrService = delegRestconfSubscrService;
+        this.schemaContextHandler = Objects.requireNonNull(schemaContextHandler);
+        this.transactionChainHandler = Objects.requireNonNull(transactionChainHandler);
+        this.mountPointServiceHandler = Objects.requireNonNull(mountPointServiceHandler);
+        this.delegRestconfSubscrService = Objects.requireNonNull(delegRestconfSubscrService);
     }
 
     @Override
@@ -138,15 +137,15 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                 instanceIdentifier, uriInfo, tagged);
 
         final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
-        final DOMTransactionChain transactionChain;
+        final TransactionChainHandler localTransactionChainHandler;
         if (mountPoint == null) {
-            transactionChain = this.transactionChainHandler.get();
+            localTransactionChainHandler = this.transactionChainHandler;
         } else {
-            transactionChain = transactionChainOfMountPoint(mountPoint);
+            localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
         }
 
         final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
-                instanceIdentifier, mountPoint, transactionChain);
+                instanceIdentifier, mountPoint, localTransactionChainHandler);
         final NormalizedNode<?, ?> node =
                 ReadDataTransactionUtil.readData(identifier, parameters.getContent(), transactionNode, withDefa,
                         schemaContextRef, uriInfo);
@@ -221,18 +220,18 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         PutDataTransactionUtil.validateListKeysEqualityInPayloadAndUri(payload);
 
         final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
-        final DOMTransactionChain transactionChain;
+        final TransactionChainHandler localTransactionChainHandler;
         final SchemaContextRef ref;
         if (mountPoint == null) {
-            transactionChain = this.transactionChainHandler.get();
+            localTransactionChainHandler = this.transactionChainHandler;
             ref = new SchemaContextRef(this.schemaContextHandler.get());
         } else {
-            transactionChain = transactionChainOfMountPoint(mountPoint);
+            localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
             ref = new SchemaContextRef(mountPoint.getSchemaContext());
         }
 
         final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
-                payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
+                payload.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
         return PutDataTransactionUtil.putData(payload, ref, transactionNode, insert, point);
     }
 
@@ -286,17 +285,17 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         checkQueryParams(insertUsed, pointUsed, insert);
 
         final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
-        final DOMTransactionChain transactionChain;
+        final TransactionChainHandler localTransactionChainHandler;
         final SchemaContextRef ref;
         if (mountPoint == null) {
-            transactionChain = this.transactionChainHandler.get();
+            localTransactionChainHandler = this.transactionChainHandler;
             ref = new SchemaContextRef(this.schemaContextHandler.get());
         } else {
-            transactionChain = transactionChainOfMountPoint(mountPoint);
+            localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
             ref = new SchemaContextRef(mountPoint.getSchemaContext());
         }
         final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
-                payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
+                payload.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
         return PostDataTransactionUtil.postData(uriInfo, payload, transactionNode, ref, insert, point);
     }
 
@@ -307,15 +306,15 @@ public class RestconfDataServiceImpl implements RestconfDataService {
                 identifier, schemaContextRef.get(), Optional.of(this.mountPointServiceHandler.get()));
 
         final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
-        final DOMTransactionChain transactionChain;
+        final TransactionChainHandler localTransactionChainHandler;
         if (mountPoint == null) {
-            transactionChain = this.transactionChainHandler.get();
+            localTransactionChainHandler = this.transactionChainHandler;
         } else {
-            transactionChain = transactionChainOfMountPoint(mountPoint);
+            localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
         }
 
         final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(instanceIdentifier, mountPoint,
-                transactionChain);
+                localTransactionChainHandler);
         return DeleteDataTransactionUtil.deleteData(transactionNode);
     }
 
@@ -329,18 +328,18 @@ public class RestconfDataServiceImpl implements RestconfDataService {
         Preconditions.checkNotNull(context);
         final DOMMountPoint mountPoint = context.getInstanceIdentifierContext().getMountPoint();
 
-        final DOMTransactionChain transactionChain;
+        final TransactionChainHandler localTransactionChainHandler;
         final SchemaContextRef ref;
         if (mountPoint == null) {
-            transactionChain = this.transactionChainHandler.get();
+            localTransactionChainHandler = this.transactionChainHandler;
             ref = new SchemaContextRef(this.schemaContextHandler.get());
         } else {
-            transactionChain = transactionChainOfMountPoint(mountPoint);
+            localTransactionChainHandler = transactionChainOfMountPoint(mountPoint);
             ref = new SchemaContextRef(mountPoint.getSchemaContext());
         }
 
         final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
-                context.getInstanceIdentifierContext(), mountPoint, transactionChain);
+                context.getInstanceIdentifierContext(), mountPoint, localTransactionChainHandler);
 
         return PatchDataTransactionUtil.patchData(context, transactionNode, ref);
     }
@@ -349,12 +348,12 @@ public class RestconfDataServiceImpl implements RestconfDataService {
      * Prepare transaction chain to access data of mount point.
      * @param mountPoint
      *            mount point reference
-     * @return {@link DOMTransactionChain}
+     * @return {@link TransactionChainHandler}
      */
-    private static DOMTransactionChain transactionChainOfMountPoint(@Nonnull final DOMMountPoint mountPoint) {
+    private static TransactionChainHandler transactionChainOfMountPoint(@Nonnull final DOMMountPoint mountPoint) {
         final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
         if (domDataBrokerService.isPresent()) {
-            return domDataBrokerService.get().createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
+            return new TransactionChainHandler(domDataBrokerService.get());
         }
 
         final String errMsg = "DOM data broker service isn't available for mount point " + mountPoint.getIdentifier();
index b678623fdd3ab7037cf3cceb69460ea375199b8a..b60d86e0663f7eed0bf201163ea85267c786d725 100644 (file)
@@ -11,6 +11,7 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 
 /**
  * This class represent delegation wrapper for transaction variables.
@@ -22,6 +23,7 @@ public final class TransactionVarsWrapper {
     private final DOMMountPoint mountPoint;
     private LogicalDatastoreType configuration = null;
     private final DOMTransactionChain transactionChain;
+    private final TransactionChainHandler transactionChainHandler;
 
     /**
      * Set base type of variables, which ones we need for transaction.
@@ -32,15 +34,16 @@ public final class TransactionVarsWrapper {
      *             {@link InstanceIdentifierContext} of data for transaction
      * @param mountPoint
      *             mount point if is present
-     * @param transactionChain
-     *             transaction chain for creating specific type of transaction
-     *            in specific operation
+     * @param transactionChainHandler
+     *             used to obtain the transaction chain for creating specific type of transaction
+     *             in specific operation
      */
     public TransactionVarsWrapper(final InstanceIdentifierContext<?> instanceIdentifier, final DOMMountPoint mountPoint,
-            final DOMTransactionChain transactionChain) {
+            final TransactionChainHandler transactionChainHandler) {
         this.instanceIdentifier = instanceIdentifier;
         this.mountPoint = mountPoint;
-        this.transactionChain = transactionChain;
+        this.transactionChainHandler = transactionChainHandler;
+        transactionChain = transactionChainHandler.get();
     }
 
     /**
@@ -90,4 +93,8 @@ public final class TransactionVarsWrapper {
     public DOMTransactionChain getTransactionChain() {
         return this.transactionChain;
     }
+
+    public TransactionChainHandler getTransactionChainHandler() {
+        return transactionChainHandler;
+    }
 }
index dd293479a95fb2a3005e9a0d813b3841033176fe..25d8de9902121112c58281fe0be19f560c1b96b5 100644 (file)
@@ -13,7 +13,7 @@ import javax.ws.rs.core.Response.Status;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
@@ -36,7 +36,7 @@ public final class DeleteDataTransactionUtil {
      */
     public static Response deleteData(final TransactionVarsWrapper transactionNode) {
         final CheckedFuture<Void, TransactionCommitFailedException> future = submitData(
-                transactionNode.getTransactionChain(), transactionNode.getTransactionChain().newReadWriteTransaction(),
+                transactionNode.getTransactionChainHandler(),
                 transactionNode.getInstanceIdentifier().getInstanceIdentifier());
         final ResponseFactory response = new ResponseFactory(Status.NO_CONTENT);
         FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE, response);
@@ -46,8 +46,8 @@ public final class DeleteDataTransactionUtil {
     /**
      * Delete data via transaction. Return error if data to delete does not exist.
      *
-     * @param transactionChain
-     *             transaction chain
+     * @param transactionChainHandler
+     *             transaction chain handler
      * @param readWriteTx
      *             read and write transaction
      * @param path
@@ -55,9 +55,9 @@ public final class DeleteDataTransactionUtil {
      * @return {@link CheckedFuture}
      */
     private static CheckedFuture<Void, TransactionCommitFailedException> submitData(
-            final DOMTransactionChain transactionChain, final DOMDataReadWriteTransaction readWriteTx,
-            final YangInstanceIdentifier path) {
-        TransactionUtil.checkItemExists(transactionChain, readWriteTx, LogicalDatastoreType.CONFIGURATION, path,
+            final TransactionChainHandler transactionChainHandler, final YangInstanceIdentifier path) {
+        final DOMDataReadWriteTransaction readWriteTx = transactionChainHandler.get().newReadWriteTransaction();
+        TransactionUtil.checkItemExists(transactionChainHandler, readWriteTx, LogicalDatastoreType.CONFIGURATION, path,
                 RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE);
         readWriteTx.delete(LogicalDatastoreType.CONFIGURATION, path);
         return readWriteTx.submit();
index fe0f3904c2708b751f5a1bd80be846c639a5a4ca..7781c71140c2dc9ab11d0f8a87d764dd87643382 100644 (file)
@@ -27,7 +27,6 @@ import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant.PatchData;
@@ -146,7 +145,7 @@ public final class PatchDataTransactionUtil {
             return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), true, null);
         } else {
             tx.cancel();
-            RestConnectorProvider.resetTransactionChainForAdapaters(transactionNode.getTransactionChain());
+            transactionNode.getTransactionChainHandler().reset();
             return new PatchStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection),
                     false, null);
         }
index 9c7014ff471dea2aca377169bd10326cedc34d6e..b2201bdad280886fb5854ef718666213c7074e2d 100644 (file)
@@ -21,6 +21,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
@@ -102,104 +103,111 @@ public final class PostDataTransactionUtil {
         final DOMTransactionChain domTransactionChain = transactionNode.getTransactionChain();
         final DOMDataReadWriteTransaction newReadWriteTransaction = domTransactionChain.newReadWriteTransaction();
         if (insert == null) {
-            makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+            makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(), newReadWriteTransaction);
             return newReadWriteTransaction.submit();
         } else {
             final DataSchemaNode schemaNode = PutDataTransactionUtil.checkListAndOrderedType(schemaContext, path);
             switch (insert) {
                 case "first":
                     if (schemaNode instanceof ListSchemaNode) {
-                        final NormalizedNode<?, ?> readData =
-                                PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
-                                        schemaNode);
+                        final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+                            schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
                         final OrderedMapNode readList = (OrderedMapNode) readData;
                         if (readList == null || readList.getValue().isEmpty()) {
-                            makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+                            makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+                                    newReadWriteTransaction);
                             return newReadWriteTransaction.submit();
                         } else {
                             newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
                                     path.getParent().getParent());
                             simplePost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
-                                    schemaContext, domTransactionChain);
-                            makePost(path, readData, schemaContext, domTransactionChain,
+                                    schemaContext, transactionNode.getTransactionChainHandler());
+                            makePost(path, readData, schemaContext, transactionNode.getTransactionChainHandler(),
                                     newReadWriteTransaction);
                             return newReadWriteTransaction.submit();
                         }
                     } else {
-                        final NormalizedNode<?, ?> readData = PutDataTransactionUtil
-                                        .readList(path.getParent(), schemaContext, domTransactionChain, schemaNode);
+                        final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+                            schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
 
                         final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
                         if (readLeafList == null || readLeafList.getValue().isEmpty()) {
-                            makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+                            makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+                                    newReadWriteTransaction);
                             return newReadWriteTransaction.submit();
                         } else {
                             newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
                                     path.getParent().getParent());
                             simplePost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
-                                    schemaContext, domTransactionChain);
-                            makePost(path, readData, schemaContext, domTransactionChain, newReadWriteTransaction);
+                                    schemaContext, transactionNode.getTransactionChainHandler());
+                            makePost(path, readData, schemaContext, transactionNode.getTransactionChainHandler(),
+                                    newReadWriteTransaction);
                             return newReadWriteTransaction.submit();
                         }
                     }
                 case "last":
-                    makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+                    makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+                            newReadWriteTransaction);
                     return newReadWriteTransaction.submit();
                 case "before":
                     if (schemaNode instanceof ListSchemaNode) {
-                        final NormalizedNode<?, ?> readData =
-                                PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
-                                        schemaNode);
+                        final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+                            schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
                         final OrderedMapNode readList = (OrderedMapNode) readData;
                         if (readList == null || readList.getValue().isEmpty()) {
-                            makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+                            makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+                                    newReadWriteTransaction);
                             return newReadWriteTransaction.submit();
                         } else {
                             insertWithPointListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path,
-                                    data, schemaContext, point, readList, true, domTransactionChain);
+                                    data, schemaContext, point, readList, true,
+                                    transactionNode.getTransactionChainHandler());
                             return newReadWriteTransaction.submit();
                         }
                     } else {
-                        final NormalizedNode<?, ?> readData =
-                                PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
-                                        schemaNode);
+                        final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+                            schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
 
                         final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
                         if (readLeafList == null || readLeafList.getValue().isEmpty()) {
-                            makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+                            makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+                                    newReadWriteTransaction);
                             return newReadWriteTransaction.submit();
                         } else {
                             insertWithPointLeafListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION,
-                                    path, data, schemaContext, point, readLeafList, true, domTransactionChain);
+                                    path, data, schemaContext, point, readLeafList, true,
+                                    transactionNode.getTransactionChainHandler());
                             return newReadWriteTransaction.submit();
                         }
                     }
                 case "after":
                     if (schemaNode instanceof ListSchemaNode) {
-                        final NormalizedNode<?, ?> readData =
-                                PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
-                                        schemaNode);
+                        final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+                            schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
                         final OrderedMapNode readList = (OrderedMapNode) readData;
                         if (readList == null || readList.getValue().isEmpty()) {
-                            makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+                            makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+                                    newReadWriteTransaction);
                             return newReadWriteTransaction.submit();
                         } else {
                             insertWithPointListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path,
-                                    data, schemaContext, point, readList, false, domTransactionChain);
+                                    data, schemaContext, point, readList, false,
+                                    transactionNode.getTransactionChainHandler());
                             return newReadWriteTransaction.submit();
                         }
                     } else {
-                        final NormalizedNode<?, ?> readData =
-                                PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
-                                        schemaNode);
+                        final NormalizedNode<?, ?> readData = PutDataTransactionUtil.readList(path.getParent(),
+                            schemaContext, transactionNode.getTransactionChainHandler(), schemaNode);
 
                         final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
                         if (readLeafList == null || readLeafList.getValue().isEmpty()) {
-                            makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+                            makePost(path, data, schemaContext, transactionNode.getTransactionChainHandler(),
+                                    newReadWriteTransaction);
                             return newReadWriteTransaction.submit();
                         } else {
                             insertWithPointLeafListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION,
-                                    path, data, schemaContext, point, readLeafList, true, domTransactionChain);
+                                    path, data, schemaContext, point, readLeafList, true,
+                                    transactionNode.getTransactionChainHandler());
                             return newReadWriteTransaction.submit();
                         }
                     }
@@ -214,7 +222,7 @@ public final class PostDataTransactionUtil {
     private static void insertWithPointLeafListPost(final DOMDataReadWriteTransaction rwTransaction,
             final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
             final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
-            final boolean before, final DOMTransactionChain domTransactionChain) {
+            final boolean before, final TransactionChainHandler transactionChainHandler) {
         rwTransaction.delete(datastore, path.getParent().getParent());
         final InstanceIdentifierContext<?> instanceIdentifier =
                 ParserIdentifier.toInstanceIdentifier(point, schemaContext, Optional.absent());
@@ -234,12 +242,12 @@ public final class PostDataTransactionUtil {
         rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
         for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
             if (lastInsertedPosition == lastItemPosition) {
-                TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, path,
+                TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, path,
                         RestconfDataServiceConstant.PostData.POST_TX_TYPE);
                 rwTransaction.put(datastore, path, payload);
             }
             final YangInstanceIdentifier childPath = path.getParent().getParent().node(nodeChild.getIdentifier());
-            TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, childPath,
+            TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, childPath,
                     RestconfDataServiceConstant.PostData.POST_TX_TYPE);
             rwTransaction.put(datastore, childPath, nodeChild);
             lastInsertedPosition++;
@@ -249,7 +257,7 @@ public final class PostDataTransactionUtil {
     private static void insertWithPointListPost(final DOMDataReadWriteTransaction rwTransaction,
             final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
             final SchemaContext schemaContext, final String point, final MapNode readList, final boolean before,
-            final DOMTransactionChain domTransactionChain) {
+            final TransactionChainHandler transactionChainHandler) {
         rwTransaction.delete(datastore, path.getParent().getParent());
         final InstanceIdentifierContext<?> instanceIdentifier =
                 ParserIdentifier.toInstanceIdentifier(point, schemaContext, Optional.absent());
@@ -269,12 +277,12 @@ public final class PostDataTransactionUtil {
         rwTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
         for (final MapEntryNode mapEntryNode : readList.getValue()) {
             if (lastInsertedPosition == lastItemPosition) {
-                TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, path,
+                TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, path,
                         RestconfDataServiceConstant.PostData.POST_TX_TYPE);
                 rwTransaction.put(datastore, path, payload);
             }
             final YangInstanceIdentifier childPath = path.getParent().getParent().node(mapEntryNode.getIdentifier());
-            TransactionUtil.checkItemDoesNotExists(domTransactionChain, rwTransaction, datastore, childPath,
+            TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, childPath,
                     RestconfDataServiceConstant.PostData.POST_TX_TYPE);
             rwTransaction.put(datastore, childPath, mapEntryNode);
             lastInsertedPosition++;
@@ -282,14 +290,14 @@ public final class PostDataTransactionUtil {
     }
 
     private static void makePost(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
-            final SchemaContext schemaContext, final DOMTransactionChain transactionChain,
+            final SchemaContext schemaContext, final TransactionChainHandler transactionChainHandler,
             final DOMDataReadWriteTransaction transaction) {
         if (data instanceof MapNode) {
             boolean merge = false;
             for (final MapEntryNode child : ((MapNode) data).getValue()) {
                 final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
                 TransactionUtil.checkItemDoesNotExists(
-                        transactionChain, transaction, LogicalDatastoreType.CONFIGURATION, childPath,
+                        transactionChainHandler, transaction, LogicalDatastoreType.CONFIGURATION, childPath,
                         RestconfDataServiceConstant.PostData.POST_TX_TYPE);
                 if (!merge) {
                     merge = true;
@@ -302,7 +310,7 @@ public final class PostDataTransactionUtil {
             }
         } else {
             TransactionUtil.checkItemDoesNotExists(
-                    transactionChain, transaction, LogicalDatastoreType.CONFIGURATION, path,
+                    transactionChainHandler, transaction, LogicalDatastoreType.CONFIGURATION, path,
                     RestconfDataServiceConstant.PostData.POST_TX_TYPE);
 
             TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
@@ -338,8 +346,8 @@ public final class PostDataTransactionUtil {
 
     private static void simplePost(final DOMDataReadWriteTransaction rwTransaction,
             final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
-            final SchemaContext schemaContext, final DOMTransactionChain transactionChain) {
-        TransactionUtil.checkItemDoesNotExists(transactionChain, rwTransaction, datastore, path,
+            final SchemaContext schemaContext, final TransactionChainHandler transactionChainHandler) {
+        TransactionUtil.checkItemDoesNotExists(transactionChainHandler, rwTransaction, datastore, path,
                 RestconfDataServiceConstant.PostData.POST_TX_TYPE);
         TransactionUtil.ensureParentsByMerge(path, schemaContext, rwTransaction);
         rwTransaction.put(datastore, path, payload);
index 9e3130cb67118671e97adbb05bbf935517bd1e13..a237f037cf0afddab2ff7d2aa2bc43a5a3d0b065 100644 (file)
@@ -19,13 +19,13 @@ import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.common.validation.RestconfValidationUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
@@ -173,7 +173,7 @@ public final class PutDataTransactionUtil {
         final ResponseFactory responseFactory =
                 new ResponseFactory(existsResponse.result ? Status.NO_CONTENT : Status.CREATED);
         final CheckedFuture<Void, TransactionCommitFailedException> submitData = submitData(path, schemaContext,
-                transactionNode.getTransactionChain(), readWriteTransaction, payload.getData(), insert, point);
+                transactionNode.getTransactionChainHandler(), readWriteTransaction, payload.getData(), insert, point);
         FutureCallbackTx.addCallback(submitData, RestconfDataServiceConstant.PutData.PUT_TX_TYPE, responseFactory);
         return responseFactory.build();
     }
@@ -185,7 +185,7 @@ public final class PutDataTransactionUtil {
      *             path of data
      * @param schemaContext
      *             {@link SchemaContext}
-     * @param domTransactionChain
+     * @param transactionChainHandler
      *             write transaction
      * @param data
      *             data
@@ -196,7 +196,7 @@ public final class PutDataTransactionUtil {
      * @return {@link CheckedFuture}
      */
     private static CheckedFuture<Void, TransactionCommitFailedException> submitData(final YangInstanceIdentifier path,
-            final SchemaContext schemaContext, final DOMTransactionChain domTransactionChain,
+            final SchemaContext schemaContext, final TransactionChainHandler transactionChainHandler,
             final DOMDataReadWriteTransaction readWriteTransaction,
             final NormalizedNode<?, ?> data, final String insert, final String point) {
         if (insert == null) {
@@ -207,7 +207,7 @@ public final class PutDataTransactionUtil {
                 case "first":
                     if (schemaNode instanceof ListSchemaNode) {
                         final NormalizedNode<?, ?> readData =
-                                readList(path, schemaContext, domTransactionChain, schemaNode);
+                                readList(path, schemaContext, transactionChainHandler, schemaNode);
                         final OrderedMapNode readList = (OrderedMapNode) readData;
                         if (readList == null || readList.getValue().isEmpty()) {
                             return makePut(path, schemaContext, readWriteTransaction, data);
@@ -221,7 +221,7 @@ public final class PutDataTransactionUtil {
                         }
                     } else {
                         final NormalizedNode<?, ?> readData =
-                                readList(path, schemaContext, domTransactionChain, schemaNode);
+                                readList(path, schemaContext, transactionChainHandler, schemaNode);
 
                         final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
                         if (readLeafList == null || readLeafList.getValue().isEmpty()) {
@@ -240,7 +240,7 @@ public final class PutDataTransactionUtil {
                 case "before":
                     if (schemaNode instanceof ListSchemaNode) {
                         final NormalizedNode<?, ?> readData =
-                                readList(path, schemaContext, domTransactionChain, schemaNode);
+                                readList(path, schemaContext, transactionChainHandler, schemaNode);
                         final OrderedMapNode readList = (OrderedMapNode) readData;
                         if (readList == null || readList.getValue().isEmpty()) {
                             return makePut(path, schemaContext, readWriteTransaction, data);
@@ -251,7 +251,7 @@ public final class PutDataTransactionUtil {
                         }
                     } else {
                         final NormalizedNode<?, ?> readData =
-                                readList(path, schemaContext, domTransactionChain, schemaNode);
+                                readList(path, schemaContext, transactionChainHandler, schemaNode);
 
                         final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
                         if (readLeafList == null || readLeafList.getValue().isEmpty()) {
@@ -265,7 +265,7 @@ public final class PutDataTransactionUtil {
                 case "after":
                     if (schemaNode instanceof ListSchemaNode) {
                         final NormalizedNode<?, ?> readData =
-                                readList(path, schemaContext, domTransactionChain, schemaNode);
+                                readList(path, schemaContext, transactionChainHandler, schemaNode);
                         final OrderedMapNode readList = (OrderedMapNode) readData;
                         if (readList == null || readList.getValue().isEmpty()) {
                             return makePut(path, schemaContext, readWriteTransaction, data);
@@ -276,7 +276,7 @@ public final class PutDataTransactionUtil {
                         }
                     } else {
                         final NormalizedNode<?, ?> readData =
-                                readList(path, schemaContext, domTransactionChain, schemaNode);
+                                readList(path, schemaContext, transactionChainHandler, schemaNode);
 
                         final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
                         if (readLeafList == null || readLeafList.getValue().isEmpty()) {
@@ -296,11 +296,10 @@ public final class PutDataTransactionUtil {
     }
 
     public static NormalizedNode<?, ?> readList(final YangInstanceIdentifier path, final SchemaContext schemaContext,
-            final DOMTransactionChain domTransactionChain, final DataSchemaNode schemaNode) {
+            final TransactionChainHandler transactionChainHandler, final DataSchemaNode schemaNode) {
         final InstanceIdentifierContext<?> iid = new InstanceIdentifierContext<SchemaNode>(
                 path.getParent(), schemaNode, null, schemaContext);
-        final TransactionVarsWrapper transactionNode =
-                new TransactionVarsWrapper(iid, null, domTransactionChain);
+        final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(iid, null, transactionChainHandler);
         final NormalizedNode<?, ?> readData = ReadDataTransactionUtil
                 .readData(RestconfDataServiceConstant.ReadData.CONFIG, transactionNode, schemaContext);
         return readData;
index a4452b6e986b6951cfb3af25092967cf6c5bd5e6..f6e50c021a31a39101b45ca3f6ca0471794bbebb 100644 (file)
@@ -17,11 +17,10 @@ import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
@@ -84,13 +83,13 @@ public final class TransactionUtil {
     /**
      * Check if items already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
      * data does NOT already exists.
-     * @param transactionChain Transaction chain
+     * @param transactionChainHandler Transaction chain handler
      * @param rwTransaction Transaction
      * @param store Datastore
      * @param path Path to be checked
      * @param operationType Type of operation (READ, POST, PUT, DELETE...)
      */
-    public static void checkItemExists(final DOMTransactionChain transactionChain,
+    public static void checkItemExists(final TransactionChainHandler transactionChainHandler,
                                        final DOMDataReadWriteTransaction rwTransaction,
                                        final LogicalDatastoreType store, final YangInstanceIdentifier path,
                                        final String operationType) {
@@ -102,7 +101,7 @@ public final class TransactionUtil {
         if (!response.result) {
             // close transaction and reset transaction chain
             rwTransaction.cancel();
-            RestConnectorProvider.resetTransactionChainForAdapaters(transactionChain);
+            transactionChainHandler.reset();
 
             // throw error
             final String errMsg = "Operation via Restconf was not executed because data does not exist";
@@ -115,13 +114,13 @@ public final class TransactionUtil {
     /**
      * Check if items do NOT already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
      * data already exists.
-     * @param transactionChain Transaction chain
+     * @param transactionChainHandler Transaction chain handler
      * @param rwTransaction Transaction
      * @param store Datastore
      * @param path Path to be checked
      * @param operationType Type of operation (READ, POST, PUT, DELETE...)
      */
-    public static void checkItemDoesNotExists(final DOMTransactionChain transactionChain,
+    public static void checkItemDoesNotExists(final TransactionChainHandler transactionChainHandler,
                                               final DOMDataReadWriteTransaction rwTransaction,
                                               final LogicalDatastoreType store, final YangInstanceIdentifier path,
                                               final String operationType) {
@@ -133,7 +132,7 @@ public final class TransactionUtil {
         if (response.result) {
             // close transaction and reset transaction chain
             rwTransaction.cancel();
-            RestConnectorProvider.resetTransactionChainForAdapaters(transactionChain);
+            transactionChainHandler.reset();
 
             // throw error
             final String errMsg = "Operation via Restconf was not executed because data already exists";
index c78d2738eb25f7731e1436b3462bbae5b0e8cebe..acf12a81193b605180716ad2f18c2cacf3a7e682 100644 (file)
   <bean id="wrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl"
           factory-method="getInstance" />
 
+  <bean id="transactionChainHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler"
+          destroy-method="close">
+    <argument ref="domDataBroker"/>
+  </bean>
+
   <bean id="restconfProvider" class="org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider"
           init-method="start" destroy-method="close">
     <argument ref="domDataBroker"/>
@@ -46,6 +51,7 @@
     <argument ref="domRpcService"/>
     <argument ref="domNotificationService"/>
     <argument ref="domMountPointService"/>
+    <argument ref="transactionChainHandler"/>
     <argument ref="wrapper"/>
   </bean>
 
index 2f3bcfad244ed0bb948c71ee42aef8acb61eef15..40152962518021f1a733f515c1252262c1e37208 100644 (file)
@@ -25,6 +25,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
@@ -34,7 +35,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
  */
 public class RestConnectorProviderTest {
     // service under test
-    private RestConnectorProvider connectorProvider;
+    private RestConnectorProvider<?> connectorProvider;
 
     @Mock private DOMMountPointService mockMountPointService;
     @Mock private DOMDataBroker mockDataBroker;
@@ -56,8 +57,9 @@ public class RestConnectorProviderTest {
         doReturn(mockRegistration).when(domSchemaService).registerSchemaContextListener(
                 Mockito.any(SchemaContextHandler.class));
 
-        this.connectorProvider = new RestConnectorProvider(mockDataBroker, domSchemaService, mockRpcService,
-                mockNotificationService, mockMountPointService, ServicesWrapperImpl.getInstance());
+        this.connectorProvider = new RestConnectorProvider<>(mockDataBroker, domSchemaService, mockRpcService,
+                mockNotificationService, mockMountPointService,
+                new TransactionChainHandler(mockDataBroker), ServicesWrapperImpl.getInstance());
     }
 
     /**
@@ -94,6 +96,5 @@ public class RestConnectorProviderTest {
 
         // verify interaction
         verify(this.mockRegistration).close();
-        verify(mockTransactionChain).close();
     }
 }
index 016abcee7f7b1ed648393c3c05455394ee924bcf..c8821e8e7b842040e22b2fa051c051791941687d 100644 (file)
@@ -179,7 +179,7 @@ public class JSONRestconfServiceRfc8040ImplTest {
 
         doReturn(schemaContext).when(mockSchemaContextHandler).get();
 
-        final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockTxChain);
+        final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockDOMDataBroker);
 
         final DOMMountPointServiceHandler mountPointServiceHandler =
                 new DOMMountPointServiceHandler(mockMountPointService);
@@ -193,7 +193,7 @@ public class JSONRestconfServiceRfc8040ImplTest {
         service = new JSONRestconfServiceRfc8040Impl(ServicesWrapperImpl.getInstance(), mountPointServiceHandler);
 
         new RestConnectorProvider<>(mockDOMDataBroker, domSchemaService, mockRpcService, mockNotificationService,
-                mockMountPointService).start();
+                mockMountPointService, txChainHandler, null).start();
 
         SchemaContextHandler.setSchemaContext(schemaContext);
     }
index acde252103c406d2f08a8065078439921093048a..de78c34c9d831d46ecee4ddc61f389c3d30dd963 100644 (file)
@@ -15,16 +15,13 @@ import static org.junit.Assert.assertTrue;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.CREATE;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.DELETE;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.REMOVE;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.REPLACE;
 
 import com.google.common.base.Optional;
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -41,7 +38,6 @@ import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
@@ -55,7 +51,6 @@ import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
@@ -92,9 +87,8 @@ public class RestconfDataServiceImplTest {
     private ContainerNode buildPlayerCont;
     private ContainerNode buildLibraryCont;
     private MapNode buildPlaylistList;
-
-    @Mock
     private TransactionChainHandler transactionChainHandler;
+
     @Mock
     private DOMTransactionChain domTransactionChain;
     @Mock
@@ -114,7 +108,7 @@ public class RestconfDataServiceImplTest {
     @Mock
     private DOMDataBroker mountDataBroker;
     @Mock
-    private DOMTransactionChain transactionChain;
+    private DOMTransactionChain mountTransactionChain;
     @Mock
     private RestconfStreamsSubscriptionService delegRestconfSubscrService;
 
@@ -178,32 +172,32 @@ public class RestconfDataServiceImplTest {
                 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
         this.schemaNode = DataSchemaContextTree.from(this.contextRef.get()).getChild(this.iidBase).getDataSchemaNode();
 
-        final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
-        final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
-        Mockito.when(txHandler.get()).thenReturn(domTx);
-        final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class);
-        Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx);
-        final CheckedFuture<Void, TransactionCommitFailedException> checked = Mockito.mock(CheckedFuture.class);
-        Mockito.when(wTx.submit()).thenReturn(checked);
-        Mockito.when(checked.checkedGet()).thenReturn(null);
-        final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(txHandler);
+        doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
+        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+
+        doReturn(this.read).when(domTransactionChain).newReadOnlyTransaction();
+        doReturn(this.readWrite).when(domTransactionChain).newReadWriteTransaction();
+        doReturn(this.write).when(domTransactionChain).newWriteOnlyTransaction();
+
+        DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+        Mockito.doReturn(domTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+
+        transactionChainHandler = new TransactionChainHandler(mockDataBroker);
+
+        final SchemaContextHandler schemaContextHandler = new SchemaContextHandler(transactionChainHandler);
 
         schemaContextHandler.onGlobalContextUpdated(this.contextRef.get());
         this.dataService = new RestconfDataServiceImpl(schemaContextHandler, this.transactionChainHandler,
                 this.mountPointServiceHandler, this.delegRestconfSubscrService);
-        doReturn(this.domTransactionChain).when(this.transactionChainHandler).get();
-        doReturn(this.read).when(this.domTransactionChain).newReadOnlyTransaction();
-        doReturn(this.readWrite).when(this.domTransactionChain).newReadWriteTransaction();
-        doReturn(this.write).when(this.domTransactionChain).newWriteOnlyTransaction();
         doReturn(this.mountPointService).when(this.mountPointServiceHandler).get();
         doReturn(Optional.of(this.mountPoint)).when(this.mountPointService)
                 .getMountPoint(any(YangInstanceIdentifier.class));
         doReturn(this.contextRef.get()).when(this.mountPoint).getSchemaContext();
         doReturn(Optional.of(this.mountDataBroker)).when(this.mountPoint).getService(DOMDataBroker.class);
-        doReturn(this.transactionChain).when(this.mountDataBroker)
+        doReturn(this.mountTransactionChain).when(this.mountDataBroker)
                 .createTransactionChain(any(TransactionChainListener.class));
-        doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
-        doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
+        doReturn(this.read).when(this.mountTransactionChain).newReadOnlyTransaction();
+        doReturn(this.readWrite).when(this.mountTransactionChain).newReadWriteTransaction();
     }
 
     @Test
@@ -325,7 +319,6 @@ public class RestconfDataServiceImplTest {
         doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(this.readWrite)
                 .exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         final Response response = this.dataService.putData(null, payload, this.uriInfo);
         assertNotNull(response);
         assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -333,10 +326,10 @@ public class RestconfDataServiceImplTest {
 
     @Test
     public void testPutDataWithMountPoint() {
-        final DOMDataBroker dataBroker = Mockito.mock(DOMDataBroker.class);
-        doReturn(Optional.of(dataBroker)).when(mountPoint).getService(DOMDataBroker.class);
-        doReturn(this.transactionChainHandler.get()).when(dataBroker)
-                .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
+//        final DOMDataBroker dataBroker = Mockito.mock(DOMDataBroker.class);
+//        doReturn(Optional.of(dataBroker)).when(mountPoint).getService(DOMDataBroker.class);
+//        doReturn(this.transactionChainHandler.get()).when(dataBroker)
+//                .createTransactionChain(RestConnectorProvider.TRANSACTION_CHAIN_LISTENER);
         final InstanceIdentifierContext<DataSchemaNode> iidContext =
                 new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, mountPoint, this.contextRef.get());
         final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildBaseCont);
@@ -344,7 +337,6 @@ public class RestconfDataServiceImplTest {
         doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(this.readWrite)
                 .exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         final Response response = this.dataService.putData(null, payload, this.uriInfo);
         assertNotNull(response);
         assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -388,7 +380,6 @@ public class RestconfDataServiceImplTest {
         doReturn(Futures.immediateCheckedFuture(false))
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
         doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/15/")).when(this.uriInfo).getBaseUriBuilder();
 
         final Response response = this.dataService.postData(null, payload, this.uriInfo);
@@ -398,7 +389,6 @@ public class RestconfDataServiceImplTest {
     @Test
     public void testDeleteData() {
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         doReturn(Futures.immediateCheckedFuture(true))
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         final Response response = this.dataService.deleteData("example-jukebox:jukebox");
@@ -412,7 +402,6 @@ public class RestconfDataServiceImplTest {
     @Test
     public void testDeleteDataMountPoint() {
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         doReturn(Futures.immediateCheckedFuture(true))
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         final Response response =
@@ -438,9 +427,7 @@ public class RestconfDataServiceImplTest {
         doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
                 .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         doReturn(Futures.immediateCheckedFuture(false))
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doReturn(Futures.immediateCheckedFuture(true))
@@ -468,9 +455,7 @@ public class RestconfDataServiceImplTest {
         doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
                 .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         doReturn(Futures.immediateCheckedFuture(false))
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doReturn(Futures.immediateCheckedFuture(true))
@@ -484,14 +469,6 @@ public class RestconfDataServiceImplTest {
 
     @Test
     public void testPatchDataDeleteNotExist() throws Exception {
-        final Field handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
-        final Field broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
-
-        handler.setAccessible(true);
-        handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
-
-        broker.setAccessible(true);
-        broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
         final InstanceIdentifierContext<? extends SchemaNode> iidContext =
                 new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef.get());
         final List<PatchEntity> entity = new ArrayList<>();
@@ -507,9 +484,7 @@ public class RestconfDataServiceImplTest {
         doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
                 .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
         doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
-        doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         doReturn(Futures.immediateCheckedFuture(false))
                 .when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
         doReturn(Futures.immediateCheckedFuture(false))
@@ -517,12 +492,6 @@ public class RestconfDataServiceImplTest {
         doReturn(true).when(this.readWrite).cancel();
         final PatchStatusContext status = this.dataService.patchData(patch, this.uriInfo);
 
-        handler.set(RestConnectorProvider.class, null);
-        handler.setAccessible(false);
-
-        broker.set(RestConnectorProvider.class, null);
-        broker.setAccessible(false);
-
         assertFalse(status.isOk());
         assertEquals(3, status.getEditCollection().size());
         assertTrue(status.getEditCollection().get(0).isOk());
index e71982a3a0c19268539165ad0efce3809c5f84b5..7db5afee6052311e8dd18c3ef17620e7831b7175 100644 (file)
@@ -10,15 +10,11 @@ package org.opendaylight.restconf.nb.rfc8040.rests.utils;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
 
 import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status;
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.Mockito;
@@ -31,7 +27,6 @@ import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -43,31 +38,10 @@ public class DeleteDataTransactionUtilTest {
     private InstanceIdentifierContext<?> context;
     @Mock
     private DOMDataReadWriteTransaction readWrite;
+    @Mock
+    private DOMDataBroker mockDataBroker;
 
-    // Fields used when delete operation fails to reset transaction chain
-    private static Field handler;
-    private static Field broker;
-
-    @BeforeClass
-    public static void setup() throws Exception {
-        DeleteDataTransactionUtilTest.handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
-        DeleteDataTransactionUtilTest.broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
-
-        DeleteDataTransactionUtilTest.handler.setAccessible(true);
-        DeleteDataTransactionUtilTest.handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
-
-        DeleteDataTransactionUtilTest.broker.setAccessible(true);
-        DeleteDataTransactionUtilTest.broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
-    }
-
-    @AfterClass
-    public static void clean() throws Exception {
-        DeleteDataTransactionUtilTest.handler.set(RestConnectorProvider.class, null);
-        DeleteDataTransactionUtilTest.handler.setAccessible(false);
-
-        DeleteDataTransactionUtilTest.broker.set(RestConnectorProvider.class, null);
-        DeleteDataTransactionUtilTest.broker.setAccessible(false);
-    }
+    private TransactionChainHandler transactionChainHandler;
 
     @Before
     public void init() throws Exception {
@@ -75,6 +49,9 @@ public class DeleteDataTransactionUtilTest {
         Mockito.when(this.transactionChain.newReadWriteTransaction()).thenReturn(this.readWrite);
         Mockito.when(this.readWrite.submit()).thenReturn(Futures.immediateCheckedFuture(null));
         Mockito.when(this.context.getInstanceIdentifier()).thenReturn(YangInstanceIdentifier.EMPTY);
+
+        Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+        transactionChainHandler = new TransactionChainHandler(mockDataBroker);
     }
 
     /**
@@ -89,7 +66,7 @@ public class DeleteDataTransactionUtilTest {
 
         // test
         final Response response = DeleteDataTransactionUtil.deleteData(
-                new TransactionVarsWrapper(this.context, null, this.transactionChain));
+                new TransactionVarsWrapper(this.context, null, transactionChainHandler));
 
         // assert success
         assertEquals("Not expected response received", Status.NO_CONTENT.getStatusCode(), response.getStatus());
@@ -107,7 +84,8 @@ public class DeleteDataTransactionUtilTest {
 
         // test and assert error
         try {
-            DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null, this.transactionChain));
+            DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null,
+                    transactionChainHandler));
             fail("Delete operation should fail due to missing data");
         } catch (final RestconfDocumentedException e) {
             assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
index efb9b05f16d47a0bb0eb61922a52147731c43813..2f084cb5d43126595deafa52dc3934a654907f6b 100644 (file)
@@ -12,7 +12,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 import static org.mockito.MockitoAnnotations.initMocks;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.CREATE;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.DELETE;
@@ -21,12 +20,12 @@ import static org.opendaylight.restconf.common.patch.PatchEditOperation.REMOVE;
 import static org.opendaylight.restconf.common.patch.PatchEditOperation.REPLACE;
 
 import com.google.common.util.concurrent.Futures;
-import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
@@ -37,7 +36,6 @@ import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.common.patch.PatchStatusContext;
 import org.opendaylight.restconf.common.patch.PatchStatusEntity;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
@@ -62,6 +60,10 @@ public class PatchDataTransactionUtilTest {
     @Mock
     private DOMDataReadWriteTransaction rwTransaction;
 
+    @Mock
+    private DOMDataBroker mockDataBroker;
+
+    private TransactionChainHandler transactionChainHandler;
     private SchemaContextRef refSchemaCtx;
     private YangInstanceIdentifier instanceIdContainer;
     private YangInstanceIdentifier instanceIdCreateAndDelete;
@@ -71,22 +73,12 @@ public class PatchDataTransactionUtilTest {
     private YangInstanceIdentifier targetNodeMerge;
     private MapNode buildArtistList;
 
-    // Fields used when delete operation fails to reset transaction chain
-    private static Field handler;
-    private static Field broker;
-
     @Before
     public void setUp() throws Exception {
         initMocks(this);
 
-        PatchDataTransactionUtilTest.handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
-        PatchDataTransactionUtilTest.broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
-
-        PatchDataTransactionUtilTest.handler.setAccessible(true);
-        PatchDataTransactionUtilTest.handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
-
-        PatchDataTransactionUtilTest.broker.setAccessible(true);
-        PatchDataTransactionUtilTest.broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
+        Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+        transactionChainHandler = new TransactionChainHandler(mockDataBroker);
 
         this.refSchemaCtx = new SchemaContextRef(
                 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_NEW_SCHEMA_CONTEXT)));
@@ -190,7 +182,7 @@ public class PatchDataTransactionUtilTest {
         final InstanceIdentifierContext<? extends SchemaNode> iidContext =
                 new InstanceIdentifierContext<>(this.instanceIdMerge, null, null, this.refSchemaCtx.get());
         final PatchContext patchContext = new PatchContext(iidContext, entities, "patchRMRm");
-        final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+        final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
         final PatchStatusContext patchStatusContext =
                 PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
 
@@ -219,7 +211,7 @@ public class PatchDataTransactionUtilTest {
         final InstanceIdentifierContext<? extends SchemaNode> iidContext =
                 new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx.get());
         final PatchContext patchContext = new PatchContext(iidContext, entities, "patchCD");
-        final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+        final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
         final PatchStatusContext patchStatusContext =
                 PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
 
@@ -243,7 +235,7 @@ public class PatchDataTransactionUtilTest {
         final InstanceIdentifierContext<? extends SchemaNode> iidContext =
                 new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx.get());
         final PatchContext patchContext = new PatchContext(iidContext, entities, "patchD");
-        final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+        final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
         final PatchStatusContext patchStatusContext =
                 PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
 
@@ -268,7 +260,7 @@ public class PatchDataTransactionUtilTest {
         final InstanceIdentifierContext<? extends SchemaNode> iidContext =
                 new InstanceIdentifierContext<>(this.instanceIdCreateAndDelete, null, null, this.refSchemaCtx.get());
         final PatchContext patchContext = new PatchContext(iidContext, entities, "patchM");
-        final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, this.transactionChain);
+        final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(iidContext, null, transactionChainHandler);
         final PatchStatusContext patchStatusContext =
                 PatchDataTransactionUtil.patchData(patchContext, wrapper, this.refSchemaCtx);
 
@@ -277,4 +269,4 @@ public class PatchDataTransactionUtilTest {
         }
         assertTrue(patchStatusContext.isOk());
     }
-}
\ No newline at end of file
+}
index a22edb193331ec3aeae1d57d91cfa4b0569def8e..105e52704873c5e0b025add50195ce0aec4eeb0f 100644 (file)
@@ -22,8 +22,10 @@ import javax.ws.rs.core.UriInfo;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
@@ -32,6 +34,7 @@ import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
 import org.opendaylight.yangtools.util.SingletonSet;
@@ -63,7 +66,10 @@ public class PostDataTransactionUtilTest {
     private UriInfo uriInfo;
     @Mock
     private UriBuilder uriBuilder;
+    @Mock
+    private DOMDataBroker mockDataBroker;
 
+    private TransactionChainHandler transactionChainHandler;
     private SchemaContextRef refSchemaCtx;
     private ContainerNode buildBaseCont;
     private SchemaContext schema;
@@ -122,6 +128,9 @@ public class PostDataTransactionUtilTest {
         doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/16/")).when(this.uriInfo).getBaseUriBuilder();
         doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
         doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
+
+        Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+        transactionChainHandler = new TransactionChainHandler(mockDataBroker);
     }
 
     @Test
@@ -141,7 +150,7 @@ public class PostDataTransactionUtilTest {
         doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
         doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         final TransactionVarsWrapper wrapper =
-                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
+                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler);
         final Response response =
                 PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
         assertEquals(201, response.getStatus());
@@ -166,7 +175,7 @@ public class PostDataTransactionUtilTest {
         doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
         doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         final TransactionVarsWrapper wrapper =
-                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
+                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler);
         final Response response =
                 PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
         assertEquals(201, response.getStatus());
@@ -193,7 +202,7 @@ public class PostDataTransactionUtilTest {
         final DOMException domException = new DOMException((short) 414, "Post request failed");
         doReturn(Futures.immediateFailedCheckedFuture(domException)).when(this.readWrite).submit();
         final TransactionVarsWrapper wrapper =
-                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
+                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler);
 
         try {
             PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
index 68caab5e33d59f7a45c37008baa5a9b32375c6fe..e44d3da1f43d59b2df98d1773caf6e6c4c67c0e2 100644 (file)
@@ -16,8 +16,10 @@ import com.google.common.util.concurrent.Futures;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
@@ -26,6 +28,7 @@ import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.references.SchemaContextRef;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -52,8 +55,10 @@ public class PutDataTransactionUtilTest {
     private DOMDataReadOnlyTransaction read;
     @Mock
     private DOMDataWriteTransaction write;
+    @Mock
+    private DOMDataBroker mockDataBroker;
 
-
+    private TransactionChainHandler transactionChainHandler;
     private SchemaContextRef refSchemaCtx;
     private LeafNode buildLeaf;
     private ContainerNode buildBaseCont;
@@ -152,6 +157,8 @@ public class PutDataTransactionUtilTest {
                 .withChild(buildList)
                 .build();
 
+        Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+        transactionChainHandler = new TransactionChainHandler(mockDataBroker);
     }
 
     @Test
@@ -214,7 +221,7 @@ public class PutDataTransactionUtilTest {
         doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
 
         PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
-                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
                 null);
         verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION,
                 payload.getInstanceIdentifierContext().getInstanceIdentifier());
@@ -238,7 +245,7 @@ public class PutDataTransactionUtilTest {
         doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
 
         PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
-                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
                 null);
         verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION,
                 payload.getInstanceIdentifierContext().getInstanceIdentifier());
@@ -261,7 +268,7 @@ public class PutDataTransactionUtilTest {
                 payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
         doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
         PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
-                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+                new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChainHandler), null,
                 null);
         verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2);
         verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iid2, payload.getData());
index 5199c6e527b6464b70cb77271738a0fb68420cbe..718f050fe09ad993f045b64b85b3096a46712133 100644 (file)
@@ -27,6 +27,7 @@ import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadOnlyTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
@@ -34,6 +35,7 @@ import org.opendaylight.restconf.common.context.WriterParameters;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
+import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.nb.rfc8040.rests.transactions.TransactionVarsWrapper;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -82,7 +84,9 @@ public class ReadDataTransactionUtilTest {
         when(containerChildNode.getQName()).thenReturn(containerChildQName);
         when(containerSchemaNode.getDataChildByName(containerChildQName)).thenReturn(containerChildNode);
 
-        wrapper = new TransactionVarsWrapper(this.context, null, this.transactionChain);
+        DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+        Mockito.doReturn(transactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
+        wrapper = new TransactionVarsWrapper(this.context, null, new TransactionChainHandler(mockDataBroker));
     }
 
     @Test
index 1fb86d2732189dd82f755309067a2ca955f1909a..d80a86f004d8f8004606138476695f03f8628e0d 100644 (file)
@@ -24,12 +24,10 @@ import java.util.concurrent.TimeUnit;
 import org.json.JSONObject;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeIdentifier;
@@ -73,8 +71,7 @@ public class ListenerAdapterTest extends AbstractConcurrentDataBrokerTest {
         SchemaContext sc = YangParserTestUtils.parseYangResource(
                 "/instanceidentifier/yang/instance-identifier-patch-module.yang");
 
-        transactionChainHandler = new TransactionChainHandler(domDataBroker.createTransactionChain(
-                Mockito.mock(TransactionChainListener.class)));
+        transactionChainHandler = new TransactionChainHandler(domDataBroker);
         schemaContextHandler = new SchemaContextHandler(transactionChainHandler);
         SchemaContextHandler.setSchemaContext(sc);
     }