2 * Copyright (c) 2016 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.mdsal.binding.testutils;
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Throwables;
12 import org.opendaylight.mdsal.binding.api.DataBroker;
13 import org.opendaylight.mdsal.binding.dom.adapter.CurrentAdapterSerializer;
14 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
15 import org.opendaylight.mdsal.dom.api.DOMDataBroker;
16 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
17 import org.opendaylight.mdsal.dom.broker.DOMNotificationRouter;
18 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContextProvider;
21 public class DataBrokerTestModule {
22 private final boolean useMTDataTreeChangeListenerExecutor;
24 private AbstractConcurrentDataBrokerTest dataBrokerTest;
26 public DataBrokerTestModule(final boolean useMTDataTreeChangeListenerExecutor) {
27 this.useMTDataTreeChangeListenerExecutor = useMTDataTreeChangeListenerExecutor;
30 public static DataBroker dataBroker() {
31 return new DataBrokerTestModule(false).getDataBroker();
34 // Suppress IllegalCatch because of AbstractDataBrokerTest (change later)
35 @SuppressWarnings("checkstyle:IllegalCatch")
36 public DataBroker getDataBroker() {
38 // This is a little bit "upside down" - in the future,
39 // we should probably put what is in AbstractDataBrokerTest
40 // into this DataBrokerTestModule, and make AbstractDataBrokerTest
41 // use it, instead of the way around it currently is (the opposite);
42 // this is just for historical reasons... and works for now.
43 dataBrokerTest = new AbstractConcurrentDataBrokerTest(useMTDataTreeChangeListenerExecutor) { };
44 dataBrokerTest.setup();
45 return dataBrokerTest.getDataBroker();
46 } catch (Exception e) {
47 Throwables.throwIfUnchecked(e);
48 throw new IllegalStateException(e);
52 public DOMDataBroker getDOMDataBroker() {
53 return dataBrokerTest.getDomBroker();
56 public CurrentAdapterSerializer getBindingToNormalizedNodeCodec() {
57 return dataBrokerTest.getDataBrokerTestCustomizer().getAdapterContext().currentSerializer();
60 public DOMNotificationRouter getDOMNotificationRouter() {
61 return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
64 public DOMSchemaService getSchemaService() {
65 return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
68 public EffectiveModelContextProvider getSchemaContextProvider() {
69 return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService()::getGlobalContext;