MDSAL-API Migration
[genius.git] / mdsalutil / mdsalutil-testutils / src / main / java / org / opendaylight / genius / datastoreutils / testutils / DataBrokerFailuresModule.java
1 /*
2  * Copyright (c) 2017 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.genius.datastoreutils.testutils;
9
10 import com.google.common.util.concurrent.ListeningExecutorService;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import com.google.inject.AbstractModule;
13 import java.util.concurrent.Executors;
14 import org.opendaylight.mdsal.binding.api.DataBroker;
15 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractBaseDataBrokerTest;
16 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTestCustomizer;
17
18 /**
19  * Guice Module which correctly binds the {@link DataBrokerFailures}.
20  *
21  * @author Michael Vorburger.ch
22  */
23 public class DataBrokerFailuresModule extends AbstractModule {
24
25     private DataBroker realDataBroker;
26
27     public DataBrokerFailuresModule(DataBroker realDataBroker) {
28         this.realDataBroker = realDataBroker;
29     }
30
31     public DataBrokerFailuresModule() throws Exception {
32         AbstractBaseDataBrokerTest dataBrokerTest = new AbstractBaseDataBrokerTest() {
33             @Override
34             protected AbstractDataBrokerTestCustomizer createDataBrokerTestCustomizer() {
35                 return new AbstractDataBrokerTestCustomizer() {
36                     @Override
37                     public ListeningExecutorService getCommitCoordinatorExecutor() {
38                         return MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
39                     }
40                 };
41             }
42         };
43         dataBrokerTest.setup();
44         this.realDataBroker = dataBrokerTest.getDataBroker();
45     }
46
47     @Override
48     protected void configure() {
49         DataBrokerFailuresImpl testableDataBroker = new DataBrokerFailuresImpl(realDataBroker);
50         bind(DataBroker.class).toInstance(testableDataBroker);
51         // bind(DataBroker.class).annotatedWith(Reference.class).toInstance(testableDataBroker);
52         bind(DataBrokerFailures.class).toInstance(testableDataBroker);
53     }
54 }