Bug 5528 - Handlers 63/39463/27
authorJakub Toth <jatoth@cisco.com>
Thu, 26 May 2016 08:25:57 +0000 (10:25 +0200)
committerJakub Toth <jatoth@cisco.com>
Tue, 28 Jun 2016 12:23:13 +0000 (12:23 +0000)
  *make handlers immutable
    *DOMMountPointServiceHandler
    *SchemaContextHandler
    *TransactionChainHandler
  *common interface for all handlers
  *fix dependencies of these changes

Change-Id: I4f3a78103036d88a5129f084bd088cd51c5b549c
Signed-off-by: Jakub Toth <jatoth@cisco.com>
17 files changed:
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/RestConnectorProvider.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/DOMMountPointServiceHandler.java [moved from restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/handlers/impl/DOMMountPointServiceHandlerImpl.java with 50% similarity]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/Handler.java [new file with mode: 0644]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/SchemaContextHandler.java [moved from restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/common/handlers/impl/SchemaContextHandlerImpl.java with 73% similarity]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/SchemaContextListenerHandler.java [moved from restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/common/handlers/api/SchemaContextHandler.java with 56% similarity]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/TransactionChainHandler.java [new file with mode: 0644]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/handlers/api/DOMMountPointServiceHandler.java [deleted file]
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/impl/Draft11ServicesWrapperImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/impl/RestconfModulesServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/impl/RestconfOperationsServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/impl/RestconfSchemaServiceImpl.java
restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/services/impl/RestconfStreamsServiceImpl.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/rest/RestConnectorProviderTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/rest/impl/schema/context/SchemaContextHandlerTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/rest/impl/services/RestconfSchemaServiceTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/rest/impl/services/RestconfStreamsServiceTest.java
restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/utils/validation/RestconfValidationTest.java

index ce6b2d2ecb5cf9155b0bf628ed8566127992ed5b..9ed9fbff8cb68492d3debb81622164094ff71139 100644 (file)
@@ -10,18 +10,25 @@ package org.opendaylight.restconf;
 import com.google.common.base.Preconditions;
 import java.util.Collection;
 import java.util.Collections;
+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.DOMTransactionChain;
 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
 import org.opendaylight.controller.sal.core.api.Provider;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.netconf.sal.rest.api.RestConnector;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.common.handlers.impl.SchemaContextHandlerImpl;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.rest.handlers.impl.DOMMountPointServiceHandlerImpl;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.handlers.TransactionChainHandler;
 import org.opendaylight.restconf.rest.services.impl.Draft11ServicesWrapperImpl;
 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 draft11.
@@ -29,20 +36,60 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
  */
 public class RestConnectorProvider implements Provider, RestConnector, AutoCloseable {
 
+    private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
+
+    private final TransactionChainListener transactionListener = new TransactionChainListener() {
+        @Override
+        public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
+                final AsyncTransaction<?, ?> transaction, final Throwable cause) {
+            LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
+            chain.close();
+            resetTransactionChainForAdapaters(chain);
+            throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
+        }
+
+        @Override
+        public void onTransactionChainSuccessful(final TransactionChain<?, ?> chain) {
+            LOG.trace("TransactionChain({}) {} SUCCESSFUL", chain);
+        }
+    };
+
     private ListenerRegistration<SchemaContextListener> listenerRegistration;
+    private DOMDataBroker dataBroker;
+    private DOMTransactionChain transactionChain;
 
     @Override
     public void onSessionInitiated(final ProviderSession session) {
         final SchemaService schemaService = Preconditions.checkNotNull(session.getService(SchemaService.class));
-        final DOMMountPointServiceHandler domMountPointServiceHandler = new DOMMountPointServiceHandlerImpl();
-        final SchemaContextHandler schemaCtxHandler = new SchemaContextHandlerImpl();
-        domMountPointServiceHandler.setDOMMountPointService(session.getService(DOMMountPointService.class));
+
         final Draft11ServicesWrapperImpl wrapperServices = Draft11ServicesWrapperImpl.getInstance();
+
+        final SchemaContextHandler schemaCtxHandler = new SchemaContextHandler();
         this.listenerRegistration = schemaService.registerSchemaContextListener(schemaCtxHandler);
 
+        final DOMMountPointServiceHandler domMountPointServiceHandler = new DOMMountPointServiceHandler(
+                session.getService(DOMMountPointService.class));
+
+        this.dataBroker = session.getService(DOMDataBroker.class);
+        this.transactionChain = this.dataBroker.createTransactionChain(this.transactionListener);
+        final TransactionChainHandler transactionChainHandler = new TransactionChainHandler(this.transactionChain);
+
         wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler);
     }
 
+    /**
+     * After {@link TransactionChain} failed, this is creating new transaction
+     * with listener.
+     *
+     * @param chain
+     *            - old {@link TransactionChain}
+     */
+    private void resetTransactionChainForAdapaters(final TransactionChain<?, ?> chain) {
+        LOG.trace("Resetting TransactionChain({}) to {}", chain, this.transactionChain);
+        this.transactionChain = Preconditions.checkNotNull(this.dataBroker)
+                .createTransactionChain(this.transactionListener);
+    }
+
     @Override
     public Collection<ProviderFunctionality> getProviderFunctionality() {
         return Collections.emptySet();
@@ -53,5 +100,8 @@ public class RestConnectorProvider implements Provider, RestConnector, AutoClose
         if (this.listenerRegistration != null) {
             this.listenerRegistration.close();
         }
+        if (this.transactionChain != null) {
+            this.transactionChain.close();
+        }
     }
 }
@@ -5,28 +5,33 @@
  * 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.rest.handlers.impl;
+package org.opendaylight.restconf.handlers;
 
+import com.google.common.base.Preconditions;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
 
 /**
  * Implementation of {@link DOMMountPointServiceHandler}
  *
  */
-public class DOMMountPointServiceHandlerImpl implements DOMMountPointServiceHandler {
+public class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
 
-    private DOMMountPointService domMountPointService;
+    private final DOMMountPointService domMountPointService;
 
-    @Override
-    public DOMMountPointService getDOMMountPointService() {
-        return this.domMountPointService;
+    /**
+     * Prepare mount point service for Restconf services
+     *
+     * @param domMountPointService
+     *            - mount point service
+     */
+    public DOMMountPointServiceHandler(final DOMMountPointService domMountPointService) {
+        Preconditions.checkNotNull(domMountPointService);
+        this.domMountPointService = domMountPointService;
     }
 
     @Override
-    public void setDOMMountPointService(final DOMMountPointService domMountPointService) {
-        this.domMountPointService = domMountPointService;
-
+    public DOMMountPointService get() {
+        return this.domMountPointService;
     }
 
 }
diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/Handler.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/Handler.java
new file mode 100644 (file)
index 0000000..69c2276
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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.handlers;
+
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+
+/**
+ * Handler for handling object prepared by provider for Restconf services
+ *
+ * @param <T>
+ *            - specific type go object for handling it
+ */
+interface Handler<T> {
+
+    /**
+     * Get prepared object
+     *
+     * @return {@link DOMTransactionChain}
+     */
+    T get();
+}
similarity index 73%
rename from restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/common/handlers/impl/SchemaContextHandlerImpl.java
rename to restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/SchemaContextHandler.java
index 01533425a0eff8f4419d0ffec23b10bb20476021..ed55429081eccc36130c355fba4a1cfa20a81829 100644 (file)
@@ -5,27 +5,28 @@
  * 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.common.handlers.impl;
+package org.opendaylight.restconf.handlers;
 
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
+import com.google.common.base.Preconditions;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
  * Implementation of {@link SchemaContextHandler}
  *
  */
-public class SchemaContextHandlerImpl implements SchemaContextHandler {
+public class SchemaContextHandler implements SchemaContextListenerHandler {
 
     private SchemaContext context;
 
     @Override
     public void onGlobalContextUpdated(final SchemaContext context) {
+        Preconditions.checkNotNull(context);
         this.context = null;
         this.context = context;
     }
 
     @Override
-    public SchemaContext getSchemaContext() {
+    public SchemaContext get() {
         return this.context;
     }
 }
similarity index 56%
rename from restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/common/handlers/api/SchemaContextHandler.java
rename to restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/SchemaContextListenerHandler.java
index db45a78c585c1223f1c14616c77c9d73fdbdb13c..fa41c9820435f125164ccdb427083a9494e5f007 100644 (file)
@@ -5,24 +5,11 @@
  * 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.common.handlers.api;
+package org.opendaylight.restconf.handlers;
 
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 
-/**
- * Handling schema context:
- * <ul>
- * <li>Retention
- * <li>Update
- * </ul>
- */
-public interface SchemaContextHandler extends SchemaContextListener {
+interface SchemaContextListenerHandler extends Handler<SchemaContext>, SchemaContextListener {
 
-    /**
-     * Get the {@link SchemaContext}.
-     *
-     * @return {@link SchemaContext}
-     */
-    SchemaContext getSchemaContext();
 }
diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/TransactionChainHandler.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/handlers/TransactionChainHandler.java
new file mode 100644 (file)
index 0000000..450a8ed
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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.handlers;
+
+import com.google.common.base.Preconditions;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+
+
+/**
+ * Implementation of {@link TransactionChainHandler}
+ *
+ */
+public class TransactionChainHandler implements Handler<DOMTransactionChain> {
+
+    private final DOMTransactionChain transactionChain;
+
+    /**
+     * Prepare transaction chain service for Restconf services
+     *
+     * @param transactionChain
+     */
+    public TransactionChainHandler(final DOMTransactionChain transactionChain) {
+        Preconditions.checkNotNull(transactionChain);
+        this.transactionChain = transactionChain;
+    }
+
+    @Override
+    public DOMTransactionChain get() {
+        return this.transactionChain;
+    }
+}
diff --git a/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/handlers/api/DOMMountPointServiceHandler.java b/restconf/sal-rest-connector/src/main/java/org/opendaylight/restconf/rest/handlers/api/DOMMountPointServiceHandler.java
deleted file mode 100644 (file)
index b332fd1..0000000
+++ /dev/null
@@ -1,35 +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.rest.handlers.api;
-
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-
-/**
- * Handling dom mount point service:
- * <ul>
- * <li>Retention
- * <li>Set
- * </ul>
- */
-public interface DOMMountPointServiceHandler {
-
-    /**
-     * Get the {@link DOMMountPointService}
-     *
-     * @return {@link DOMMountPointService}
-     */
-    DOMMountPointService getDOMMountPointService();
-
-    /**
-     * Set {@link DOMMountPointService}
-     *
-     * @param domMountPointService
-     *            - {@link DOMMountPointService}
-     */
-    void setDOMMountPointService(DOMMountPointService domMountPointService);
-}
index dba808b66aac526dd80fd8420329f70a7ac671ed..39acd298bc04433bd9f5e47c0178d8fbecd61843 100644 (file)
@@ -10,8 +10,8 @@ package org.opendaylight.restconf.rest.services.impl;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.rest.services.api.Draft11ServicesWrapper;
 import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
 import org.opendaylight.restconf.rest.services.api.RestconfOperationsService;
index c5261958533b1ae7e2e54a1ceceab5996d665cff..afefd6d45722b1bc80f855e53ee360c6a40a770a 100644 (file)
@@ -19,9 +19,9 @@ import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.restconf.Draft11;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
 import org.opendaylight.restconf.common.references.SchemaContextRef;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
 import org.opendaylight.restconf.utils.RestconfConstants;
 import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeUtil;
@@ -66,7 +66,7 @@ public class RestconfModulesServiceImpl implements RestconfModulesService {
 
     @Override
     public NormalizedNodeContext getModules(final UriInfo uriInfo) {
-        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
         return getModules(schemaContextRef.getModules(), schemaContextRef, null);
     }
 
@@ -79,10 +79,10 @@ public class RestconfModulesServiceImpl implements RestconfModulesService {
             LOG.debug(errMsg + " for " + identifier);
             throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
         }
-        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
         final InstanceIdentifierContext<?> mountPointIdentifier = ParserIdentifier.toInstanceIdentifier(identifier,
                 schemaContextRef.get());
-        final DOMMountPointService domMointPointService = this.domMountPointServiceHandler.getDOMMountPointService();
+        final DOMMountPointService domMointPointService = this.domMountPointServiceHandler.get();
         final DOMMountPoint mountPoint = domMointPointService
                 .getMountPoint(mountPointIdentifier.getInstanceIdentifier()).get();
         return getModules(mountPoint.getSchemaContext().getModules(), schemaContextRef, mountPoint);
@@ -92,15 +92,14 @@ public class RestconfModulesServiceImpl implements RestconfModulesService {
     @Override
     public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
         Preconditions.checkNotNull(identifier);
-        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
         final QName moduleQname = ParserIdentifier.makeQNameFromIdentifier(identifier);
         Module module = null;
         DOMMountPoint mountPoint = null;
         if (identifier.contains(RestconfConstants.MOUNT)) {
             final InstanceIdentifierContext<?> point = ParserIdentifier.toInstanceIdentifier(identifier,
                     schemaContextRef.get());
-            final DOMMountPointService domMointPointService = this.domMountPointServiceHandler
-                    .getDOMMountPointService();
+            final DOMMountPointService domMointPointService = this.domMountPointServiceHandler.get();
             mountPoint = domMointPointService.getMountPoint(point.getInstanceIdentifier()).get();
             module = schemaContextRef.findModuleInMountPointByQName(mountPoint, moduleQname);
         } else {
index f269e9a0cb246855046bae0936e420541af679b0..fec4c3f659390d694a8f92c7505bca4b6199c514 100644 (file)
@@ -10,8 +10,8 @@ package org.opendaylight.restconf.rest.services.impl;
 import javax.ws.rs.core.UriInfo;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.rest.services.api.RestconfOperationsService;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
index f5682d7b777e3266b2d5a278fce587825fd11c75..6313244561dbb86710ecba6c603b7913388096b0 100644 (file)
@@ -8,9 +8,9 @@
 package org.opendaylight.restconf.rest.services.impl;
 
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
 import org.opendaylight.restconf.common.references.SchemaContextRef;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.rest.services.api.RestconfSchemaService;
 import org.opendaylight.restconf.utils.parser.ParserIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -41,8 +41,8 @@ public class RestconfSchemaServiceImpl implements RestconfSchemaService {
 
     @Override
     public SchemaExportContext getSchema(final String identifier) {
-        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
         return ParserIdentifier.toSchemaExportContextFromIdentifier(schemaContextRef.get(), identifier,
-                this.domMountPointServiceHandler.getDOMMountPointService());
+                this.domMountPointServiceHandler.get());
     }
 }
index 1fb85aae8ca4972513d58a3c8aee605742bfc28b..1346e50142d14f1bf56d10223fab39041a49eaa2 100644 (file)
@@ -14,8 +14,8 @@ import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.streams.listeners.Notificator;
 import org.opendaylight.restconf.Draft11;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
 import org.opendaylight.restconf.common.references.SchemaContextRef;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.rest.services.api.RestconfStreamsService;
 import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeUtil;
 import org.opendaylight.restconf.utils.schema.context.RestconfSchemaUtil;
@@ -52,7 +52,7 @@ public class RestconfStreamsServiceImpl implements RestconfStreamsService {
 
     @Override
     public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
-        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.getSchemaContext());
+        final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
         final Set<String> availableStreams = Notificator.getStreamNames();
 
         final DataSchemaNode streamListSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
index d2ce0adefa489c170cdd06af56e44d94a6f794ed..623e2c8bd05e60cc74c61fef32befc99ed64659f 100644 (file)
@@ -19,11 +19,13 @@ 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.DOMTransactionChain;
 import org.opendaylight.controller.sal.core.api.Broker;
 import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.restconf.RestConnectorProvider;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
 
@@ -68,6 +70,10 @@ public class RestConnectorProviderTest {
         // prepare conditions
         when(this.mockSession.getService(SchemaService.class)).thenReturn(this.mockSchemaService);
         when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(this.mockMountPointService);
+        final DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+        when(this.mockSession.getService(DOMDataBroker.class)).thenReturn(mockDataBroker);
+        final DOMTransactionChain mockTransactionChain = Mockito.mock(DOMTransactionChain.class);
+        when(mockDataBroker.createTransactionChain(Mockito.any())).thenReturn(mockTransactionChain);
 
         // test
         this.connectorProvider.onSessionInitiated(this.mockSession);
@@ -90,6 +96,12 @@ public class RestConnectorProviderTest {
         // prepare conditions
         when(this.mockSession.getService(SchemaService.class)).thenReturn(this.mockSchemaService);
         when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(null);
+        final DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+        when(this.mockSession.getService(DOMDataBroker.class)).thenReturn(mockDataBroker);
+        final DOMTransactionChain mockTransactionChain = Mockito.mock(DOMTransactionChain.class);
+        when(mockDataBroker.createTransactionChain(Mockito.any())).thenReturn(mockTransactionChain);
+        final DOMMountPointService mockDomMountPoint = Mockito.mock(DOMMountPointService.class);
+        when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(mockDomMountPoint);
 
         // test
         this.connectorProvider.onSessionInitiated(this.mockSession);
@@ -146,6 +158,10 @@ public class RestConnectorProviderTest {
         when(this.mockSession.getService(DOMMountPointService.class)).thenReturn(this.mockMountPointService);
         when(this.mockSchemaService.registerSchemaContextListener(Mockito.any(SchemaContextHandler.class)))
                 .thenReturn(this.mockRegistration);
+        final DOMDataBroker mockDataBroker = Mockito.mock(DOMDataBroker.class);
+        when(this.mockSession.getService(DOMDataBroker.class)).thenReturn(mockDataBroker);
+        final DOMTransactionChain mockTransactionChain = Mockito.mock(DOMTransactionChain.class);
+        when(mockDataBroker.createTransactionChain(Mockito.any())).thenReturn(mockTransactionChain);
 
         // register
         this.connectorProvider.onSessionInitiated(this.mockSession);
index 78d84abd8e0bf356bc2e4e75ac250f664dd037aa..6107d67d1ef5d6a5251e792098810ef94509e284 100644 (file)
@@ -13,8 +13,7 @@ import static org.junit.Assert.assertNotNull;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.common.handlers.impl.SchemaContextHandlerImpl;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 /**
@@ -30,14 +29,14 @@ public class SchemaContextHandlerTest {
 
     @Before
     public void setup() throws Exception {
-        this.schemaContextHandler = new SchemaContextHandlerImpl();
+        this.schemaContextHandler = new SchemaContextHandler();
 
         this.schemaContext = TestRestconfUtils.loadSchemaContext(PATH_FOR_ACTUAL_SCHEMA_CONTEXT);
         this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
     }
 
     /**
-     * Testing init of {@link SchemaContextHandlerImpl}
+     * Testing init of {@link SchemaContextHandler}
      */
     @Test
     public void schemaContextHandlerImplInitTest() {
@@ -53,7 +52,7 @@ public class SchemaContextHandlerTest {
     @Test
     public void getSchemaContextTest() {
         assertEquals("SchemaContextHandler should has reference to actual SchemaContext",
-                this.schemaContext, this.schemaContextHandler.getSchemaContext());
+                this.schemaContext, this.schemaContextHandler.get());
     }
 
     /**
@@ -69,8 +68,8 @@ public class SchemaContextHandlerTest {
         this.schemaContextHandler.onGlobalContextUpdated(newSchemaContext);
 
         assertNotEquals("SchemaContextHandler should not has reference to old SchemaContext",
-                this.schemaContext, this.schemaContextHandler.getSchemaContext());
+                this.schemaContext, this.schemaContextHandler.get());
         assertEquals("SchemaContextHandler should has reference to new SchemaContext",
-                newSchemaContext, this.schemaContextHandler.getSchemaContext());
+                newSchemaContext, this.schemaContextHandler.get());
     }
 }
index 2ffb5a0ff41bb716959f7bebe5c712d6baeb67f4..712e89f83ae9e830a8a0656ad10e7f494ec87ec8 100644 (file)
@@ -29,8 +29,8 @@ import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
-import org.opendaylight.restconf.rest.handlers.api.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.rest.services.api.RestconfSchemaService;
 import org.opendaylight.restconf.rest.services.impl.RestconfSchemaServiceImpl;
 import org.opendaylight.restconf.utils.RestconfConstants;
@@ -99,7 +99,7 @@ public class RestconfSchemaServiceTest {
         this.mountPointService = new DOMMountPointServiceImpl();
         ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
         ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPointWithNullSchemaContext);
-        when(this.mockMountPointHandler.getDOMMountPointService()).thenReturn(this.mountPointService);
+        when(this.mockMountPointHandler.get()).thenReturn(this.mountPointService);
 
         this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler);
     }
@@ -118,7 +118,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaTest() {
         // prepare conditions - return not-mount point schema context
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
 
         // make test
         final SchemaExportContext exportContext = this.schemaService.getSchema(TEST_MODULE);
@@ -142,7 +142,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaForNotExistingModuleTest() {
         // prepare conditions - return not-mount point schema context
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
 
         // make test
         final SchemaExportContext exportContext = this.schemaService.getSchema(NOT_EXISTING_MODULE);
@@ -158,7 +158,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaMountPointTest() {
         // prepare conditions - return schema context with mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
 
         // make test
         final SchemaExportContext exportContext = this.schemaService.getSchema(MOUNT_POINT + TEST_MODULE_BEHIND_MOUNT_POINT);
@@ -182,7 +182,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaForNotExistingModuleMountPointTest() {
         // prepare conditions - return schema context with mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
 
         // make test
         final SchemaExportContext exportContext = this.schemaService.getSchema(MOUNT_POINT + NOT_EXISTING_MODULE);
@@ -198,7 +198,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWithNullSchemaContextTest() {
         // prepare conditions - returned schema context is null
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(null);
+        when(this.mockContextHandler.get()).thenReturn(null);
 
         // make test
         this.thrown.expect(NullPointerException.class);
@@ -212,7 +212,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWithNullSchemaContextMountPointTest() {
         // prepare conditions - returned schema context for mount points is null
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(null);
+        when(this.mockContextHandler.get()).thenReturn(null);
 
         // make test
         this.thrown.expect(NullPointerException.class);
@@ -226,7 +226,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaNullSchemaContextBehindMountPointTest() {
         // prepare conditions - return correct schema context for mount points (this is not null)
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
 
         // make test - call service on mount point with null schema context
         this.thrown.expect(NullPointerException.class);
@@ -241,7 +241,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWithNullIdentifierTest() {
         // prepare conditions - return correct schema context
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
 
         // make test
         this.thrown.expect(NullPointerException.class);
@@ -255,7 +255,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWithEmptyIdentifierTest() {
         // prepare conditions - return correct schema context
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
 
         // make test and verify
         try {
@@ -276,7 +276,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWithEmptyIdentifierMountPointTest() {
         // prepare conditions - return correct schema context with mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
 
         // make test and verify
         try {
@@ -296,7 +296,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWithNotParsableIdentifierTest() {
         // prepare conditions - return correct schema context without mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
 
         // make test and verify
         try {
@@ -317,7 +317,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWithNotParsableIdentifierMountPointTest() {
         // prepare conditions - return correct schema context with mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
 
         // make test and verify
         try {
@@ -339,7 +339,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWrongIdentifierTest() {
         // prepare conditions - return correct schema context without mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
 
         // make test and verify
         try {
@@ -362,7 +362,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWrongIdentifierMountPointTest() {
         // prepare conditions - return correct schema context with mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
 
         // make test and verify
         try {
@@ -383,7 +383,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWithoutRevisionTest() {
         // prepare conditions - return correct schema context without mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContext);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContext);
 
         // make test and verify
         try {
@@ -404,7 +404,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaWithoutRevisionMountPointTest() {
         // prepare conditions - return correct schema context with mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
 
         // make test and verify
         try {
@@ -424,7 +424,7 @@ public class RestconfSchemaServiceTest {
     @Test
     public void getSchemaContextWithNotExistingMountPointTest() {
         // prepare conditions - return schema context with mount points
-        when(this.mockContextHandler.getSchemaContext()).thenReturn(this.schemaContextWithMountPoints);
+        when(this.mockContextHandler.get()).thenReturn(this.schemaContextWithMountPoints);
 
         // make test
         this.thrown.expect(IllegalArgumentException.class);
index d4754e849d615b9d0f47078d63531f4b8c82a91d..85859000d86ff95fab1acdfb544abc9567e1209f 100644 (file)
@@ -38,7 +38,7 @@ import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
 import org.opendaylight.netconf.sal.streams.listeners.Notificator;
 import org.opendaylight.restconf.Draft11;
-import org.opendaylight.restconf.common.handlers.api.SchemaContextHandler;
+import org.opendaylight.restconf.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.rest.services.api.RestconfStreamsService;
 import org.opendaylight.restconf.rest.services.impl.RestconfStreamsServiceImpl;
 import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeConstants;
@@ -108,7 +108,7 @@ public class RestconfStreamsServiceTest {
     @Test
     public void getAvailableStreamsTest() throws Exception {
         // prepare conditions - get correct Restconf module
-        when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+        when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
         when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
                 .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
                 .thenReturn(getTestingRestconfModule("ietf-restconf"));
@@ -128,7 +128,7 @@ public class RestconfStreamsServiceTest {
     @Test
     public void getAvailableStreamsNullSchemaContextNegativeTest() {
         // prepare conditions - returned SchemaContext is null
-        when(this.contextHandler.getSchemaContext()).thenReturn(null);
+        when(this.contextHandler.get()).thenReturn(null);
 
         // make test
         this.thrown.expect(NullPointerException.class);
@@ -142,7 +142,7 @@ public class RestconfStreamsServiceTest {
     @Test
     public void getAvailableStreamsMissingRestconfModuleNegativeTest() {
         // prepare conditions - get null Restconf module
-        when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+        when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
         when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
                 .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision())).thenReturn(null);
 
@@ -159,7 +159,7 @@ public class RestconfStreamsServiceTest {
     @Test
     public void getAvailableStreamsMissingListStreamNegativeTest() {
         // prepare conditions - get Restconf module with missing list stream
-        when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+        when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
         when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
                 .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
                 .thenReturn(getTestingRestconfModule("restconf-module-with-missing-list-stream"));
@@ -186,7 +186,7 @@ public class RestconfStreamsServiceTest {
     @Test
     public void getAvailableStreamsMissingContainerStreamsNegativeTest() {
         // prepare conditions - get Restconf module with missing container streams
-        when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+        when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
         when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
                 .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
                 .thenReturn(getTestingRestconfModule("restconf-module-with-missing-container-streams"));
@@ -212,7 +212,7 @@ public class RestconfStreamsServiceTest {
     @Test
     public void getAvailableStreamsIllegalListStreamNegativeTest() {
         // prepare conditions - get Restconf module with illegal list stream
-        when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+        when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
         when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
                 .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
                 .thenReturn(getTestingRestconfModule("restconf-module-with-illegal-list-stream"));
@@ -229,7 +229,7 @@ public class RestconfStreamsServiceTest {
     @Test
     public void getAvailableStreamsIllegalContainerStreamsNegativeTest() {
         // prepare conditions - get Restconf module with illegal container streams
-        when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+        when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
         when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
                 .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
                 .thenReturn(getTestingRestconfModule("restconf-module-with-illegal-container-streams"));
@@ -246,7 +246,7 @@ public class RestconfStreamsServiceTest {
     @Test
     public void getAvailableStreamsIllegalLeafDescriptionNegativeTest() {
         // prepare conditions - get Restconf module with illegal leaf description in list stream
-        when(this.contextHandler.getSchemaContext()).thenReturn(this.mockSchemaContext);
+        when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
         when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
                 .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
                 .thenReturn(getTestingRestconfModule("restconf-module-with-illegal-leaf-description"));
index d6c5dc2927aa016687dae7f16eacc3e4fbaedd57..8f8933f65f38b2d5a7508162df2d85eeeaf2433c 100644 (file)
@@ -21,6 +21,7 @@ import java.util.List;
 import org.junit.Test;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
+import org.opendaylight.restconf.utils.validation.RestconfValidation;
 
 /**
  * Unit test for {@link RestconfValidation}