986575cc4874fc401e571dd05a7111495c00ace3
[netconf.git] / restconf / restconf-nb-rfc8040 / 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.DOMDataBroker;
18 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
19 import org.opendaylight.mdsal.dom.api.DOMNotificationPublishService;
20 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
21 import org.opendaylight.mdsal.dom.api.DOMRpcService;
22 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
23 import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
24 import org.opendaylight.mdsal.dom.broker.DOMNotificationRouter;
25 import org.opendaylight.mdsal.dom.broker.DOMRpcRouter;
26 import org.opendaylight.mdsal.dom.spi.DOMNotificationSubscriptionListenerRegistry;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
28
29 /**
30  * Copy paste from org.opendaylight.controller.sal.restconf.impl.test.incubate.InMemoryMdsalModule.
31  *
32  * @author Michael Vorburger.ch
33  */
34 public class InMemoryMdsalModule extends AbstractModule {
35
36     private static final int NOTIFICATION_SERVICE_QUEUE_DEPTH = 128;
37
38     private final AbstractBaseDataBrokerTest dataBrokerTest;
39     private final DOMNotificationRouter domNotificationRouter;
40
41     public InMemoryMdsalModule() throws Exception {
42         dataBrokerTest = new AbstractConcurrentDataBrokerTest(true) { // NOT AbstractDataBrokerTest
43         };
44         dataBrokerTest.setup();
45
46         domNotificationRouter = DOMNotificationRouter.create(NOTIFICATION_SERVICE_QUEUE_DEPTH);
47     }
48
49     @Override
50     protected void configure() {
51     }
52
53     @Provides
54     @Singleton
55     DataBroker getDataBroker() {
56         return dataBrokerTest.getDataBroker();
57     }
58
59     @Provides
60     @Singleton DOMDataBroker getDOMDataBroker() {
61         return dataBrokerTest.getDomBroker();
62     }
63
64     @Provides
65     @Singleton DOMNotificationRouter getDOMNotificationRouter() {
66         return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
67     }
68
69     @Provides
70     @Singleton DOMSchemaService getSchemaService() {
71         return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
72     }
73
74     @Provides
75     @Singleton SchemaContextProvider getSchemaContextProvider() {
76         DOMSchemaService schemaService = dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
77         if (schemaService instanceof SchemaContextProvider) {
78             return (SchemaContextProvider) schemaService;
79         }
80         throw new IllegalStateException(
81                 "The schema service isn't a SchemaContextProvider, it's a " + schemaService.getClass());
82     }
83
84     @Provides
85     @Singleton DOMMountPointService getDOMMountPoint() {
86         return new DOMMountPointServiceImpl();
87     }
88
89     @Provides
90     @Singleton DOMNotificationService getDOMNotificationService() {
91         return domNotificationRouter;
92     }
93
94     @Provides
95     @Singleton DOMNotificationPublishService getDOMNotificationPublishService() {
96         return domNotificationRouter;
97     }
98
99     @Provides
100     @Singleton DOMNotificationSubscriptionListenerRegistry getDOMNotificationSubscriptionListenerRegistry() {
101         return domNotificationRouter;
102     }
103
104     @Provides
105     @Singleton DOMRpcService getDOMRpcService(DOMSchemaService schemaService) {
106         return DOMRpcRouter.newInstance(schemaService).getRpcService();
107     }
108
109     @PreDestroy
110     public void close() {
111     }
112 }