Bump yangtools to 13.0.0
[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 com.google.common.base.Throwables;
12 import java.util.function.Supplier;
13 import org.opendaylight.mdsal.binding.api.DataBroker;
14 import org.opendaylight.mdsal.binding.dom.adapter.CurrentAdapterSerializer;
15 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
16 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
17 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
18 import org.opendaylight.mdsal.dom.broker.DOMNotificationRouter;
19 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
20
21 @Beta
22 public class DataBrokerTestModule {
23     private final boolean useMTDataTreeChangeListenerExecutor;
24
25     private AbstractConcurrentDataBrokerTest dataBrokerTest;
26
27     public DataBrokerTestModule(final boolean useMTDataTreeChangeListenerExecutor) {
28         this.useMTDataTreeChangeListenerExecutor = useMTDataTreeChangeListenerExecutor;
29     }
30
31     public static DataBroker dataBroker() {
32         return new DataBrokerTestModule(false).getDataBroker();
33     }
34
35     // Suppress IllegalCatch because of AbstractDataBrokerTest (change later)
36     @SuppressWarnings("checkstyle:IllegalCatch")
37     public DataBroker getDataBroker() {
38         try {
39             // This is a little bit "upside down" - in the future,
40             // we should probably put what is in AbstractDataBrokerTest
41             // into this DataBrokerTestModule, and make AbstractDataBrokerTest
42             // use it, instead of the way around it currently is (the opposite);
43             // this is just for historical reasons... and works for now.
44             dataBrokerTest = new AbstractConcurrentDataBrokerTest(useMTDataTreeChangeListenerExecutor) { };
45             dataBrokerTest.setup();
46             return dataBrokerTest.getDataBroker();
47         } catch (Exception e) {
48             Throwables.throwIfUnchecked(e);
49             throw new IllegalStateException(e);
50         }
51     }
52
53     public DOMDataBroker getDOMDataBroker() {
54         return dataBrokerTest.getDomBroker();
55     }
56
57     public CurrentAdapterSerializer getBindingToNormalizedNodeCodec() {
58         return dataBrokerTest.getDataBrokerTestCustomizer().getAdapterContext().currentSerializer();
59     }
60
61     public DOMNotificationRouter getDOMNotificationRouter() {
62         return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
63     }
64
65     public DOMSchemaService getSchemaService() {
66         return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
67     }
68
69     public Supplier<EffectiveModelContext> getModelContextSupplier() {
70         return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService()::getGlobalContext;
71     }
72 }