DataBrokerTestModule getBindingToNormalizedNodeCodec() & Co.
[mdsal.git] / binding / mdsal-binding-test-utils / src / main / java / org / opendaylight / mdsal / binding / testutils / DataBrokerTestModule.java
1 /*
2  * Copyright (c) 2016 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.mdsal.binding.testutils;
9
10 import com.google.common.annotations.Beta;
11 import org.opendaylight.mdsal.binding.api.DataBroker;
12 import org.opendaylight.mdsal.binding.dom.adapter.BindingToNormalizedNodeCodec;
13 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
14 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
15 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
16 import org.opendaylight.mdsal.dom.broker.DOMNotificationRouter;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
18
19 @Beta
20 public class DataBrokerTestModule {
21     private final boolean useMTDataTreeChangeListenerExecutor;
22
23     private AbstractConcurrentDataBrokerTest dataBrokerTest;
24
25     public DataBrokerTestModule(final boolean useMTDataTreeChangeListenerExecutor) {
26         this.useMTDataTreeChangeListenerExecutor = useMTDataTreeChangeListenerExecutor;
27     }
28
29     public static DataBroker dataBroker() {
30         return new DataBrokerTestModule(false).getDataBroker();
31     }
32
33     // Suppress IllegalCatch because of AbstractDataBrokerTest (change later)
34     @SuppressWarnings({ "checkstyle:IllegalCatch", "checkstyle:IllegalThrows" })
35     public DataBroker getDataBroker() throws RuntimeException {
36         try {
37             // This is a little bit "upside down" - in the future,
38             // we should probably put what is in AbstractDataBrokerTest
39             // into this DataBrokerTestModule, and make AbstractDataBrokerTest
40             // use it, instead of the way around it currently is (the opposite);
41             // this is just for historical reasons... and works for now.
42             dataBrokerTest = new AbstractConcurrentDataBrokerTest(useMTDataTreeChangeListenerExecutor) { };
43             dataBrokerTest.setup();
44             return dataBrokerTest.getDataBroker();
45         } catch (Exception e) {
46             throw new RuntimeException(e);
47         }
48     }
49
50     public DOMDataBroker getDOMDataBroker() {
51         return dataBrokerTest.getDomBroker();
52     }
53
54     public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() {
55         return dataBrokerTest.getDataBrokerTestCustomizer().getBindingToNormalized();
56     }
57
58     public DOMNotificationRouter getDOMNotificationRouter() {
59         return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
60     }
61
62     public DOMSchemaService getSchemaService() {
63         return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
64     }
65
66     public SchemaContextProvider getSchemaContextProvider() {
67         return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService()::getGlobalContext;
68     }
69 }