Remove sal.core.api.model
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / test / 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.controller.md.sal.binding.test;
9
10 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
11 import org.opendaylight.controller.md.sal.binding.impl.BindingToNormalizedNodeCodec;
12 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
13 import org.opendaylight.controller.md.sal.dom.broker.impl.DOMNotificationRouter;
14 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
16
17 public class DataBrokerTestModule {
18
19     public static DataBroker dataBroker() {
20         return new DataBrokerTestModule(false).getDataBroker();
21     }
22
23     private final boolean useMTDataTreeChangeListenerExecutor;
24     private ConstantSchemaAbstractDataBrokerTest dataBrokerTest;
25
26     public DataBrokerTestModule(boolean useMTDataTreeChangeListenerExecutor) {
27         this.useMTDataTreeChangeListenerExecutor = useMTDataTreeChangeListenerExecutor;
28     }
29
30     // Suppress IllegalCatch because of AbstractDataBrokerTest (change later)
31     @SuppressWarnings({ "checkstyle:IllegalCatch", "checkstyle:IllegalThrows" })
32     public DataBroker getDataBroker() throws RuntimeException {
33         try {
34             // This is a little bit "upside down" - in the future,
35             // we should probably put what is in AbstractDataBrokerTest
36             // into this DataBrokerTestModule, and make AbstractDataBrokerTest
37             // use it, instead of the way around it currently is (the opposite);
38             // this is just for historical reasons... and works for now.
39             dataBrokerTest = new ConstantSchemaAbstractDataBrokerTest(useMTDataTreeChangeListenerExecutor);
40             dataBrokerTest.setup();
41             return dataBrokerTest.getDataBroker();
42         } catch (Exception e) {
43             throw new RuntimeException(e);
44         }
45     }
46
47     public DOMDataBroker getDOMDataBroker() {
48         return dataBrokerTest.getDomBroker();
49     }
50
51     public BindingToNormalizedNodeCodec getBindingToNormalizedNodeCodec() {
52         return dataBrokerTest.getDataBrokerTestCustomizer().getBindingToNormalized();
53     }
54
55     public DOMNotificationRouter getDOMNotificationRouter() {
56         return dataBrokerTest.getDataBrokerTestCustomizer().getDomNotificationRouter();
57     }
58
59     public DOMSchemaService getSchemaService() {
60         return dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
61     }
62
63     public SchemaContextProvider getSchemaContextProvider() {
64         return (SchemaContextProvider) dataBrokerTest.getDataBrokerTestCustomizer().getSchemaService();
65     }
66 }