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 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;
22 public class DataBrokerTestModule {
23 private final boolean useMTDataTreeChangeListenerExecutor;
25 private AbstractConcurrentDataBrokerTest dataBrokerTest;
27 public DataBrokerTestModule(final boolean useMTDataTreeChangeListenerExecutor) {
28 this.useMTDataTreeChangeListenerExecutor = useMTDataTreeChangeListenerExecutor;
31 public static DataBroker dataBroker() {
32 return new DataBrokerTestModule(false).getDataBroker();
35 // Suppress IllegalCatch because of AbstractDataBrokerTest (change later)
36 @SuppressWarnings("checkstyle:IllegalCatch")
37 public DataBroker getDataBroker() {
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);
53 public DOMDataBroker getDOMDataBroker() {
54 return dataBrokerTest.getDomBroker();
57 public CurrentAdapterSerializer getBindingToNormalizedNodeCodec() {
58 return dataBrokerTest.getDataBrokerTestCustomizer().getAdapterContext().currentSerializer();
61 public DOMNotificationRouter getDOMNotificationRouter() {
62 return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
65 public DOMSchemaService getSchemaService() {
66 return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
69 public Supplier<EffectiveModelContext> getModelContextSupplier() {
70 return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService()::getGlobalContext;