<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>
*
* <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.
<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>
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;
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;
--- /dev/null
+/*
+ * 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} & {@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;
+ }
+}
*/
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;
}
public DOMDataBroker get() {
return this.broker;
}
-
}
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;
* @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);
}
*/
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;
* @param notificationService
* DOMNotificationService
*/
- public NotificationServiceHandler(final DOMNotificationService notificationService) {
+ @Inject
+ public NotificationServiceHandler(final @Reference DOMNotificationService notificationService) {
this.notificationService = notificationService;
}
public DOMNotificationService get() {
return this.notificationService;
}
-
}
*/
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;
}
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;
/**
* Implementation of {@link SchemaContextHandler}.
- *
*/
+@Singleton
@SuppressWarnings("checkstyle:FinalClass")
public class SchemaContextHandler implements SchemaContextListenerHandler, AutoCloseable {
*
* @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();
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;
/**
* Implementation of {@link TransactionChainHandler}.
- *
*/
+@Singleton
public class TransactionChainHandler implements Handler<DOMTransactionChain>, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(TransactionChainHandler.class);
/**
* Prepare transaction chain service for Restconf services.
*/
+ @Inject
public TransactionChainHandler(final DOMDataBroker dataBroker) {
this.dataBroker = Objects.requireNonNull(dataBroker);
transactionChain = Objects.requireNonNull(dataBroker.createTransactionChain(transactionChainListener));
}
@Override
+ @PreDestroy
public synchronized void close() {
transactionChain.close();
}
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;
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;
*
* @author Thomas Pantelis
*/
+@Singleton
public class JSONRestconfServiceRfc8040Impl implements JSONRestconfService, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(JSONRestconfServiceRfc8040Impl.class);
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;
}
@Override
+ @PreDestroy
public void close() {
}
* <li>{@link BaseServicesWrapper}
* <li>{@link TransactionServicesWrapper}
* </ul>
- *
*/
@Path("/")
public final class ServicesWrapper implements BaseServicesWrapper, TransactionServicesWrapper {
*/
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;
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())
registration = webServer.registerWebContext(webContextBuilder.build());
}
+ @PreDestroy
public void close() {
if (registration != null) {
registration.close();
</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>
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+/*
+ * 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() {
+ }
+}
<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>