Bump upstreams
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / rfc8040 / test / incubate / InMemoryMdsalModule.java
1 /*
2  * Copyright (c) 2019 Red Hat, Inc. and others. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.restconf.nb.rfc8040.test.incubate;
9
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
28 /**
29  * Copy paste from org.opendaylight.controller.sal.restconf.impl.test.incubate.InMemoryMdsalModule.
30  *
31  * @author Michael Vorburger.ch
32  */
33 public class InMemoryMdsalModule extends AbstractModule {
34     private static final int NOTIFICATION_SERVICE_QUEUE_DEPTH = 128;
35
36     private final AbstractBaseDataBrokerTest dataBrokerTest;
37     private final DOMNotificationRouter domNotificationRouter;
38
39     public InMemoryMdsalModule() throws Exception {
40         dataBrokerTest = new AbstractConcurrentDataBrokerTest(true) {
41             // NOT AbstractDataBrokerTest
42         };
43         dataBrokerTest.setup();
44
45         domNotificationRouter = new DOMNotificationRouter(NOTIFICATION_SERVICE_QUEUE_DEPTH);
46     }
47
48     @Override
49     protected void configure() {
50     }
51
52     @Provides
53     @Singleton
54     DataBroker getDataBroker() {
55         return dataBrokerTest.getDataBroker();
56     }
57
58     @Provides
59     @Singleton DOMDataBroker getDOMDataBroker() {
60         return dataBrokerTest.getDomBroker();
61     }
62
63     @Provides
64     @Singleton DOMNotificationRouter getDOMNotificationRouter() {
65         return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
66     }
67
68     @Provides
69     @Singleton DOMSchemaService getSchemaService() {
70         return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
71     }
72
73     @Provides
74     @Singleton DOMMountPointService getDOMMountPoint() {
75         return new DOMMountPointServiceImpl();
76     }
77
78     @Provides
79     @Singleton DOMNotificationService getDOMNotificationService() {
80         return domNotificationRouter.notificationService();
81     }
82
83     @Provides
84     @Singleton DOMNotificationPublishService getDOMNotificationPublishService() {
85         return domNotificationRouter.notificationPublishService();
86     }
87
88     @Provides
89     @Singleton DOMRpcService getDOMRpcService(final DOMSchemaService schemaService) {
90         return new DOMRpcRouter(schemaService).rpcService();
91     }
92
93     @Provides
94     @Singleton
95     DOMActionService getDOMActionService(final DOMSchemaService schemaService) {
96         return new DOMRpcRouter(schemaService).actionService();
97     }
98
99     @PreDestroy
100     public void close() {
101     }
102 }