Fix issues related to checkstyle enforcement for module
[genius.git] / interfacemanager / interfacemanager-impl / src / test / java / org / opendaylight / genius / interfacemanager / test / InterfaceManagerTestModule.java
1 /*
2  * Copyright (c) 2016, 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.interfacemanager.test;
9
10 import static org.mockito.Mockito.mock;
11
12 import java.net.UnknownHostException;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestModule;
15 import org.opendaylight.controller.md.sal.common.api.clustering.EntityOwnershipService;
16 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
17 import org.opendaylight.genius.idmanager.IdManager;
18 import org.opendaylight.genius.idmanager.IdUtils;
19 import org.opendaylight.genius.interfacemanager.listeners.CacheBridgeEntryConfigListener;
20 import org.opendaylight.genius.interfacemanager.listeners.CacheBridgeRefEntryListener;
21 import org.opendaylight.genius.interfacemanager.listeners.HwVTEPConfigListener;
22 import org.opendaylight.genius.interfacemanager.listeners.HwVTEPTunnelsStateListener;
23 import org.opendaylight.genius.interfacemanager.listeners.InterfaceConfigListener;
24 import org.opendaylight.genius.interfacemanager.listeners.InterfaceInventoryStateListener;
25 import org.opendaylight.genius.interfacemanager.listeners.InterfaceStateListener;
26 import org.opendaylight.genius.interfacemanager.listeners.InterfaceTopologyStateListener;
27 import org.opendaylight.genius.interfacemanager.listeners.TerminationPointStateListener;
28 import org.opendaylight.genius.interfacemanager.listeners.VlanMemberConfigListener;
29 import org.opendaylight.genius.interfacemanager.rpcservice.InterfaceManagerRpcService;
30 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.listeners.FlowBasedServicesConfigListener;
31 import org.opendaylight.genius.interfacemanager.servicebindings.flowbased.listeners.FlowBasedServicesInterfaceStateListener;
32 import org.opendaylight.genius.interfacemanager.test.infra.TestEntityOwnershipService;
33 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
34 import org.opendaylight.genius.mdsalutil.interfaces.testutils.TestIMdsalApiManager;
35 import org.opendaylight.infrautils.inject.ModuleSetupRuntimeException;
36 import org.opendaylight.infrautils.inject.guice.testutils.AbstractGuiceJsr250Module;
37 import org.opendaylight.lockmanager.LockManager;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.AlivenessMonitorService;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.lockmanager.rev160413.LockManagerService;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
44
45 /**
46  * Dependency Injection Wiring for {@link InterfaceManagerConfigurationTest}.
47  *
48  * <p>
49  * This class looks a little bit more complicated than it could and later will
50  * be just because interfacemanager is still using CSS instead of BP
51  * with @Inject.
52  *
53  * <p>
54  * Please DO NOT copy/paste this class as-is into other projects; this is
55  * intended to be temporary, until interfacemanager is switch from CSS to BP.
56  *
57  * <p>
58  * For "proper" *Module examples, please see the AclServiceModule and
59  * AclServiceTestModule or ElanServiceTestModule instead.
60  *
61  * @author Michael Vorburger
62  */
63 public class InterfaceManagerTestModule extends AbstractGuiceJsr250Module {
64
65     private static final Logger LOG = LoggerFactory.getLogger(InterfaceManagerTestModule.class);
66
67     @Override
68     protected void configureBindings() throws UnknownHostException {
69         // TODO Ordering as below.. hard to do currently, because of interdeps.
70         // due to CSS
71         // Bindings for services from this project
72         // Bindings for external services to "real" implementations
73         // Bindings to test infra (fakes & mocks)
74
75         DataBroker dataBroker = DataBrokerTestModule.dataBroker();
76         bind(DataBroker.class).toInstance(dataBroker);
77
78         LockManagerService lockManager = new LockManager(dataBroker);
79         bind(LockManagerService.class).toInstance(lockManager);
80
81         IdUtils idUtils = new IdUtils();
82         IdManagerService idManager;
83         try {
84             idManager = new IdManager(dataBroker, lockManager, idUtils);
85         } catch (ReadFailedException e) {
86             // TODO Support AbstractGuiceJsr250Module
87             throw new ModuleSetupRuntimeException(e);
88         }
89         bind(IdManagerService.class).toInstance(idManager);
90
91         TestIMdsalApiManager mdsalManager = TestIMdsalApiManager.newInstance();
92         bind(IMdsalApiManager.class).toInstance(mdsalManager);
93         bind(TestIMdsalApiManager.class).toInstance(mdsalManager);
94
95         EntityOwnershipService entityOwnershipService = TestEntityOwnershipService.newInstance();
96         bind(EntityOwnershipService.class).toInstance(entityOwnershipService);
97
98         bind(AlivenessMonitorService.class).toInstance(mock(AlivenessMonitorService.class));
99         bind(OdlInterfaceRpcService.class).to(InterfaceManagerRpcService.class);
100         bind(CacheBridgeEntryConfigListener.class);
101         bind(CacheBridgeRefEntryListener.class);
102         bind(FlowBasedServicesConfigListener.class);
103         bind(FlowBasedServicesInterfaceStateListener.class);
104         bind(HwVTEPConfigListener.class);
105         bind(HwVTEPTunnelsStateListener.class);
106         bind(InterfaceConfigListener.class);
107         bind(InterfaceInventoryStateListener.class);
108         bind(InterfaceTopologyStateListener.class);
109         bind(TerminationPointStateListener.class);
110         bind(VlanMemberConfigListener.class);
111         bind(InterfaceStateListener.class);
112     }
113 }