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 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;
20 public class DataBrokerTestModule {
21 private final boolean useMTDataTreeChangeListenerExecutor;
23 private AbstractConcurrentDataBrokerTest dataBrokerTest;
25 public DataBrokerTestModule(final boolean useMTDataTreeChangeListenerExecutor) {
26 this.useMTDataTreeChangeListenerExecutor = useMTDataTreeChangeListenerExecutor;
29 public static DataBroker dataBroker() {
30 return new DataBrokerTestModule(false).getDataBroker();
33 // Suppress IllegalCatch because of AbstractDataBrokerTest (change later)
34 @SuppressWarnings({ "checkstyle:IllegalCatch", "checkstyle:IllegalThrows" })
35 public DataBroker getDataBroker() throws RuntimeException {
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);
50 public DOMDataBroker getDOMDataBroker() {
51 return dataBrokerTest.getDomBroker();
54 public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() {
55 return dataBrokerTest.getDataBrokerTestCustomizer().getBindingToNormalized();
58 public DOMNotificationRouter getDOMNotificationRouter() {
59 return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
62 public DOMSchemaService getSchemaService() {
63 return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
66 public SchemaContextProvider getSchemaContextProvider() {
67 return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService()::getGlobalContext;