Merge "introduce Rfc8040RestConfWiring for standalone (simple) environments"
authorJakub Morvay <jakub.morvay@gmail.com>
Fri, 8 Feb 2019 18:41:41 +0000 (18:41 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 8 Feb 2019 18:41:41 +0000 (18:41 +0000)
18 files changed:
restconf/restconf-nb-bierman02/pom.xml
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/incubate/InMemoryMdsalModule.java
restconf/restconf-nb-rfc8040/pom.xml
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/Rfc8040RestConfWiring.java [new file with mode: 0644]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/DOMDataBrokerHandler.java
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/NotificationServiceHandler.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/RpcServiceHandler.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/SchemaContextHandler.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/handlers/TransactionChainHandler.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/JSONRestconfServiceRfc8040Impl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/services/wrapper/ServicesWrapper.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/web/WebInitializer.java
restconf/restconf-nb-rfc8040/src/main/resources/OSGI-INF/blueprint/restconf-bp.xml
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/Rfc8040RestConfWiringTest.java [new file with mode: 0644]
restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/incubate/InMemoryMdsalModule.java [new file with mode: 0644]
restconf/restconf-parent/pom.xml

index 5a456adfb6e83471edb3599ef34f7d981262c3a9..1f997ef1ee1613ede6b7f866d25d0a8b0f11b9c6 100644 (file)
     <dependency>
       <groupId>org.opendaylight.infrautils</groupId>
       <artifactId>inject.guice.testutils</artifactId>
-      <version>1.6.0-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.infrautils</groupId>
       <artifactId>infrautils-testutils</artifactId>
-      <version>1.6.0-SNAPSHOT</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
index fba66a033964970afb38b4be92b34ebc40b082a4..18f1287a796bb2812737dc6937ba6eba0c081fee 100644 (file)
@@ -33,7 +33,8 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
  *
  * <p>This class is here only temporarily and it can and should be removed and
  * replaced when the equivalent will be offered by the mdsal project itself; see
- * <a href="https://jira.opendaylight.org/browse/MDSAL-418">MDSAL-418</a>.
+ * <a href="https://jira.opendaylight.org/browse/MDSAL-418">MDSAL-418</a>.  It is
+ * also copy/pasted to org.opendaylight.restconf.nb.rfc8040.test.incubate.InMemoryMdsalModule.
  *
  * <p>BEWARE: Do *NOT* use this module in component tests or applications mixing
  * code requiring the old controller and the new mdsal {@link DataBroker} & Co.
index babb39d16c44f8d3db8513b3a2c82174020b6b46..4ace68941336c66c8d2103280ebb94b478e294c9 100644 (file)
   <packaging>bundle</packaging>
 
   <dependencies>
+    <dependency>
+      <groupId>javax.annotation</groupId>
+      <artifactId>javax.annotation-api</artifactId>
+      <optional>true</optional>
+    </dependency>
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.aries.blueprint</groupId>
+      <artifactId>blueprint-maven-plugin-annotation</artifactId>
+      <optional>true</optional>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.netconf</groupId>
       <artifactId>restconf-common-models</artifactId>
       <artifactId>jsonassert</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.aaa.web</groupId>
+      <artifactId>testutils</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.infrautils</groupId>
+      <artifactId>inject.guice.testutils</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.infrautils</groupId>
+      <artifactId>infrautils-testutils</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.netconf</groupId>
+      <artifactId>ietf-restconf</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <build>
     <plugins>
+      <plugin>
+        <groupId>org.apache.aries.blueprint</groupId>
+        <artifactId>blueprint-maven-plugin</artifactId>
+      </plugin>
       <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-bundle-plugin</artifactId>
index 89c858788043374e911f576b6cd2f35a74ee8279..d5acb749254bbdf1f986d28a6d3826e69505fa6e 100644 (file)
@@ -10,6 +10,8 @@ package org.opendaylight.restconf.nb.rfc8040;
 import com.google.common.collect.ImmutableSet;
 import java.util.HashSet;
 import java.util.Set;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import javax.ws.rs.core.Application;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
@@ -25,11 +27,14 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExport
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.schema.SchemaExportContentYinBodyWriter;
 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
 
+@Singleton
 public class RestconfApplication extends Application {
+
     private final SchemaContextHandler schemaContextHandler;
     private final DOMMountPointServiceHandler mountPointServiceHandler;
     private final ServicesWrapper servicesWrapper;
 
+    @Inject
     public RestconfApplication(SchemaContextHandler schemaContextHandler,
             DOMMountPointServiceHandler mountPointServiceHandler, ServicesWrapper servicesWrapper) {
         this.schemaContextHandler = schemaContextHandler;
diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040RestConfWiring.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/Rfc8040RestConfWiring.java
new file mode 100644 (file)
index 0000000..d3fe406
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2019 Red Hat, 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 javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Reference;
+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;
+import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
+import org.opendaylight.restconf.nb.rfc8040.web.WebInitializer;
+
+/**
+ * Standalone wiring for RESTCONF.
+ *
+ * <p>This wiring alone is not sufficient; there are a few other singletons which
+ * need to be bound as well, incl. {@link RestconfApplication},
+ * {@link JSONRestconfServiceRfc8040Impl} &amp; {@link WebInitializer}; see the
+ * Rfc8040RestConfWiringTest for how to do this e.g. for Guice (this class can
+ * be used with another DI framework but needs the equivalent).
+ *
+ * @author Michael Vorburger.ch
+ */
+@Singleton
+public class Rfc8040RestConfWiring {
+
+    private final ServicesWrapper servicesWrapper;
+
+    @Inject
+    public Rfc8040RestConfWiring(
+            SchemaContextHandler schemaCtxHandler,
+            DOMMountPointServiceHandler domMountPointServiceHandler, TransactionChainHandler transactionChainHandler,
+            DOMDataBrokerHandler domDataBrokerHandler, RpcServiceHandler rpcServiceHandler,
+            NotificationServiceHandler notificationServiceHandler, @Reference DOMSchemaService domSchemaService) {
+        servicesWrapper = ServicesWrapper.newInstance(schemaCtxHandler, domMountPointServiceHandler,
+                transactionChainHandler, domDataBrokerHandler, rpcServiceHandler, notificationServiceHandler,
+                domSchemaService);
+    }
+
+    public ServicesWrapper getServicesWrapper() {
+        return servicesWrapper;
+    }
+}
index f53bb405139dea8c8cea6c68b057fb4572301fcf..8702c4ab3ff41d31dd99d78a6d4c4021944eaa15 100644 (file)
@@ -7,15 +7,19 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.handlers;
 
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 
 /**
  * Implementation of {@link DOMDataBrokerHandler}.
  */
+@Singleton
 public class DOMDataBrokerHandler implements Handler<DOMDataBroker> {
 
     private final DOMDataBroker broker;
 
+    @Inject
     public DOMDataBrokerHandler(final DOMDataBroker broker) {
         this.broker = broker;
     }
@@ -24,5 +28,4 @@ public class DOMDataBrokerHandler implements Handler<DOMDataBroker> {
     public DOMDataBroker get() {
         return this.broker;
     }
-
 }
index fcec775ce9549ac859a8ace11ad87127d735d0e2..501aeafa736970014476257f713d509c9b2732cc 100644 (file)
@@ -9,12 +9,16 @@ package org.opendaylight.restconf.nb.rfc8040.handlers;
 
 import static java.util.Objects.requireNonNull;
 
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 
 /**
  * Implementation of {@link DOMMountPointServiceHandler}.
  *
  */
+@Singleton
 public final class DOMMountPointServiceHandler implements Handler<DOMMountPointService> {
     private final DOMMountPointService domMountPointService;
 
@@ -24,10 +28,12 @@ public final class DOMMountPointServiceHandler implements Handler<DOMMountPointS
      * @param domMountPointService
      *             mount point service
      */
-    private DOMMountPointServiceHandler(final DOMMountPointService domMountPointService) {
+    @Inject
+    public DOMMountPointServiceHandler(final @Reference DOMMountPointService domMountPointService) {
         this.domMountPointService = requireNonNull(domMountPointService);
     }
 
+    @Deprecated
     public static DOMMountPointServiceHandler newInstance(final DOMMountPointService domMountPointService) {
         return new DOMMountPointServiceHandler(domMountPointService);
     }
index 82513d9acd16122c81a1f32cd7b3946c654fde9e..378f891404d598bb51cd40ed91fd480fce1f351c 100644 (file)
@@ -7,8 +7,12 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.handlers;
 
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
 
+@Singleton
 public class NotificationServiceHandler implements Handler<DOMNotificationService> {
 
     private final DOMNotificationService notificationService;
@@ -19,7 +23,8 @@ public class NotificationServiceHandler implements Handler<DOMNotificationServic
      * @param notificationService
      *             DOMNotificationService
      */
-    public NotificationServiceHandler(final DOMNotificationService notificationService) {
+    @Inject
+    public NotificationServiceHandler(final @Reference DOMNotificationService notificationService) {
         this.notificationService = notificationService;
     }
 
@@ -27,5 +32,4 @@ public class NotificationServiceHandler implements Handler<DOMNotificationServic
     public DOMNotificationService get() {
         return this.notificationService;
     }
-
 }
index beff503a67e8622a6ff66b5c51d36295da981976..44141f49fea9fab1486643df6d58f44aa289e184 100644 (file)
@@ -7,15 +7,20 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.handlers;
 
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.mdsal.dom.api.DOMRpcService;
 
 /**
  * Implementation of {@link RpcServiceHandler}.
  */
+@Singleton
 public class RpcServiceHandler implements Handler<DOMRpcService> {
     private final DOMRpcService rpcService;
 
-    public RpcServiceHandler(final DOMRpcService rpcService) {
+    @Inject
+    public RpcServiceHandler(final @Reference DOMRpcService rpcService) {
         this.rpcService = rpcService;
     }
 
index 86396c100dac002f9b12e6234d6e327fb680e0f4..6e12200660a7d9d2e09907e053acfb2d15a52967 100644 (file)
@@ -12,6 +12,11 @@ import com.google.common.base.Throwables;
 import java.util.Collection;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicInteger;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
@@ -35,8 +40,8 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Implementation of {@link SchemaContextHandler}.
- *
  */
+@Singleton
 @SuppressWarnings("checkstyle:FinalClass")
 public class SchemaContextHandler implements SchemaContextListenerHandler, AutoCloseable {
 
@@ -55,22 +60,26 @@ public class SchemaContextHandler implements SchemaContextListenerHandler, AutoC
      *
      * @param transactionChainHandler Transaction chain handler
      */
-    private SchemaContextHandler(final TransactionChainHandler transactionChainHandler,
-            final DOMSchemaService domSchemaService) {
+    @Inject
+    public SchemaContextHandler(final TransactionChainHandler transactionChainHandler,
+            final @Reference DOMSchemaService domSchemaService) {
         this.transactionChainHandler = transactionChainHandler;
         this.domSchemaService = domSchemaService;
     }
 
+    @Deprecated
     public static SchemaContextHandler newInstance(final TransactionChainHandler transactionChainHandler,
             final DOMSchemaService domSchemaService) {
         return new SchemaContextHandler(transactionChainHandler, domSchemaService);
     }
 
+    @PostConstruct
     public void init() {
         listenerRegistration = domSchemaService.registerSchemaContextListener(this);
     }
 
     @Override
+    @PreDestroy
     public void close() {
         if (listenerRegistration != null) {
             listenerRegistration.close();
index 7c2440bc3f4666b81f4c4bd527e076cd17cff554..0e2df38e5fce0038081d037e7d66cc606ea2d1de 100644 (file)
@@ -8,6 +8,9 @@
 package org.opendaylight.restconf.nb.rfc8040.handlers;
 
 import java.util.Objects;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeTransaction;
 import org.opendaylight.mdsal.dom.api.DOMTransactionChain;
@@ -18,8 +21,8 @@ import org.slf4j.LoggerFactory;
 
 /**
  * Implementation of {@link TransactionChainHandler}.
- *
  */
+@Singleton
 public class TransactionChainHandler implements Handler<DOMTransactionChain>, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(TransactionChainHandler.class);
 
@@ -45,6 +48,7 @@ public class TransactionChainHandler implements Handler<DOMTransactionChain>, Au
     /**
      * Prepare transaction chain service for Restconf services.
      */
+    @Inject
     public TransactionChainHandler(final DOMDataBroker dataBroker) {
         this.dataBroker = Objects.requireNonNull(dataBroker);
         transactionChain = Objects.requireNonNull(dataBroker.createTransactionChain(transactionChainListener));
@@ -62,6 +66,7 @@ public class TransactionChainHandler implements Handler<DOMTransactionChain>, Au
     }
 
     @Override
+    @PreDestroy
     public synchronized void close() {
         transactionChain.close();
     }
index 642ecabec83a1ebffb22afd1c974619a2a88fd30..b33d21971a0603c4f743ee0dcabca12a61b0a056 100644 (file)
@@ -18,6 +18,9 @@ import java.lang.annotation.Annotation;
 import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Optional;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
@@ -41,6 +44,7 @@ import org.opendaylight.restconf.nb.rfc8040.jersey.providers.patch.PatchJsonBody
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.JSONRestconfService;
 import org.opendaylight.restconf.nb.rfc8040.rests.services.api.TransactionServicesWrapper;
 import org.opendaylight.restconf.nb.rfc8040.rests.utils.RestconfDataServiceConstant;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
 import org.opendaylight.yangtools.yang.common.OperationFailedException;
 import org.opendaylight.yangtools.yang.common.RpcError;
@@ -54,6 +58,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author Thomas Pantelis
  */
+@Singleton
 public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(JSONRestconfServiceRfc8040Impl.class);
 
@@ -63,7 +68,8 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto
     private final DOMMountPointServiceHandler mountPointServiceHandler;
     private final SchemaContextHandler schemaContextHandler;
 
-    public JSONRestconfServiceRfc8040Impl(final TransactionServicesWrapper services,
+    @Inject
+    public JSONRestconfServiceRfc8040Impl(final ServicesWrapper services,
             final DOMMountPointServiceHandler mountPointServiceHandler,
             final SchemaContextHandler schemaContextHandler) {
         this.services = services;
@@ -212,6 +218,7 @@ public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, Auto
     }
 
     @Override
+    @PreDestroy
     public void close() {
     }
 
index 02e69b589f51d75a51e999693fc0b7bdcd9db8e3..aabce8a544836399691eb3817e1558ab9b840da5 100644 (file)
@@ -43,7 +43,6 @@ import org.opendaylight.restconf.nb.rfc8040.services.simple.impl.RestconfSchemaS
  * <li>{@link BaseServicesWrapper}
  * <li>{@link TransactionServicesWrapper}
  * </ul>
- *
  */
 @Path("/")
 public final class ServicesWrapper implements BaseServicesWrapper, TransactionServicesWrapper {
index d971aa0391968cccfd5bbbc39e86114127c7f8cb..e7f80a73881e0de0e5c795ce1027d5f39c09b733 100644 (file)
@@ -7,8 +7,11 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.web;
 
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Singleton;
 import javax.servlet.ServletException;
-import javax.ws.rs.core.Application;
+import org.apache.aries.blueprint.annotation.service.Reference;
 import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
 import org.opendaylight.aaa.filterchain.filters.CustomFilterAdapter;
 import org.opendaylight.aaa.web.FilterDetails;
@@ -19,17 +22,22 @@ import org.opendaylight.aaa.web.WebContextRegistration;
 import org.opendaylight.aaa.web.WebContextSecurer;
 import org.opendaylight.aaa.web.WebServer;
 import org.opendaylight.aaa.web.servlet.ServletSupport;
+import org.opendaylight.restconf.nb.rfc8040.RestconfApplication;
 
 /**
  * Initializes the rfc8040 web app endpoint.
  *
  * @author Thomas Pantelis
  */
+@Singleton
 public class WebInitializer {
+
     private final WebContextRegistration registration;
 
-    public WebInitializer(WebServer webServer,  WebContextSecurer webContextSecurer, ServletSupport servletSupport,
-            Application webApp, CustomFilterAdapterConfiguration customFilterAdapterConfig) throws ServletException {
+    @Inject
+    public WebInitializer(@Reference WebServer webServer, @Reference WebContextSecurer webContextSecurer,
+            @Reference ServletSupport servletSupport, RestconfApplication webApp,
+            @Reference CustomFilterAdapterConfiguration customFilterAdapterConfig) throws ServletException {
         WebContextBuilder webContextBuilder = WebContext.builder().contextPath("rests").supportsSessions(false)
                 .addServlet(ServletDetails.builder().servlet(servletSupport.createHttpServletBuilder(webApp).build())
                     .addUrlPattern("/*").build())
@@ -48,6 +56,7 @@ public class WebInitializer {
         registration = webServer.registerWebContext(webContextBuilder.build());
     }
 
+    @PreDestroy
     public void close() {
         if (registration != null) {
             registration.close();
index 758a0ed8e2dfdf16d77a0371e42565a4d275d2ce..b009a9ae6439a6d938ce54ebc5d73d13e9020775 100644 (file)
     </cm:default-properties>
   </cm:property-placeholder>
 
-  <reference id="domRpcService" interface="org.opendaylight.mdsal.dom.api.DOMRpcService"/>
-  <reference id="domMountPointService" interface="org.opendaylight.mdsal.dom.api.DOMMountPointService"/>
-  <reference id="domNotificationService" interface="org.opendaylight.mdsal.dom.api.DOMNotificationService"/>
-  <reference id="domDataBroker" interface="org.opendaylight.mdsal.dom.api.DOMDataBroker"
+  <reference id="dOMDataBroker" interface="org.opendaylight.mdsal.dom.api.DOMDataBroker"
           ext:filter="(type=@{databroker-service-type})"/>
-  <reference id="domSchemaService" interface="org.opendaylight.mdsal.dom.api.DOMSchemaService"/>
 
-  <bean id="transactionChainHandler" class="org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler"
-          destroy-method="close">
-    <argument ref="domDataBroker"/>
-  </bean>
+  <bean id="servicesWrapper" factory-ref="rfc8040RestConfWiring" factory-method="getServicesWrapper" />
 
-  <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"/>
-  </bean>
-
-  <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>
-
-  <bean id="restconfApplication" class="org.opendaylight.restconf.nb.rfc8040.RestconfApplication">
-    <argument ref="schemaContextHandler"/>
-    <argument ref="mountPointServiceHandler"/>
-    <argument ref="servicesWrapper"/>
-  </bean>
-
-  <!-- JSONRestconfService -->
-  <bean id="jsonRestconfService"
-      class="org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl"
-      destroy-method="close">
-    <argument ref="servicesWrapper"/>
-    <argument ref="mountPointServiceHandler"/>
-    <argument ref="schemaContextHandler"/>
-  </bean>
-
-  <service ref="jsonRestconfService" odl:type="rfc8040"
+  <service ref="jSONRestconfServiceRfc8040Impl" odl:type="rfc8040"
       interface="org.opendaylight.restconf.nb.rfc8040.rests.services.api.JSONRestconfService" />
 
-  <!-- Web app registration -->
-
-  <reference id="customFilterAdapterConfig"
-      interface="org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration"/>
-
-  <reference id="webServer" interface="org.opendaylight.aaa.web.WebServer" />
-
-  <reference id="webContextSecurer" interface="org.opendaylight.aaa.web.WebContextSecurer" />
-
-  <reference id="servletSupport" interface="org.opendaylight.aaa.web.servlet.ServletSupport" />
-
-  <bean id="webInitializer" class="org.opendaylight.restconf.nb.rfc8040.web.WebInitializer"
-          destroy-method="close">
-    <argument ref="webServer"/>
-    <argument ref="webContextSecurer"/>
-    <argument ref="servletSupport"/>
-    <argument ref="restconfApplication"/>
-    <argument ref="customFilterAdapterConfig"/>
-  </bean>
-
 </blueprint>
diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/Rfc8040RestConfWiringTest.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/Rfc8040RestConfWiringTest.java
new file mode 100644 (file)
index 0000000..7b9a9a6
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2019 Red Hat, 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.test;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.opendaylight.infrautils.testutils.web.TestWebClient.Method.GET;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import java.io.IOException;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.aaa.filterchain.configuration.CustomFilterAdapterConfiguration;
+import org.opendaylight.aaa.web.WebServer;
+import org.opendaylight.aaa.web.testutils.TestWebClient;
+import org.opendaylight.aaa.web.testutils.WebTestModule;
+import org.opendaylight.infrautils.inject.guice.testutils.AnnotationsModule;
+import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
+import org.opendaylight.infrautils.testutils.LogRule;
+import org.opendaylight.restconf.nb.rfc8040.RestconfApplication;
+import org.opendaylight.restconf.nb.rfc8040.Rfc8040RestConfWiring;
+import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.rests.services.impl.JSONRestconfServiceRfc8040Impl;
+import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServicesWrapper;
+import org.opendaylight.restconf.nb.rfc8040.test.incubate.InMemoryMdsalModule;
+import org.opendaylight.restconf.nb.rfc8040.web.WebInitializer;
+import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+
+/**
+ * Tests if the {@link Rfc8040RestConfWiring} works.
+ *
+ * @author Michael Vorburger.ch
+ */
+public class Rfc8040RestConfWiringTest {
+
+    public static class TestModule extends AbstractModule {
+        @Override
+        protected void configure() {
+            bind(Rfc8040RestConfWiring.class).asEagerSingleton();
+            bind(RestconfApplication.class).asEagerSingleton();
+            bind(JSONRestconfServiceRfc8040Impl.class).asEagerSingleton();
+            bind(WebInitializer.class).asEagerSingleton();
+            bind(CustomFilterAdapterConfiguration.class).toInstance(listener -> { });
+        }
+
+        @Provides
+        @Singleton ServicesWrapper getServicesWrapper(Rfc8040RestConfWiring wiring) {
+            return wiring.getServicesWrapper();
+        }
+    }
+
+    public @Rule LogRule logRule = new LogRule();
+
+    public @Rule GuiceRule guice = new GuiceRule(TestModule.class,
+            InMemoryMdsalModule.class, WebTestModule.class, AnnotationsModule.class);
+
+    @Inject WebServer webServer;
+    @Inject TestWebClient webClient;
+
+    @Inject SchemaContextProvider schemaContextProvider;
+    @Inject SchemaContextHandler schemaContextHandler;
+
+    @Test
+    public void testWiring() throws IOException {
+        schemaContextHandler.onGlobalContextUpdated(schemaContextProvider.getSchemaContext());
+        assertThat(webClient.request(GET, "/rests/yang-library-version").getStatus()).isEqualTo(200);
+    }
+}
diff --git a/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/incubate/InMemoryMdsalModule.java b/restconf/restconf-nb-rfc8040/src/test/java/org/opendaylight/restconf/nb/rfc8040/test/incubate/InMemoryMdsalModule.java
new file mode 100644 (file)
index 0000000..986575c
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2019 Red Hat, 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.test.incubate;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import javax.annotation.PreDestroy;
+import javax.inject.Singleton;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractBaseDataBrokerTest;
+import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
+import org.opendaylight.mdsal.dom.api.DOMNotificationService;
+import org.opendaylight.mdsal.dom.api.DOMRpcService;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
+import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
+import org.opendaylight.mdsal.dom.broker.DOMNotificationRouter;
+import org.opendaylight.mdsal.dom.broker.DOMRpcRouter;
+import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
+import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
+
+/**
+ * Copy paste from org.opendaylight.controller.sal.restconf.impl.test.incubate.InMemoryMdsalModule.
+ *
+ * @author Michael Vorburger.ch
+ */
+public class InMemoryMdsalModule extends AbstractModule {
+
+    private static final int NOTIFICATION_SERVICE_QUEUE_DEPTH = 128;
+
+    private final AbstractBaseDataBrokerTest dataBrokerTest;
+    private final DOMNotificationRouter domNotificationRouter;
+
+    public InMemoryMdsalModule() throws Exception {
+        dataBrokerTest = new AbstractConcurrentDataBrokerTest(true) { // NOT AbstractDataBrokerTest
+        };
+        dataBrokerTest.setup();
+
+        domNotificationRouter = DOMNotificationRouter.create(NOTIFICATION_SERVICE_QUEUE_DEPTH);
+    }
+
+    @Override
+    protected void configure() {
+    }
+
+    @Provides
+    @Singleton
+    DataBroker getDataBroker() {
+        return dataBrokerTest.getDataBroker();
+    }
+
+    @Provides
+    @Singleton DOMDataBroker getDOMDataBroker() {
+        return dataBrokerTest.getDomBroker();
+    }
+
+    @Provides
+    @Singleton DOMNotificationRouter getDOMNotificationRouter() {
+        return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
+    }
+
+    @Provides
+    @Singleton DOMSchemaService getSchemaService() {
+        return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
+    }
+
+    @Provides
+    @Singleton SchemaContextProvider getSchemaContextProvider() {
+        DOMSchemaService schemaService = dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
+        if (schemaService instanceof SchemaContextProvider) {
+            return (SchemaContextProvider) schemaService;
+        }
+        throw new IllegalStateException(
+                "The schema service isn't a SchemaContextProvider, it's a " + schemaService.getClass());
+    }
+
+    @Provides
+    @Singleton DOMMountPointService getDOMMountPoint() {
+        return new DOMMountPointServiceImpl();
+    }
+
+    @Provides
+    @Singleton DOMNotificationService getDOMNotificationService() {
+        return domNotificationRouter;
+    }
+
+    @Provides
+    @Singleton DOMNotificationPublishService getDOMNotificationPublishService() {
+        return domNotificationRouter;
+    }
+
+    @Provides
+    @Singleton DOMNotificationSubscriptionListenerRegistry getDOMNotificationSubscriptionListenerRegistry() {
+        return domNotificationRouter;
+    }
+
+    @Provides
+    @Singleton DOMRpcService getDOMRpcService(DOMSchemaService schemaService) {
+        return DOMRpcRouter.newInstance(schemaService).getRpcService();
+    }
+
+    @PreDestroy
+    public void close() {
+    }
+}
index a1f4b84341923812d4fcfcc869f38b0f16460233..26ac2eaa004bc9580b4a5d6684adbf45ecefc9d5 100644 (file)
 
   <dependencyManagement>
     <dependencies>
+      <dependency>
+        <groupId>org.opendaylight.infrautils</groupId>
+        <artifactId>infrautils-artifacts</artifactId>
+        <version>1.6.0-SNAPSHOT</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
       <dependency>
         <groupId>org.opendaylight.aaa</groupId>
         <artifactId>aaa-artifacts</artifactId>