2 * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.nb.rfc8040.test.incubate;
10 import com.google.inject.AbstractModule;
11 import com.google.inject.Provides;
12 import javax.annotation.PreDestroy;
13 import javax.inject.Singleton;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractBaseDataBrokerTest;
16 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
17 import org.opendaylight.mdsal.dom.api.DOMActionService;
18 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
19 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
20 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
21 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
22 import org.opendaylight.mdsal.dom.api.DOMRpcService;
23 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
24 import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
25 import org.opendaylight.mdsal.dom.broker.DOMNotificationRouter;
26 import org.opendaylight.mdsal.dom.broker.DOMRpcRouter;
27 import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
28 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
31 * Copy paste from org.opendaylight.controller.sal.restconf.impl.test.incubate.InMemoryMdsalModule.
33 * @author Michael Vorburger.ch
35 public class InMemoryMdsalModule extends AbstractModule {
37 private static final int NOTIFICATION_SERVICE_QUEUE_DEPTH = 128;
39 private final AbstractBaseDataBrokerTest dataBrokerTest;
40 private final DOMNotificationRouter domNotificationRouter;
42 public InMemoryMdsalModule() throws Exception {
43 dataBrokerTest = new AbstractConcurrentDataBrokerTest(true) { // NOT AbstractDataBrokerTest
45 dataBrokerTest.setup();
47 domNotificationRouter = DOMNotificationRouter.create(NOTIFICATION_SERVICE_QUEUE_DEPTH);
51 protected void configure() {
56 DataBroker getDataBroker() {
57 return dataBrokerTest.getDataBroker();
61 @Singleton DOMDataBroker getDOMDataBroker() {
62 return dataBrokerTest.getDomBroker();
66 @Singleton DOMNotificationRouter getDOMNotificationRouter() {
67 return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
71 @Singleton DOMSchemaService getSchemaService() {
72 return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
76 @Singleton EffectiveModelContextProvider getSchemaContextProvider() {
77 DOMSchemaService schemaService = dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
78 if (schemaService instanceof EffectiveModelContextProvider) {
79 return (EffectiveModelContextProvider) schemaService;
81 throw new IllegalStateException(
82 "The schema service isn't a SchemaContextProvider, it's a " + schemaService.getClass());
86 @Singleton DOMMountPointService getDOMMountPoint() {
87 return new DOMMountPointServiceImpl();
91 @Singleton DOMNotificationService getDOMNotificationService() {
92 return domNotificationRouter;
96 @Singleton DOMNotificationPublishService getDOMNotificationPublishService() {
97 return domNotificationRouter;
101 @Singleton DOMNotificationSubscriptionListenerRegistry getDOMNotificationSubscriptionListenerRegistry() {
102 return domNotificationRouter;
106 @Singleton DOMRpcService getDOMRpcService(final DOMSchemaService schemaService) {
107 return new DOMRpcRouter(schemaService).getRpcService();
112 DOMActionService getDOMActionService(final DOMSchemaService schemaService) {
113 return new DOMRpcRouter(schemaService).getActionService();
117 public void close() {