Merge changes from topic 'rem_web_xml'
authorJakub Morvay <jakub.morvay@gmail.com>
Thu, 26 Apr 2018 10:38:38 +0000 (10:38 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 26 Apr 2018 10:38:38 +0000 (10:38 +0000)
* changes:
  Remove RestConnectorProvider
  Use DOMMountPointServiceHandler non-statically
  Use SchemaContextHandler non-statically
  Remove static TransactionChainHandler instance

48 files changed:
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java [deleted file]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfApplication.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfConnector.java [deleted file]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMMountPointServiceHandler.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/jersey/providers/JsonNormalizedNodeBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlNormalizedNodeBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/AbstractToPatchBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonToPatchBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlToPatchBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractIdentifierAwareJaxRsProvider.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/spi/AbstractNormalizedNodeBodyReader.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040Impl.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/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServiceWrapper.java [deleted file]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java [moved from restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapperImpl.java with 85% similarity]
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 [deleted file]
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/TestUtils.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandlerTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/XmlBodyReaderMountPointTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderMountPointTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/JsonPatchBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderMountPointTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/patch/XmlPatchBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/AbstractBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/JsonBodyReaderTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/jersey/providers/test/XmlBodyReaderTest.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/services/impl/RestconfInvokeOperationsServiceImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfStreamsSubscriptionServiceImplTest.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/services/simple/impl/RestconfImplTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfOperationsServiceTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/services/simple/impl/RestconfSchemaServiceTest.java
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/ListenerAdapterTest.java

diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProvider.java
deleted file mode 100644 (file)
index 7e251ef..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-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;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServiceWrapper;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Provider for restconf draft18.
- *
- */
-public class RestConnectorProvider<T extends ServiceWrapper> implements RestconfConnector, AutoCloseable {
-
-    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;
-
-    private final DOMRpcService rpcService;
-    private final DOMNotificationService notificationService;
-    private final DOMMountPointService mountPointService;
-    private final DOMSchemaService domSchemaService;
-    private final Builder<Object> servicesProperties;
-
-    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);
-    }
-
-    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();
-        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);
-    }
-
-    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,
-                    notificationServiceHandler, domSchemaService);
-        }
-    }
-
-    public DOMMountPointServiceHandler getMountPointServiceHandler() {
-        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}
-     */
-    public static DOMMountPointService getMountPointService() {
-        return mountPointServiceHandler.get();
-    }
-
-    @Override
-    public void close() throws Exception {
-        // close registration
-        if (this.listenerRegistration != null) {
-            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 e779281483c80b1a1c3b0e48c4e8e422af8e9b65..76b560c296196d7f3811e7111304d2b335b73272 100644 (file)
@@ -11,6 +11,8 @@ import com.google.common.collect.ImmutableSet;
 import java.util.HashSet;
 import java.util.Set;
 import javax.ws.rs.core.Application;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.NormalizedNodeJsonBodyWriter;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.NormalizedNodeXmlBodyWriter;
@@ -21,17 +23,17 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.PatchXmlBodyW
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.XmlToPatchBodyReader;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYangBodyWriter;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYinBodyWriter;
-import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
 
 public class RestconfApplication extends Application {
+    private final SchemaContextHandler schemaContextHandler = SchemaContextHandler.instance();
+    private final DOMMountPointServiceHandler mountPointServiceHandler = DOMMountPointServiceHandler.instance();
 
     @Override
     public Set<Class<?>> getClasses() {
         return ImmutableSet.<Class<?>>builder()
                 .add(NormalizedNodeJsonBodyWriter.class).add(NormalizedNodeXmlBodyWriter.class)
-                .add(JsonNormalizedNodeBodyReader.class).add(XmlNormalizedNodeBodyReader.class)
                 .add(SchemaExportContentYinBodyWriter.class).add(SchemaExportContentYangBodyWriter.class)
-                .add(JsonToPatchBodyReader.class).add(XmlToPatchBodyReader.class)
                 .add(PatchJsonBodyWriter.class).add(PatchXmlBodyWriter.class)
                 .build();
     }
@@ -39,7 +41,11 @@ public class RestconfApplication extends Application {
     @Override
     public Set<Object> getSingletons() {
         final Set<Object> singletons = new HashSet<>();
-        singletons.add(ServicesWrapperImpl.getInstance());
+        singletons.add(ServicesWrapper.getInstance());
+        singletons.add(new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
+        singletons.add(new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
+        singletons.add(new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler));
+        singletons.add(new XmlToPatchBodyReader(schemaContextHandler, mountPointServiceHandler));
         return singletons;
     }
 }
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfConnector.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/RestconfConnector.java
deleted file mode 100644 (file)
index 26a53cd..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.restconf.nb.rfc8040;
-
-/*
- * This is a simple dummy interface to allow us to create instances of RestconfProvider
- * via the config subsystem.
- */
-public interface RestconfConnector {
-
-}
index c95ee3f64cf7aa54383336a4996e453647432862..e299fe071587c1690620b44669926efdd7444602 100644 (file)
@@ -14,8 +14,10 @@ import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
  * Implementation of {@link DOMMountPointServiceHandler}.
  *
  */
-public class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
-    private final DOMMountPointService domMountPointService;
+public final class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
+    private static final DOMMountPointServiceHandler INSTANCE = new DOMMountPointServiceHandler();
+
+    private DOMMountPointService domMountPointService;
 
     /**
      * Prepare mount point service for Restconf services.
@@ -23,10 +25,24 @@ public class DOMMountPointServiceHandler implements Handler<DOMMountPointService
      * @param domMountPointService
      *             mount point service
      */
-    public DOMMountPointServiceHandler(final DOMMountPointService domMountPointService) {
+    private DOMMountPointServiceHandler(final DOMMountPointService domMountPointService) {
         this.domMountPointService = Objects.requireNonNull(domMountPointService);
     }
 
+    @Deprecated
+    private DOMMountPointServiceHandler() {
+    }
+
+    @Deprecated
+    public static DOMMountPointServiceHandler instance() {
+        return INSTANCE;
+    }
+
+    public static DOMMountPointServiceHandler newInstance(DOMMountPointService domMountPointService) {
+        INSTANCE.domMountPointService = domMountPointService;
+        return INSTANCE;
+    }
+
     @Override
     public DOMMountPointService get() {
         return this.domMountPointService;
index 51b7790fd34913a586e8a4a4adfa54e2466ee927..aecbf8d6aed547fe4a773075446606168c40caef 100644 (file)
@@ -8,17 +8,17 @@
 package org.opendaylight.restconf.nb.rfc8040.handlers;
 
 import com.google.common.base.Preconditions;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Collection;
 import java.util.concurrent.atomic.AtomicInteger;
 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.mdsal.dom.api.DOMSchemaService;
 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;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -27,6 +27,7 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -34,25 +35,57 @@ import org.slf4j.LoggerFactory;
  * Implementation of {@link SchemaContextHandler}.
  *
  */
-public class SchemaContextHandler implements SchemaContextListenerHandler {
+@SuppressWarnings("checkstyle:FinalClass")
+public class SchemaContextHandler implements SchemaContextListenerHandler, AutoCloseable {
 
     private static final Logger LOG = LoggerFactory.getLogger(SchemaContextHandler.class);
 
-    @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
-    private static volatile SchemaContext schemaContext;
-
-    private final TransactionChainHandler transactionChainHandler;
+    private static final SchemaContextHandler INSTANCE = new SchemaContextHandler();
 
     private final AtomicInteger moduleSetId = new AtomicInteger(0);
 
+    private TransactionChainHandler transactionChainHandler;
+    private DOMSchemaService domSchemaService;
+    private ListenerRegistration<SchemaContextListener> listenerRegistration;
+
+    private volatile SchemaContext schemaContext;
+
     /**
      * Constructor.
      *
      * @param transactionChainHandler Transaction chain handler
      */
-    public SchemaContextHandler(final TransactionChainHandler transactionChainHandler) {
+    private SchemaContextHandler(final TransactionChainHandler transactionChainHandler,
+            final DOMSchemaService domSchemaService) {
         this.transactionChainHandler = transactionChainHandler;
-        schemaContext = null;
+        this.domSchemaService = domSchemaService;
+    }
+
+    @Deprecated
+    private SchemaContextHandler() {
+    }
+
+    @Deprecated
+    public static SchemaContextHandler instance() {
+        return INSTANCE;
+    }
+
+    public static SchemaContextHandler newInstance(TransactionChainHandler transactionChainHandler,
+            DOMSchemaService domSchemaService) {
+        INSTANCE.transactionChainHandler = transactionChainHandler;
+        INSTANCE.domSchemaService = domSchemaService;
+        return INSTANCE;
+    }
+
+    public void init() {
+        listenerRegistration = domSchemaService.registerSchemaContextListener(this);
+    }
+
+    @Override
+    public void close() {
+        if (listenerRegistration != null) {
+            listenerRegistration.close();
+        }
     }
 
     @Override
@@ -63,15 +96,20 @@ public class SchemaContextHandler implements SchemaContextListenerHandler {
 
         final Module ietfYangLibraryModule =
                 context.findModule(IetfYangLibrary.MODULE_QNAME).orElse(null);
-        NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode =
-                RestconfMappingNodeUtil.mapModulesByIetfYangLibraryYang(context.getModules(), ietfYangLibraryModule,
-                        context, String.valueOf(this.moduleSetId.incrementAndGet()));
-        putData(normNode);
+        if (ietfYangLibraryModule != null) {
+            NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode =
+                    RestconfMappingNodeUtil.mapModulesByIetfYangLibraryYang(context.getModules(), ietfYangLibraryModule,
+                            context, String.valueOf(this.moduleSetId.incrementAndGet()));
+            putData(normNode);
+        }
 
         final Module monitoringModule =
                 schemaContext.findModule(MonitoringModule.MODULE_QNAME).orElse(null);
-        normNode = RestconfMappingNodeUtil.mapCapabilites(monitoringModule);
-        putData(normNode);
+        if (monitoringModule != null) {
+            NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode =
+                    RestconfMappingNodeUtil.mapCapabilites(monitoringModule);
+            putData(normNode);
+        }
     }
 
     @Override
@@ -79,14 +117,6 @@ public class SchemaContextHandler implements SchemaContextListenerHandler {
         return schemaContext;
     }
 
-    public static SchemaContext getSchemaContext() {
-        return schemaContext;
-    }
-
-    public static void setSchemaContext(final SchemaContext context) {
-        schemaContext = context;
-    }
-
     private void putData(
             final NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode) {
         final DOMDataWriteTransaction wTx = this.transactionChainHandler.get().newWriteOnlyTransaction();
@@ -108,7 +138,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 83b927a7bbadcb498222c4be93c45ebc9f5cbb81..37a39b62d9c3874d5e0be9ae8eb498152dc0521b 100644 (file)
@@ -25,6 +25,8 @@ 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.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractNormalizedNodeBodyReader;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -50,9 +52,13 @@ import org.slf4j.LoggerFactory;
 @Provider
 @Consumes({ Rfc8040.MediaTypes.DATA + RestconfConstants.JSON, MediaType.APPLICATION_JSON })
 public class JsonNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader {
-
     private static final Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
 
+    public JsonNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler,
+            DOMMountPointServiceHandler mountPointServiceHandler) {
+        super(schemaContextHandler, mountPointServiceHandler);
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     protected NormalizedNodeContext readBody(final InstanceIdentifierContext<?> path, final InputStream entityStream)
index 54ea4fe3680acc2214e053e6ff62227435b19a89..62fd33a51f1f7deba2bec1373fb3d92b83898b38 100644 (file)
@@ -30,6 +30,8 @@ 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.Rfc8040;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractNormalizedNodeBodyReader;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
@@ -63,6 +65,11 @@ import org.xml.sax.SAXException;
 public class XmlNormalizedNodeBodyReader extends AbstractNormalizedNodeBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class);
 
+    public XmlNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler,
+            DOMMountPointServiceHandler mountPointServiceHandler) {
+        super(schemaContextHandler, mountPointServiceHandler);
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     protected NormalizedNodeContext readBody(final InstanceIdentifierContext<?> path, final InputStream entityStream)
index e2e7fdc21d9ffcd891794ce0b3fb26b0ae9c521f..5ceaf04544efe91f0086d3c2a243b47c19b1f0e4 100644 (file)
@@ -9,6 +9,8 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
 
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.patch.PatchContext;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
 
 /**
@@ -17,6 +19,10 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentif
  * @author Robert Varga
  */
 abstract class AbstractToPatchBodyReader extends AbstractIdentifierAwareJaxRsProvider<PatchContext> {
+    protected AbstractToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+            DOMMountPointServiceHandler mountPointServiceHandler) {
+        super(schemaContextHandler, mountPointServiceHandler);
+    }
 
     @Override
     protected final PatchContext emptyBody(final InstanceIdentifierContext<?> path) {
index 9985f7686124ab7d7ef81050ee47ef6846632d17..232a9a7c03ff4b5eeac6a67f2c3c8189395bab23 100644 (file)
@@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
+import java.util.concurrent.atomic.AtomicReference;
 import javax.annotation.Nonnull;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.WebApplicationException;
@@ -32,9 +33,9 @@ import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.common.patch.PatchContext;
 import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 import org.opendaylight.restconf.nb.rfc8040.codecs.StringModuleInstanceIdentifierCodec;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
@@ -57,7 +58,10 @@ import org.slf4j.LoggerFactory;
 public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(JsonToPatchBodyReader.class);
 
-    private String patchId;
+    public JsonToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+            DOMMountPointServiceHandler mountPointServiceHandler) {
+        super(schemaContextHandler, mountPointServiceHandler);
+    }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
@@ -73,10 +77,11 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
     private PatchContext readFrom(final InstanceIdentifierContext<?> path, final InputStream entityStream)
             throws IOException {
         final JsonReader jsonReader = new JsonReader(new InputStreamReader(entityStream, StandardCharsets.UTF_8));
-        final List<PatchEntity> resultList = read(jsonReader, path);
+        AtomicReference<String> patchId = new AtomicReference<>();
+        final List<PatchEntity> resultList = read(jsonReader, path, patchId);
         jsonReader.close();
 
-        return new PatchContext(path, resultList, patchId);
+        return new PatchContext(path, resultList, patchId.get());
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
@@ -84,8 +89,8 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
             RestconfDocumentedException {
         try {
             return readFrom(
-                    ParserIdentifier.toInstanceIdentifier(uriPath, SchemaContextHandler.getSchemaContext(),
-                            Optional.of(RestConnectorProvider.getMountPointService())), entityStream);
+                    ParserIdentifier.toInstanceIdentifier(uriPath, getSchemaContext(),
+                            Optional.fromNullable(getMountPointService())), entityStream);
         } catch (final Exception e) {
             propagateExceptionAs(e);
             return null; // no-op
@@ -106,7 +111,8 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
                 ErrorTag.MALFORMED_MESSAGE, exception);
     }
 
-    private List<PatchEntity> read(final JsonReader in, final InstanceIdentifierContext<?> path) throws IOException {
+    private List<PatchEntity> read(final JsonReader in, final InstanceIdentifierContext<?> path,
+            final AtomicReference<String> patchId) throws IOException {
         final List<PatchEntity> resultCollection = new ArrayList<>();
         final StringModuleInstanceIdentifierCodec codec = new StringModuleInstanceIdentifierCodec(
                 path.getSchemaContext());
@@ -133,7 +139,7 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
                 case END_DOCUMENT:
                     break;
                 case NAME:
-                    parseByName(in.nextName(), edit, in, path, codec, resultCollection);
+                    parseByName(in.nextName(), edit, in, path, codec, resultCollection, patchId);
                     break;
                 case END_OBJECT:
                     in.endObject();
@@ -164,7 +170,8 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
     private void parseByName(@Nonnull final String name, @Nonnull final PatchEdit edit,
                              @Nonnull final JsonReader in, @Nonnull final InstanceIdentifierContext<?> path,
                              @Nonnull final StringModuleInstanceIdentifierCodec codec,
-                             @Nonnull final List<PatchEntity> resultCollection) throws IOException {
+                             @Nonnull final List<PatchEntity> resultCollection,
+                             @Nonnull final AtomicReference<String> patchId) throws IOException {
         switch (name) {
             case "edit":
                 if (in.peek() == JsonToken.BEGIN_ARRAY) {
@@ -185,7 +192,7 @@ public class JsonToPatchBodyReader extends AbstractToPatchBodyReader {
 
                 break;
             case "patch-id":
-                this.patchId = in.nextString();
+                patchId.set(in.nextString());
                 break;
             default:
                 break;
index 7af6e56b32c14e2b35de0c58eebf5aeea42f02cd..8364572de4874a2e2b8ca807e07375e9805eab32 100644 (file)
@@ -34,6 +34,8 @@ import org.opendaylight.restconf.common.patch.PatchEditOperation;
 import org.opendaylight.restconf.common.patch.PatchEntity;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040;
 import org.opendaylight.restconf.nb.rfc8040.codecs.StringModuleInstanceIdentifierCodec;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -66,6 +68,11 @@ public class XmlToPatchBodyReader extends AbstractToPatchBodyReader {
     private static final Logger LOG = LoggerFactory.getLogger(XmlToPatchBodyReader.class);
     private static final Splitter SLASH_SPLITTER = Splitter.on('/');
 
+    public XmlToPatchBodyReader(SchemaContextHandler schemaContextHandler,
+            DOMMountPointServiceHandler mountPointServiceHandler) {
+        super(schemaContextHandler, mountPointServiceHandler);
+    }
+
     @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     protected PatchContext readBody(final InstanceIdentifierContext<?> path, final InputStream entityStream)
index 8028ee94d8cd5c1bd2ccc386f74feda47d654662..f516e5f1d45f2882e0f599a6d6f0bfe3bc453d0a 100644 (file)
@@ -22,11 +22,13 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.MessageBodyReader;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
-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.utils.RestconfConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements MessageBodyReader<T> {
 
@@ -36,6 +38,15 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
     @Context
     private Request request;
 
+    private final SchemaContextHandler schemaContextHandler;
+    private final DOMMountPointServiceHandler mountPointServiceHandler;
+
+    protected AbstractIdentifierAwareJaxRsProvider(SchemaContextHandler schemaContextHandler,
+            DOMMountPointServiceHandler mountPointServiceHandler) {
+        this.schemaContextHandler = schemaContextHandler;
+        this.mountPointServiceHandler = mountPointServiceHandler;
+    }
+
     @Override
     public final boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
             final MediaType mediaType) {
@@ -78,16 +89,22 @@ public abstract class AbstractIdentifierAwareJaxRsProvider<T> implements Message
     }
 
     private InstanceIdentifierContext<?> getInstanceIdentifierContext() {
-        return ParserIdentifier.toInstanceIdentifier(
-                getIdentifier(),
-                SchemaContextHandler.getSchemaContext(),
-                Optional.of(RestConnectorProvider.getMountPointService()));
+        return ParserIdentifier.toInstanceIdentifier(getIdentifier(), getSchemaContext(),
+                Optional.fromNullable(getMountPointService()));
     }
 
     protected UriInfo getUriInfo() {
         return this.uriInfo;
     }
 
+    protected SchemaContext getSchemaContext() {
+        return schemaContextHandler.get();
+    }
+
+    protected DOMMountPointService getMountPointService() {
+        return mountPointServiceHandler.get();
+    }
+
     protected boolean isPost() {
         return HttpMethod.POST.equals(this.request.getMethod());
     }
index 61147543e22849d4a641013869e857acdae6b87c..90703bfee42eb347a5640ac4c94d6f644b470395 100644 (file)
@@ -12,6 +12,8 @@ import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
+import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 
 /**
  * Common superclass for readers producing {@link NormalizedNodeContext}.
@@ -21,6 +23,10 @@ import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 @Beta
 public abstract class AbstractNormalizedNodeBodyReader
         extends AbstractIdentifierAwareJaxRsProvider<NormalizedNodeContext> {
+    protected AbstractNormalizedNodeBodyReader(SchemaContextHandler schemaContextHandler,
+            DOMMountPointServiceHandler mountPointServiceHandler) {
+        super(schemaContextHandler, mountPointServiceHandler);
+    }
 
     public final void injectParams(final UriInfo uriInfo, final Request request) {
         setUriInfo(uriInfo);
index 8ec497f31e49f302ed3b9c819f3e7fa83e93e6df..5efca62de73e4feba25732a261c68a3751e57ae6 100644 (file)
@@ -60,11 +60,14 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto
 
     private final TransactionServicesWrapper services;
     private final DOMMountPointServiceHandler mountPointServiceHandler;
+    private final SchemaContextHandler schemaContextHandler;
 
     public JSONRestconfServiceRfc8040Impl(final TransactionServicesWrapper services,
-            final DOMMountPointServiceHandler mountPointServiceHandler) {
+            final DOMMountPointServiceHandler mountPointServiceHandler,
+            final SchemaContextHandler schemaContextHandler) {
         this.services = services;
         this.mountPointServiceHandler = mountPointServiceHandler;
+        this.schemaContextHandler = schemaContextHandler;
     }
 
     @SuppressWarnings("checkstyle:IllegalCatch")
@@ -192,7 +195,8 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto
 
         final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
 
-        JsonToPatchBodyReader jsonToPatchBodyReader = new JsonToPatchBodyReader();
+        JsonToPatchBodyReader jsonToPatchBodyReader =
+                new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
         final PatchContext context = jsonToPatchBodyReader.readFrom(uriPath, entityStream);
 
         LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
@@ -214,8 +218,7 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto
     private NormalizedNodeContext toNormalizedNodeContext(final String uriPath, @Nullable final String payload,
             final boolean isPost) throws OperationFailedException {
         final InstanceIdentifierContext<?> instanceIdentifierContext = ParserIdentifier.toInstanceIdentifier(
-                uriPath, SchemaContextHandler.getSchemaContext(),
-                Optional.of(mountPointServiceHandler.get()));
+                uriPath, schemaContextHandler.get(), Optional.of(mountPointServiceHandler.get()));
 
         if (payload == null) {
             return new NormalizedNodeContext(instanceIdentifierContext, null);
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";
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServiceWrapper.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServiceWrapper.java
deleted file mode 100644 (file)
index 157d7d4..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (c) 2017 Pantheon Technologies, s.r.o. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040.services.wrapper;
-
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
-
-public interface ServiceWrapper {
-
-    void setHandlers(SchemaContextHandler schemaCtxHandler, DOMMountPointServiceHandler domMountPointServiceHandler,
-            TransactionChainHandler transactionChainHandler, DOMDataBrokerHandler domDataBrokerHandler,
-            RpcServiceHandler rpcServiceHandler, NotificationServiceHandler notificationServiceHandler,
-            DOMSchemaService domSchemaService);
-}
@@ -46,7 +46,7 @@ import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfSchemaS
  *
  */
 @Path("/")
-public final class ServicesWrapperImpl implements BaseServicesWrapper, TransactionServicesWrapper, ServiceWrapper {
+public final class ServicesWrapper implements BaseServicesWrapper, TransactionServicesWrapper {
 
     private RestconfDataService delegRestconfDataService;
     private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
@@ -55,14 +55,41 @@ public final class ServicesWrapperImpl implements BaseServicesWrapper, Transacti
     private RestconfSchemaService delegRestSchService;
     private RestconfService delegRestService;
 
-    private ServicesWrapperImpl() {
+    @Deprecated
+    private ServicesWrapper() {
     }
 
     private static class InstanceHolder {
-        public static final ServicesWrapperImpl INSTANCE = new ServicesWrapperImpl();
+        public static final ServicesWrapper INSTANCE = new ServicesWrapper();
     }
 
-    public static ServicesWrapperImpl getInstance() {
+    @Deprecated
+    public static ServicesWrapper getInstance() {
+        return InstanceHolder.INSTANCE;
+    }
+
+    public static ServicesWrapper newInstance(final SchemaContextHandler schemaCtxHandler,
+            final DOMMountPointServiceHandler domMountPointServiceHandler,
+            final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
+            final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
+            final DOMSchemaService domSchemaService) {
+        InstanceHolder.INSTANCE.delegRestOpsService =
+                new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+        final DOMYangTextSourceProvider yangTextSourceProvider =
+                (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
+                        .get(DOMYangTextSourceProvider.class);
+        InstanceHolder.INSTANCE.delegRestSchService =
+                new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
+                yangTextSourceProvider);
+        InstanceHolder.INSTANCE.delegRestconfSubscrService =
+                new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
+                notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
+        InstanceHolder.INSTANCE.delegRestconfDataService =
+                new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler, domMountPointServiceHandler,
+                        InstanceHolder.INSTANCE.delegRestconfSubscrService);
+        InstanceHolder.INSTANCE.delegRestconfInvokeOpsService =
+                new RestconfInvokeOperationsServiceImpl(rpcServiceHandler, schemaCtxHandler);
+        InstanceHolder.INSTANCE.delegRestService = new RestconfImpl(schemaCtxHandler);
         return InstanceHolder.INSTANCE;
     }
 
@@ -136,26 +163,4 @@ public final class ServicesWrapperImpl implements BaseServicesWrapper, Transacti
     public NormalizedNodeContext getLibraryVersion() {
         return this.delegRestService.getLibraryVersion();
     }
-
-    @Override
-    public void setHandlers(final SchemaContextHandler schemaCtxHandler,
-            final DOMMountPointServiceHandler domMountPointServiceHandler,
-            final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
-            final RpcServiceHandler rpcServiceHandler, final NotificationServiceHandler notificationServiceHandler,
-            final DOMSchemaService domSchemaService) {
-        this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
-        final DOMYangTextSourceProvider yangTextSourceProvider =
-                (DOMYangTextSourceProvider) domSchemaService.getSupportedExtensions()
-                        .get(DOMYangTextSourceProvider.class);
-        this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler,
-                yangTextSourceProvider);
-        this.delegRestconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler,
-                notificationServiceHandler, schemaCtxHandler, transactionChainHandler);
-        this.delegRestconfDataService =
-                new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler, domMountPointServiceHandler,
-                        this.delegRestconfSubscrService);
-        this.delegRestconfInvokeOpsService =
-                new RestconfInvokeOperationsServiceImpl(rpcServiceHandler, schemaCtxHandler);
-        this.delegRestService = new RestconfImpl(schemaCtxHandler);
-    }
 }
index c78d2738eb25f7731e1436b3462bbae5b0e8cebe..022982962ffc2fc00b4f53fbd2bc62c76b1257f1 100644 (file)
           ext:filter="(type=@{databroker-service-type})"/>
   <reference id="domSchemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
 
-  <bean id="wrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapperImpl"
-          factory-method="getInstance" />
-
-  <bean id="restconfProvider" class="org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider"
-          init-method="start" destroy-method="close">
+  <bean id="transactionChainHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler"
+          destroy-method="close">
     <argument ref="domDataBroker"/>
+  </bean>
+
+  <bean id="schemaContextHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler"
+      factory-method="newInstance" init-method="init" destroy-method="close">
+    <argument ref="transactionChainHandler"/>
     <argument ref="domSchemaService"/>
+  </bean>
+
+  <bean id="mountPointServiceHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler"
+      factory-method="newInstance">
+    <argument ref="domMountPointService"/>
+  </bean>
+
+  <bean id="dataBrokerHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler">
+    <argument ref="domDataBroker"/>
+  </bean>
+
+  <bean id="rpcServiceHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler">
     <argument ref="domRpcService"/>
+  </bean>
+
+  <bean id="notificationServiceHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler">
     <argument ref="domNotificationService"/>
-    <argument ref="domMountPointService"/>
-    <argument ref="wrapper"/>
   </bean>
 
-  <service ref="restconfProvider"
-      interface="org.opendaylight.restconf.nb.rfc8040.RestconfConnector" />
+  <bean id="servicesWrapper" class="org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper"
+      factory-method="newInstance">
+    <argument ref="schemaContextHandler"/>
+    <argument ref="mountPointServiceHandler"/>
+    <argument ref="transactionChainHandler"/>
+    <argument ref="dataBrokerHandler"/>
+    <argument ref="rpcServiceHandler"/>
+    <argument ref="notificationServiceHandler"/>
+    <argument ref="domSchemaService"/>
+  </bean>
 
   <!-- JSONRestconfService -->
-  <bean id="jsonRestconfService" depends-on="restconfProvider"
+  <bean id="jsonRestconfService"
       class="org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl"
       destroy-method="close">
-    <argument ref="wrapper"/>
-    <argument>
-      <bean factory-ref="restconfProvider" factory-method="getMountPointServiceHandler" />
-    </argument>
+    <argument ref="servicesWrapper"/>
+    <argument ref="mountPointServiceHandler"/>
+    <argument ref="schemaContextHandler"/>
   </bean>
 
   <service ref="jsonRestconfService" odl:type="rfc8040"
diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProviderTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/RestConnectorProviderTest.java
deleted file mode 100644 (file)
index 2f3bcfa..0000000
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.restconf.nb.rfc8040;
-
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.verify;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.mockito.Mock;
-import org.mockito.Mockito;
-import org.mockito.MockitoAnnotations;
-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.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.services.wrapper.ServicesWrapperImpl;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
-import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
-
-/**
- * Unit tests for {@link RestConnectorProvider}.
- */
-public class RestConnectorProviderTest {
-    // service under test
-    private RestConnectorProvider connectorProvider;
-
-    @Mock private DOMMountPointService mockMountPointService;
-    @Mock private DOMDataBroker mockDataBroker;
-    @Mock private DOMRpcService mockRpcService;
-    @Mock private DOMNotificationService mockNotificationService;
-    @Mock DOMTransactionChain mockTransactionChain;
-    @Mock private ListenerRegistration<SchemaContextListener> mockRegistration;
-    @Mock
-    private DOMSchemaService domSchemaService;
-
-    @Rule
-    public ExpectedException thrown = ExpectedException.none();
-
-    @Before
-    public void init() {
-        MockitoAnnotations.initMocks(this);
-
-        doReturn(mockTransactionChain).when(mockDataBroker).createTransactionChain(Mockito.any());
-        doReturn(mockRegistration).when(domSchemaService).registerSchemaContextListener(
-                Mockito.any(SchemaContextHandler.class));
-
-        this.connectorProvider = new RestConnectorProvider(mockDataBroker, domSchemaService, mockRpcService,
-                mockNotificationService, mockMountPointService, ServicesWrapperImpl.getInstance());
-    }
-
-    /**
-     * Test for successful start when all conditions are satisfied.
-     */
-    @Test
-    public void successfulStartTest() {
-        // test
-        this.connectorProvider.start();
-
-        // verify interactions
-        verify(mockDataBroker).createTransactionChain(Mockito.any());
-        verify(domSchemaService).registerSchemaContextListener(Mockito.any(SchemaContextHandler.class));
-    }
-
-    /**
-     * Test of closing <code>null</code> registration.
-     */
-    @Test
-    public void closeNotOpenTest() throws Exception {
-        this.connectorProvider.close();
-    }
-
-    /**
-     * Test of creating and closing not <code>null</code> registration.
-     */
-    @Test
-    public void closeOpenTest() throws Exception {
-        // start
-        this.connectorProvider.start();
-
-        // close
-        this.connectorProvider.close();
-
-        // verify interaction
-        verify(this.mockRegistration).close();
-        verify(mockTransactionChain).close();
-    }
-}
index ab7ad9bf87acdff984bf85995e8e00e461ef86bc..be8b993ae3a107068f3913dc4a4b34310a714657 100644 (file)
@@ -8,8 +8,12 @@
 package org.opendaylight.restconf.nb.rfc8040;
 
 import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
 
 import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.Futures;
 import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -35,6 +39,13 @@ import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+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.yangtools.util.xml.UntrustedXML;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.Revision;
@@ -263,4 +274,18 @@ public final class TestUtils {
 
         return mapEntryNode.build();
     }
+
+    public static SchemaContextHandler newSchemaContextHandler(SchemaContext schemaContext) {
+        DOMDataBroker mockDataBroker = mock(DOMDataBroker.class);
+        DOMTransactionChain mockChain = mock(DOMTransactionChain.class);
+        DOMDataWriteTransaction mockTx = mock(DOMDataWriteTransaction.class);
+        doReturn(Futures.immediateCheckedFuture(null)).when(mockTx).submit();
+        doReturn(mockTx).when(mockChain).newWriteOnlyTransaction();
+
+        doReturn(mockChain).when(mockDataBroker).createTransactionChain(any());
+        SchemaContextHandler schemaContextHandler = SchemaContextHandler.newInstance(
+                new TransactionChainHandler(mockDataBroker), Mockito.mock(DOMSchemaService.class));
+        schemaContextHandler.onGlobalContextUpdated(schemaContext);
+        return schemaContextHandler;
+    }
 }
index ef4c63b985053c1123c290b761b72e8eb7194b38..8ea9b45275659b45c14407c8e9d291ed1e1c7fc6 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040.handlers;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
 
 import com.google.common.util.concurrent.CheckedFuture;
 import org.junit.Before;
@@ -19,7 +18,9 @@ import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
@@ -33,6 +34,7 @@ public class SchemaContextHandlerTest {
 
     private SchemaContextHandler schemaContextHandler;
     private SchemaContext schemaContext;
+    private final DOMSchemaService mockDOMSchemaService = Mockito.mock(DOMSchemaService.class);
 
     @Before
     public void setup() throws Exception {
@@ -44,7 +46,9 @@ public class SchemaContextHandlerTest {
         final CheckedFuture<Void,TransactionCommitFailedException> checked = Mockito.mock(CheckedFuture.class);
         Mockito.when(wTx.submit()).thenReturn(checked);
         Mockito.when(checked.checkedGet()).thenReturn(null);
-        this.schemaContextHandler = new SchemaContextHandler(txHandler);
+
+
+        this.schemaContextHandler = SchemaContextHandler.newInstance(txHandler, mockDOMSchemaService);
 
         this.schemaContext =
                 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles(PATH_FOR_ACTUAL_SCHEMA_CONTEXT));
@@ -52,11 +56,21 @@ public class SchemaContextHandlerTest {
     }
 
     /**
-     * Testing init of {@link SchemaContextHandler}.
+     * Testing init and close.
      */
     @Test
-    public void schemaContextHandlerImplInitTest() {
-        assertNotNull("Handler should be created and not null", this.schemaContextHandler);
+    public void testInitAndClose() {
+        ListenerRegistration<?> mockListenerReg = Mockito.mock(ListenerRegistration.class);
+        Mockito.doReturn(mockListenerReg).when(mockDOMSchemaService)
+            .registerSchemaContextListener(schemaContextHandler);
+
+        schemaContextHandler.init();
+
+        Mockito.verify(mockDOMSchemaService).registerSchemaContextListener(schemaContextHandler);
+
+        schemaContextHandler.close();
+
+        Mockito.verify(mockListenerReg).close();
     }
 
     /**
index 6290961e1ddf73b792c4c7cd054bf8760ca50553..578bcd7e8c23bdf10e7fa6841e5580430deb907b 100644 (file)
@@ -11,11 +11,7 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.io.File;
 import java.io.InputStream;
 import java.net.URI;
@@ -25,12 +21,10 @@ import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -54,7 +48,8 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
         URI.create("instance:identifier:module"), Revision.of("2014-01-17"));
 
     public XmlBodyReaderMountPointTest() throws Exception {
-        this.xmlBodyReader = new XmlNormalizedNodeBodyReader();
+        super(schemaContext);
+        this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler);
     }
 
     @Override
@@ -67,14 +62,6 @@ public class XmlBodyReaderMountPointTest extends AbstractBodyReaderTest {
         final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
         testFiles.addAll(TestRestconfUtils.loadFiles("/invoke-rpc"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-
-        final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
-        final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-
-        when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mountPointService);
-        when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
-        when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
-        SchemaContextHandler.setSchemaContext(schemaContext);
     }
 
     @Test
index fa0d482fde4f6bfae5036127bb42198c5da12a6c..4730d31c83ba68c5d254312e0699f7d3af2ca276 100644 (file)
@@ -11,23 +11,15 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
@@ -37,7 +29,8 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
     private final JsonToPatchBodyReader jsonToPatchBodyReader;
 
     public JsonPatchBodyReaderMountPointTest() throws Exception {
-        jsonToPatchBodyReader = new JsonToPatchBodyReader();
+        super(schemaContext);
+        jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
     }
 
     @Override
@@ -48,14 +41,6 @@ public class JsonPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-
-        final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
-        final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-
-        when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mountPointService);
-        when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
-        when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
-        SchemaContextHandler.setSchemaContext(schemaContext);
     }
 
     @Test
index e5824c9217cffdf98267b068a4a25a1bbdb03079..f84917da6f40ddc76ef01ed7b96910fe38a707f9 100644 (file)
@@ -11,17 +11,13 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -32,7 +28,8 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
     private static SchemaContext schemaContext;
 
     public JsonPatchBodyReaderTest() throws Exception {
-        jsonToPatchBodyReader = new JsonToPatchBodyReader();
+        super(schemaContext);
+        jsonToPatchBodyReader = new JsonToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
     }
 
     @Override
@@ -43,8 +40,6 @@ public class JsonPatchBodyReaderTest extends AbstractBodyReaderTest {
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-        when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
-        SchemaContextHandler.setSchemaContext(schemaContext);
     }
 
     @Test
index 00c200ea273a93ab8cfea3bcbfb207396ee743dd..cfe49159387518906164f31510efc9570999bb3b 100644 (file)
@@ -10,23 +10,15 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
-import com.google.common.base.Optional;
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
@@ -36,7 +28,8 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
     private static final String MOUNT_POINT = "instance-identifier-module:cont/yang-ext:mount/";
 
     public XmlPatchBodyReaderMountPointTest() throws Exception {
-        xmlToPatchBodyReader = new XmlToPatchBodyReader();
+        super(schemaContext);
+        xmlToPatchBodyReader = new XmlToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
     }
 
     @Override
@@ -47,14 +40,6 @@ public class XmlPatchBodyReaderMountPointTest extends AbstractBodyReaderTest {
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-
-        final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
-        final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
-
-        when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mountPointService);
-        when(mountPointService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountPoint));
-        when(mountPoint.getSchemaContext()).thenReturn(schemaContext);
-        SchemaContextHandler.setSchemaContext(schemaContext);
     }
 
     @Test
index aee4a976639234f7cc10aa3a08554330bb069291..2733f9001ab61eae860aeacf1318e62ecf703d2f 100644 (file)
@@ -10,17 +10,13 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import java.io.InputStream;
 import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.XmlBodyReaderTest;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -31,7 +27,8 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
     private static SchemaContext schemaContext;
 
     public XmlPatchBodyReaderTest() throws Exception {
-        xmlToPatchBodyReader = new XmlToPatchBodyReader();
+        super(schemaContext);
+        xmlToPatchBodyReader = new XmlToPatchBodyReader(schemaContextHandler, mountPointServiceHandler);
     }
 
     @Override
@@ -42,8 +39,6 @@ public class XmlPatchBodyReaderTest extends AbstractBodyReaderTest {
     @BeforeClass
     public static void initialization() {
         schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
-        when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
-        SchemaContextHandler.setSchemaContext(schemaContext);
     }
 
     @Test
index 990340edaeec69bb9178174615cbfd717dffe066..5f876d67068545104b2b57462cdb5acc4502f06a 100644 (file)
@@ -9,39 +9,48 @@
 package org.opendaylight.restconf.nb.rfc8040.jersey.providers.test;
 
 import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.lang.reflect.Field;
+import com.google.common.base.Optional;
 import java.util.Collections;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public abstract class AbstractBodyReaderTest {
 
-    protected static final DOMMountPointServiceHandler MOUNT_POINT_SERVICE_HANDLER =
-            mock(DOMMountPointServiceHandler.class);
-
     protected final MediaType mediaType;
+    protected final SchemaContextHandler schemaContextHandler;
+    protected final DOMMountPointServiceHandler mountPointServiceHandler;
 
-    protected AbstractBodyReaderTest() throws NoSuchFieldException, IllegalAccessException {
+    protected AbstractBodyReaderTest(SchemaContext schemaContext) throws NoSuchFieldException, IllegalAccessException {
         mediaType = getMediaType();
 
-        final Field mountPointServiceHandlerField =
-                RestConnectorProvider.class.getDeclaredField("mountPointServiceHandler");
-        mountPointServiceHandlerField.setAccessible(true);
-        mountPointServiceHandlerField.set(RestConnectorProvider.class, MOUNT_POINT_SERVICE_HANDLER);
+        schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
+
+        final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
+        final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
+        doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
+        doReturn(schemaContext).when(mountPoint).getSchemaContext();
+
+        mountPointServiceHandler = DOMMountPointServiceHandler.newInstance(mountPointService);
     }
 
     protected abstract MediaType getMediaType();
index 41283b63f89677cfe21d784e4977dccd45962fb6..1c3050e33e09cd113030ab0cde2210570c9de643 100644 (file)
@@ -10,8 +10,6 @@ package org.opendaylight.restconf.nb.rfc8040.jersey.providers.test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import com.google.common.collect.Sets;
 import java.io.File;
@@ -22,10 +20,8 @@ import java.util.Collection;
 import javax.ws.rs.core.MediaType;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.JsonNormalizedNodeBodyReader;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -49,7 +45,8 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
         URI.create("instance:identifier:module"), Revision.of("2014-01-17"));
 
     public JsonBodyReaderTest() throws Exception {
-        this.jsonBodyReader = new JsonNormalizedNodeBodyReader();
+        super(schemaContext);
+        this.jsonBodyReader = new JsonNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler);
     }
 
     @Override
@@ -63,8 +60,6 @@ public class JsonBodyReaderTest extends AbstractBodyReaderTest {
         final Collection<File> testFiles = TestRestconfUtils.loadFiles("/instanceidentifier/yang");
         testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-        when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
-        SchemaContextHandler.setSchemaContext(schemaContext);
     }
 
     @Test
index d3529d0ab07f6bf233e5a47718eb61ed553fd3a1..7f8d621cf921926c77cb5bf735022440cf353448 100644 (file)
@@ -12,8 +12,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import com.google.common.collect.Sets;
 import java.io.File;
@@ -24,12 +22,10 @@ import javax.ws.rs.core.MediaType;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.XmlNormalizedNodeBodyReader;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -53,7 +49,8 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
         URI.create("instance:identifier:module"), Revision.of("2014-01-17"));
 
     public XmlBodyReaderTest() throws Exception {
-        this.xmlBodyReader = new XmlNormalizedNodeBodyReader();
+        super(schemaContext);
+        this.xmlBodyReader = new XmlNormalizedNodeBodyReader(schemaContextHandler, mountPointServiceHandler);
     }
 
     @Override
@@ -67,8 +64,6 @@ public class XmlBodyReaderTest extends AbstractBodyReaderTest {
         testFiles.addAll(TestRestconfUtils.loadFiles("/modules"));
         testFiles.addAll(TestRestconfUtils.loadFiles("/foo-xml-test/yang"));
         schemaContext = YangParserTestUtils.parseYangFiles(testFiles);
-        when(MOUNT_POINT_SERVICE_HANDLER.get()).thenReturn(mock(DOMMountPointService.class));
-        SchemaContextHandler.setSchemaContext(schemaContext);
     }
 
     @Test
index 016abcee7f7b1ed648393c3c05455394ee924bcf..bad0decc33afc2f0047fa8308901a705e7fb5dd0 100644 (file)
@@ -51,7 +51,6 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.controller.md.sal.dom.spi.DefaultDOMRpcResult;
 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
@@ -59,7 +58,7 @@ import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
 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.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
 import org.opendaylight.yangtools.yang.common.OperationFailedException;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
@@ -128,9 +127,6 @@ public class JSONRestconfServiceRfc8040ImplTest {
     @Mock
     private DOMMountPointService mockMountPointService;
 
-    @Mock
-    private SchemaContextHandler mockSchemaContextHandler;
-
     @Mock
     private DOMDataBroker mockDOMDataBroker;
 
@@ -142,10 +138,11 @@ public class JSONRestconfServiceRfc8040ImplTest {
 
     private JSONRestconfServiceRfc8040Impl service;
 
+    private final SchemaContextHandler schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
+
     @BeforeClass
     public static void init() throws IOException, ReactorException {
         schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
-        SchemaContextHandler.setSchemaContext(schemaContext);
     }
 
     @SuppressWarnings("resource")
@@ -177,25 +174,19 @@ public class JSONRestconfServiceRfc8040ImplTest {
 
         doReturn(mockTxChain).when(mockDOMDataBroker).createTransactionChain(any());
 
-        doReturn(schemaContext).when(mockSchemaContextHandler).get();
-
-        final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockTxChain);
+        final TransactionChainHandler txChainHandler = new TransactionChainHandler(mockDOMDataBroker);
 
         final DOMMountPointServiceHandler mountPointServiceHandler =
-                new DOMMountPointServiceHandler(mockMountPointService);
+                DOMMountPointServiceHandler.newInstance(mockMountPointService);
 
         final DOMNotificationService mockNotificationService = mock(DOMNotificationService.class);
-        ServicesWrapperImpl.getInstance().setHandlers(mockSchemaContextHandler, mountPointServiceHandler,
-                txChainHandler, new DOMDataBrokerHandler(mockDOMDataBroker),
-                new RpcServiceHandler(mockRpcService),
-                new NotificationServiceHandler(mockNotificationService), domSchemaService);
-
-        service = new JSONRestconfServiceRfc8040Impl(ServicesWrapperImpl.getInstance(), mountPointServiceHandler);
-
-        new RestConnectorProvider<>(mockDOMDataBroker, domSchemaService, mockRpcService, mockNotificationService,
-                mockMountPointService).start();
+        final ServicesWrapper servicesWrapper = ServicesWrapper.newInstance(schemaContextHandler,
+                mountPointServiceHandler, txChainHandler, new DOMDataBrokerHandler(mockDOMDataBroker),
+                new RpcServiceHandler(mockRpcService), new NotificationServiceHandler(mockNotificationService),
+                domSchemaService);
 
-        SchemaContextHandler.setSchemaContext(schemaContext);
+        service = new JSONRestconfServiceRfc8040Impl(servicesWrapper, mountPointServiceHandler,
+                schemaContextHandler);
     }
 
     private static String loadData(final String path) throws IOException {
index acde252103c406d2f08a8065078439921093048a..e6046caee54baa30c97ab52634a6e3ca06b1ed53 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;
@@ -49,13 +45,13 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 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.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 +88,8 @@ public class RestconfDataServiceImplTest {
     private ContainerNode buildPlayerCont;
     private ContainerNode buildLibraryCont;
     private MapNode buildPlaylistList;
-
-    @Mock
     private TransactionChainHandler transactionChainHandler;
+
     @Mock
     private DOMTransactionChain domTransactionChain;
     @Mock
@@ -106,15 +101,13 @@ public class RestconfDataServiceImplTest {
     @Mock
     private DOMDataWriteTransaction write;
     @Mock
-    private DOMMountPointServiceHandler mountPointServiceHandler;
-    @Mock
     private DOMMountPointService mountPointService;
     @Mock
     private DOMMountPoint mountPoint;
     @Mock
     private DOMDataBroker mountDataBroker;
     @Mock
-    private DOMTransactionChain transactionChain;
+    private DOMTransactionChain mountTransactionChain;
     @Mock
     private RestconfStreamsSubscriptionService delegRestconfSubscrService;
 
@@ -178,32 +171,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 = SchemaContextHandler.newInstance(transactionChainHandler,
+                Mockito.mock(DOMSchemaService.class));
 
         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();
+                DOMMountPointServiceHandler.newInstance(mountPointService), this.delegRestconfSubscrService);
         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 +318,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 +325,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 +336,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 +379,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 +388,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 +401,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 +426,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 +454,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 +468,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 +483,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 +491,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 87998c82aa2bb8db233090e01c9d775242183c93..f8ab905c799167ef32ae7f05a5d795bfe16f92a7 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMRpcException;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 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.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
@@ -61,7 +62,8 @@ public class RestconfInvokeOperationsServiceImplTest {
         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);
+        final SchemaContextHandler schemaContextHandler =
+                SchemaContextHandler.newInstance(txHandler, Mockito.mock(DOMSchemaService.class));
         schemaContextHandler.onGlobalContextUpdated(contextRef.get());
         this.invokeOperationsService =
                 new RestconfInvokeOperationsServiceImpl(this.rpcServiceHandler, schemaContextHandler);
index bda60dd71de79ba8079e15971582182b5d91f86e..b7d476fa075baa28298beb86238fe4360dc7c123 100644 (file)
@@ -42,6 +42,7 @@ import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.util.SimpleUriInfo;
@@ -70,9 +71,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     private UriInfo uriInfo;
     @Mock
     private NotificationServiceHandler notificationServiceHandler;
-    @Mock
-    private TransactionChainHandler transactionHandler;
 
+    private TransactionChainHandler transactionHandler;
     private SchemaContextHandler schemaHandler;
 
     @SuppressWarnings("unchecked")
@@ -80,10 +80,7 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
 
-        final TransactionChainHandler txHandler = mock(TransactionChainHandler.class);
         final DOMTransactionChain domTx = mock(DOMTransactionChain.class);
-        Mockito.when(this.transactionHandler.get()).thenReturn(domTx);
-        Mockito.when(txHandler.get()).thenReturn(domTx);
         final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class);
         Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx);
         final DOMDataReadWriteTransaction rwTx = Mockito.mock(DOMDataReadWriteTransaction.class);
@@ -96,9 +93,12 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         final CheckedFuture<Void, TransactionCommitFailedException> checked = mock(CheckedFuture.class);
         Mockito.when(wTx.submit()).thenReturn(checked);
         Mockito.when(checked.checkedGet()).thenReturn(null);
-        this.schemaHandler = new SchemaContextHandler(txHandler);
 
         final DOMDataBroker dataBroker = mock(DOMDataBroker.class);
+        doReturn(domTx).when(dataBroker).createTransactionChain(any());
+
+        transactionHandler = new TransactionChainHandler(dataBroker);
+        schemaHandler = SchemaContextHandler.newInstance(transactionHandler, Mockito.mock(DOMSchemaService.class));
 
         DOMDataTreeChangeService dataTreeChangeService = mock(DOMDataTreeChangeService.class);
         doReturn(mock(ListenerRegistration.class)).when(dataTreeChangeService)
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 dcfa41a80568166421d8b4e56779fcc6fc6ad751..bec5c7be12ec25c6f6295a294aa13807a21ade40 100644 (file)
@@ -7,18 +7,13 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.services.simple.impl;
 
-import com.google.common.util.concurrent.CheckedFuture;
 import org.junit.Assert;
 import org.junit.Test;
-import org.mockito.Mockito;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.nb.rfc8040.Rfc8040.IetfYangLibrary;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
@@ -29,18 +24,7 @@ public class RestconfImplTest {
     public void restImplTest() throws Exception {
         final SchemaContext schemaContext =
                 YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/restconf/impl"));
-
-        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);
-        schemaContextHandler.onGlobalContextUpdated(schemaContext);
-
+        final SchemaContextHandler schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
         final RestconfImpl restconfImpl = new RestconfImpl(schemaContextHandler);
         final NormalizedNodeContext libraryVersion = restconfImpl.getLibraryVersion();
         final LeafNode<?> value = (LeafNode<?>) libraryVersion.getData();
index 562a1f2bbec8d5698c1e64f7c2e63d8ff6c4dc92..70ac7888449677e76e4f9b28618b4402d0cb17f1 100644 (file)
@@ -11,23 +11,19 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.ImmutableSet;
-import com.google.common.util.concurrent.Futures;
 import java.net.URI;
 import java.util.Set;
 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.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
+import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
 import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
@@ -55,17 +51,9 @@ public class RestconfOperationsServiceTest {
     public void init() throws Exception {
         MockitoAnnotations.initMocks(this);
         this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules"));
+        this.schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
 
-        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);
-        Mockito.when(wTx.submit()).thenReturn(Futures.immediateCheckedFuture(null));
-        this.schemaContextHandler = new SchemaContextHandler(txHandler);
-        this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
-
-        this.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService);
+        this.domMountPointServiceHandler = DOMMountPointServiceHandler.newInstance(this.domMountPointService);
 
         final QNameModule module1 = QNameModule.create(URI.create("module:1"));
         final QNameModule module2 = QNameModule.create(URI.create("module:2"));
index 80b9231159cd8515c135a22db3cb2e0546b28511..d9b280212ec512e6565d4b4588e93c94a3db28ec 100644 (file)
@@ -63,8 +63,6 @@ public class RestconfSchemaServiceTest {
     @Mock
     private SchemaContextHandler mockContextHandler;
     @Mock
-    private DOMMountPointServiceHandler mockMountPointHandler;
-    @Mock
     private DOMYangTextSourceProvider sourceProvider;
 
     // schema context with modules
@@ -107,10 +105,9 @@ public class RestconfSchemaServiceTest {
         this.mountPointService = new DOMMountPointServiceImpl();
         ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
         ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPointWithNullSchemaContext);
-        when(this.mockMountPointHandler.get()).thenReturn(this.mountPointService);
 
-        this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler,
-                sourceProvider);
+        this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler,
+                DOMMountPointServiceHandler.newInstance(mountPointService), sourceProvider);
     }
 
     /**
index 1fb86d2732189dd82f755309067a2ca955f1909a..5d1d3353800486bc92546339475a8c14e533273f 100644 (file)
@@ -29,10 +29,10 @@ 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;
+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.yang.gen.v1.instance.identifier.patch.module.rev151121.PatchCont;
@@ -73,10 +73,10 @@ 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)));
-        schemaContextHandler = new SchemaContextHandler(transactionChainHandler);
-        SchemaContextHandler.setSchemaContext(sc);
+        transactionChainHandler = new TransactionChainHandler(domDataBroker);
+        schemaContextHandler = SchemaContextHandler.newInstance(transactionChainHandler,
+                Mockito.mock(DOMSchemaService.class));
+        schemaContextHandler.onGlobalContextUpdated(sc);
     }
 
     class ListenerAdapterTester extends ListenerAdapter {