938195b2181b30e060372c03abce410ea2c53cfc
[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 org.opendaylight.mdsal.binding.api.DataBroker;
11 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
12
13 public class DataBrokerTestModule {
14     private final boolean useMTDataTreeChangeListenerExecutor;
15
16     public DataBrokerTestModule(final boolean useMTDataTreeChangeListenerExecutor) {
17         this.useMTDataTreeChangeListenerExecutor = useMTDataTreeChangeListenerExecutor;
18     }
19
20     public static DataBroker dataBroker() {
21         return new DataBrokerTestModule(false).getDataBroker();
22     }
23
24     // Suppress IllegalCatch because of AbstractDataBrokerTest (change later)
25     @SuppressWarnings({ "checkstyle:IllegalCatch", "checkstyle:IllegalThrows" })
26     public DataBroker getDataBroker() throws RuntimeException {
27         try {
28             // This is a little bit "upside down" - in the future,
29             // we should probably put what is in AbstractDataBrokerTest
30             // into this DataBrokerTestModule, and make AbstractDataBrokerTest
31             // use it, instead of the way around it currently is (the opposite);
32             // this is just for historical reasons... and works for now.
33             AbstractConcurrentDataBrokerTest dataBrokerTest =
34                     new AbstractConcurrentDataBrokerTest(useMTDataTreeChangeListenerExecutor) { };
35             dataBrokerTest.setup();
36             return dataBrokerTest.getDataBroker();
37         } catch (Exception e) {
38             throw new RuntimeException(e);
39         }
40     }
41 }