c020b545c0af96d07b4dd28f606d7e577e45f34c
[transportpce.git] / olm / src / test / java / org / opendaylight / transportpce / olm / power / PowerMgmtTest.java
1 /*
2  * Copyright © 2018 Orange, 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 package org.opendaylight.transportpce.olm.power;
10
11 import java.util.List;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.mdsal.binding.api.DataBroker;
17 import org.opendaylight.mdsal.binding.api.MountPoint;
18 import org.opendaylight.mdsal.binding.api.MountPointService;
19 import org.opendaylight.transportpce.common.StringConstants;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
21 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
22 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
23 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
24 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl710;
25 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
26 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
27 import org.opendaylight.transportpce.common.mapping.MappingUtils;
28 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
29 import org.opendaylight.transportpce.common.mapping.PortMapping;
30 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
31 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
32 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
33 import org.opendaylight.transportpce.common.mapping.PortMappingVersion710;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
35 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
36 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
37 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
38 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
39 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
40 import org.opendaylight.transportpce.olm.stub.MountPointStub;
41 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
42 import org.opendaylight.transportpce.olm.util.TransactionUtils;
43 import org.opendaylight.transportpce.test.AbstractTest;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
46 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
47
48 public class PowerMgmtTest extends AbstractTest {
49     private MountPoint mountPoint;
50     private MountPointService mountPointService;
51     private DeviceTransactionManager deviceTransactionManager;
52     private CrossConnect crossConnect;
53     private OpenRoadmInterfaces openRoadmInterfaces;
54     private PortMapping portMapping;
55     private PowerMgmt powerMgmt;
56     private CrossConnectImpl121 crossConnectImpl121;
57     private CrossConnectImpl221 crossConnectImpl22;
58     private CrossConnectImpl710 crossConnectImpl710;
59     private MappingUtils mappingUtils;
60     private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
61     private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
62     private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710;
63     private PortMappingVersion710 portMappingVersion710;
64     private PortMappingVersion221 portMappingVersion22;
65     private PortMappingVersion121 portMappingVersion121;
66     private DataBroker dataBroker;
67
68     @Before
69     public void setUp() {
70         dataBroker = this.getNewDataBroker();
71         this.mountPoint = new MountPointStub(dataBroker);
72         this.mountPointService = new MountPointServiceStub(mountPoint);
73         // this.mappingUtils = new MappingUtilsImpl(getDataBroker());
74         this.mappingUtils = Mockito.spy(new MappingUtilsImpl(dataBroker));
75         Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
76                 .getOpenRoadmVersion(Mockito.anyString());
77         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
78         this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
79         this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
80         this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
81                 this.crossConnectImpl22, this.crossConnectImpl710);
82         this.portMappingVersion22 = new PortMappingVersion221(dataBroker, deviceTransactionManager);
83         this.portMappingVersion121 = new PortMappingVersion121(dataBroker, deviceTransactionManager);
84         this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
85                 this.portMappingVersion22, this.portMappingVersion121);
86         this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
87         this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager, this.portMapping,
88             this.portMappingVersion22);
89         this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager);
90         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
91                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
92             this.openRoadmInterfacesImpl710);
93         this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
94         this.portMapping = Mockito.spy(this.portMapping);
95         this.powerMgmt = new PowerMgmtImpl(this.dataBroker, this.openRoadmInterfaces, this.crossConnect,
96                 this.deviceTransactionManager);
97     }
98
99     @Test
100     public void testSetPower() {
101         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
102         boolean output = this.powerMgmt.setPower(input);
103         Assert.assertEquals(true, output);
104     }
105
106     @Test
107     public void testSetPower2() {
108         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
109         boolean output = this.powerMgmt.setPower(input);
110         Assert.assertEquals(true, output);
111     }
112
113     @Test
114     public void testSetPower3() {
115         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
116         boolean output = this.powerMgmt.setPower(input);
117         Assert.assertEquals(true, output);
118     }
119
120     @Test
121     public void testSetPower4() {
122         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
123         boolean output = this.powerMgmt.setPower(input);
124         Assert.assertEquals(true, output);
125     }
126
127     @Test
128     public void testPowerTurnDown() {
129         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
130         boolean output = this.powerMgmt.powerTurnDown(input);
131         Assert.assertEquals(true, output);
132     }
133
134     @Test
135     public void testPowerTurnDown2() {
136         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
137         boolean output = this.powerMgmt.powerTurnDown(input);
138         Assert.assertEquals(false, output);
139     }
140
141     @Test
142     public void testPowerTurnDown3() {
143         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput3();
144         boolean output = this.powerMgmt.powerTurnDown(input);
145         Assert.assertEquals(true, output);
146     }
147
148     @Test
149     public void testPowerTurnDown4() {
150         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput4();
151         boolean output = this.powerMgmt.powerTurnDown(input);
152         Assert.assertEquals(false, output);
153     }
154
155     @Test
156     public void testSetPowerPresentNodes() throws InterruptedException {
157         List<NodeId> nodes = TransactionUtils.getNodeIds();
158         for (NodeId nodeId : nodes) {
159             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
160             Thread.sleep(1000);
161         }
162         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
163         boolean output = this.powerMgmt.setPower(input);
164         Assert.assertEquals(true, output);
165     }
166
167     @Test
168     public void testSetPowerPresentNodes2() throws InterruptedException {
169         List<NodeId> nodes = TransactionUtils.getNodeIds();
170         for (NodeId nodeId : nodes) {
171             TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.dataBroker, null);
172             Thread.sleep(500);
173         }
174         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
175         boolean output = this.powerMgmt.setPower(input);
176         Assert.assertEquals(true, output);
177     }
178
179     @Test
180     public void testSetPowerPresentNodes3() throws InterruptedException {
181         List<NodeId> nodes = TransactionUtils.getNodeIds();
182         for (NodeId nodeId : nodes) {
183             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
184             Thread.sleep(500);
185         }
186         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
187         boolean output = this.powerMgmt.setPower(input);
188         Assert.assertEquals(true, output);
189     }
190     /*
191     @Test
192     public void testSetPowerPresentNodes31() throws InterruptedException {
193         List<NodeId> nodes = TransactionUtils.getNodeIds();
194         for (NodeId nodeId : nodes) {
195             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
196             Thread.sleep(500);
197         }
198         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
199         boolean output = this.powerMgmt.setPower(input);
200         Assert.assertEquals(false, output);
201     }*/
202
203     @Test
204     public void testSetPowerPresentNodes312() throws InterruptedException {
205         List<NodeId> nodes = TransactionUtils.getNodeIds();
206         for (NodeId nodeId : nodes) {
207             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, "deg");
208             Thread.sleep(500);
209         }
210         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
211         boolean output = this.powerMgmt.setPower(input);
212         Assert.assertEquals(true, output);
213     }
214
215     @Test
216     public void testSetPowerPresentNodes32() throws InterruptedException {
217         List<NodeId> nodes = TransactionUtils.getNodeIds();
218         for (NodeId nodeId : nodes) {
219             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
220             Thread.sleep(500);
221         }
222         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
223         boolean output = this.powerMgmt.setPower(input);
224         Assert.assertEquals(true, output);
225     }
226
227     @Test
228     public void testSetPowerPresentNodes4() throws InterruptedException {
229         List<NodeId> nodes = TransactionUtils.getNodeIds();
230         for (NodeId nodeId : nodes) {
231             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "network");
232             Thread.sleep(500);
233         }
234         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
235         boolean output = this.powerMgmt.setPower(input);
236         Assert.assertEquals(true, output);
237     }
238
239     /*
240     @Test
241     public void testSetPowerPresentNodes41() throws InterruptedException {
242         List<NodeId> nodes = TransactionUtils.getNodeIds();
243         for (NodeId nodeId : nodes) {
244             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
245             Thread.sleep(500);
246         }
247         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
248         boolean output = this.powerMgmt.setPower(input);
249         Assert.assertEquals(false, output);
250     }*/
251
252     @Test
253     public void testSetPowerPresentNodes42() throws InterruptedException {
254         List<NodeId> nodes = TransactionUtils.getNodeIds();
255         for (NodeId nodeId : nodes) {
256             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
257             Thread.sleep(500);
258         }
259         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
260         boolean output = this.powerMgmt.setPower(input);
261         Assert.assertEquals(true, output);
262     }
263
264     @Test
265     public void testSetPowerPresentNodes422() throws InterruptedException {
266         List<NodeId> nodes = TransactionUtils.getNodeIds();
267         for (NodeId nodeId : nodes) {
268             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
269             Thread.sleep(500);
270         }
271         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
272         boolean output = this.powerMgmt.setPower(input);
273         Assert.assertEquals(true, output);
274     }
275
276     @Test
277     public void testSetPowerPresentNodes43() throws InterruptedException {
278         List<NodeId> nodes = TransactionUtils.getNodeIds();
279         for (NodeId nodeId : nodes) {
280             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
281             Thread.sleep(500);
282         }
283         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
284         boolean output = this.powerMgmt.setPower(input);
285         Assert.assertEquals(true, output);
286     }
287
288 }