0c6a056c9e2622ac72f116c24045c56342e08b65
[transportpce.git] / olm / src / test / java / org / opendaylight / transportpce / olm / OlmProviderTest.java
1 /*
2  * Copyright © 2018 Orange Systems, 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
9
10 package org.opendaylight.transportpce.olm;
11
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.mockito.Mockito;
15 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
16 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
17 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
18 import org.opendaylight.transportpce.common.StringConstants;
19 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
21 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
22 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
23 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
24 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
25 import org.opendaylight.transportpce.common.mapping.*;
26 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
27 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
28 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
29 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
30 import org.opendaylight.transportpce.olm.power.PowerMgmt;
31 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
32 import org.opendaylight.transportpce.olm.service.OlmPowerService;
33 import org.opendaylight.transportpce.olm.service.OlmPowerServiceImpl;
34 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
35 import org.opendaylight.transportpce.olm.stub.MountPointStub;
36 import org.opendaylight.transportpce.olm.stub.RpcProviderRegistryStub;
37 import org.opendaylight.transportpce.olm.stub.RpcProviderRegistryStub2;
38 import org.opendaylight.transportpce.test.AbstractTest;
39
40 public class OlmProviderTest extends AbstractTest {
41
42     private MountPoint mountPoint;
43     private MountPointService mountPointService;
44     private DeviceTransactionManager deviceTransactionManager;
45     private CrossConnect crossConnect;
46     private OpenRoadmInterfaces openRoadmInterfaces;
47     private PortMapping portMapping;
48     private PowerMgmt powerMgmt;
49     private OlmPowerService olmPowerService;
50     private RpcProviderRegistry rpcProviderRegistry;
51     private OlmProvider olmProvider;
52     private CrossConnectImpl121 crossConnectImpl121;
53     private CrossConnectImpl221 crossConnectImpl22;
54     private MappingUtils mappingUtils;
55     private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
56     private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
57     private PortMappingVersion221 portMappingVersion22;
58     private PortMappingVersion121 portMappingVersion121;
59
60     @Before
61     public void setUp() {
62         this.mountPoint = new MountPointStub(this.getDataBroker());
63         this.mountPointService = new MountPointServiceStub(mountPoint);
64         this.mappingUtils = Mockito.spy(MappingUtils.class);
65         Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
66                 .getOpenRoadmVersion(Mockito.anyString());
67         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
68         this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
69         this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
70         this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
71                 this.crossConnectImpl22);
72         this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
73         this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
74         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
75                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
76         this.portMappingVersion22 =
77                 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
78         this.portMappingVersion121 =
79                 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
80         this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
81                 this.portMappingVersion121);
82         this.portMapping = Mockito.spy(this.portMapping);
83         this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
84             this.deviceTransactionManager);
85         this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt,
86             this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
87         this.rpcProviderRegistry = new RpcProviderRegistryStub();
88         this.olmProvider = new OlmProvider(this.rpcProviderRegistry, this.olmPowerService);
89
90     }
91
92     @Test
93     public void testInitAndClose() {
94         this.olmProvider.init();
95         this.olmProvider.close();
96     }
97
98     @Test
99     public void testClose2() {
100         this.rpcProviderRegistry = new RpcProviderRegistryStub2();
101         this.olmProvider = new OlmProvider(this.rpcProviderRegistry, this.olmPowerService);
102         this.olmProvider.init();
103         this.olmProvider.close();
104     }
105
106 }