Update 7.1 port-mapping data after inf delete
[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, this.portMapping,
90             this.portMappingVersion710);
91         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
92                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
93             this.openRoadmInterfacesImpl710);
94         this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
95         this.portMapping = Mockito.spy(this.portMapping);
96         this.powerMgmt = new PowerMgmtImpl(this.dataBroker, this.openRoadmInterfaces, this.crossConnect,
97                 this.deviceTransactionManager);
98     }
99
100     @Test
101     public void testSetPower() {
102         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
103         boolean output = this.powerMgmt.setPower(input);
104         Assert.assertEquals(true, output);
105     }
106
107     @Test
108     public void testSetPower2() {
109         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
110         boolean output = this.powerMgmt.setPower(input);
111         Assert.assertEquals(true, output);
112     }
113
114     @Test
115     public void testSetPower3() {
116         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
117         boolean output = this.powerMgmt.setPower(input);
118         Assert.assertEquals(true, output);
119     }
120
121     @Test
122     public void testSetPower4() {
123         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
124         boolean output = this.powerMgmt.setPower(input);
125         Assert.assertEquals(true, output);
126     }
127
128     @Test
129     public void testPowerTurnDown() {
130         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
131         boolean output = this.powerMgmt.powerTurnDown(input);
132         Assert.assertEquals(true, output);
133     }
134
135     @Test
136     public void testPowerTurnDown2() {
137         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
138         boolean output = this.powerMgmt.powerTurnDown(input);
139         Assert.assertEquals(false, output);
140     }
141
142     @Test
143     public void testPowerTurnDown3() {
144         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput3();
145         boolean output = this.powerMgmt.powerTurnDown(input);
146         Assert.assertEquals(true, output);
147     }
148
149     @Test
150     public void testPowerTurnDown4() {
151         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput4();
152         boolean output = this.powerMgmt.powerTurnDown(input);
153         Assert.assertEquals(false, output);
154     }
155
156     @Test
157     public void testSetPowerPresentNodes() throws InterruptedException {
158         List<NodeId> nodes = TransactionUtils.getNodeIds();
159         for (NodeId nodeId : nodes) {
160             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
161             Thread.sleep(1000);
162         }
163         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
164         boolean output = this.powerMgmt.setPower(input);
165         Assert.assertEquals(true, output);
166     }
167
168     @Test
169     public void testSetPowerPresentNodes2() throws InterruptedException {
170         List<NodeId> nodes = TransactionUtils.getNodeIds();
171         for (NodeId nodeId : nodes) {
172             TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.dataBroker, null);
173             Thread.sleep(500);
174         }
175         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
176         boolean output = this.powerMgmt.setPower(input);
177         Assert.assertEquals(true, output);
178     }
179
180     @Test
181     public void testSetPowerPresentNodes3() throws InterruptedException {
182         List<NodeId> nodes = TransactionUtils.getNodeIds();
183         for (NodeId nodeId : nodes) {
184             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
185             Thread.sleep(500);
186         }
187         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
188         boolean output = this.powerMgmt.setPower(input);
189         Assert.assertEquals(true, output);
190     }
191     /*
192     @Test
193     public void testSetPowerPresentNodes31() throws InterruptedException {
194         List<NodeId> nodes = TransactionUtils.getNodeIds();
195         for (NodeId nodeId : nodes) {
196             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
197             Thread.sleep(500);
198         }
199         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
200         boolean output = this.powerMgmt.setPower(input);
201         Assert.assertEquals(false, output);
202     }*/
203
204     @Test
205     public void testSetPowerPresentNodes312() throws InterruptedException {
206         List<NodeId> nodes = TransactionUtils.getNodeIds();
207         for (NodeId nodeId : nodes) {
208             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, "deg");
209             Thread.sleep(500);
210         }
211         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
212         boolean output = this.powerMgmt.setPower(input);
213         Assert.assertEquals(true, output);
214     }
215
216     @Test
217     public void testSetPowerPresentNodes32() throws InterruptedException {
218         List<NodeId> nodes = TransactionUtils.getNodeIds();
219         for (NodeId nodeId : nodes) {
220             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
221             Thread.sleep(500);
222         }
223         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
224         boolean output = this.powerMgmt.setPower(input);
225         Assert.assertEquals(true, output);
226     }
227
228     @Test
229     public void testSetPowerPresentNodes4() throws InterruptedException {
230         List<NodeId> nodes = TransactionUtils.getNodeIds();
231         for (NodeId nodeId : nodes) {
232             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "network");
233             Thread.sleep(500);
234         }
235         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
236         boolean output = this.powerMgmt.setPower(input);
237         Assert.assertEquals(true, output);
238     }
239
240     /*
241     @Test
242     public void testSetPowerPresentNodes41() throws InterruptedException {
243         List<NodeId> nodes = TransactionUtils.getNodeIds();
244         for (NodeId nodeId : nodes) {
245             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
246             Thread.sleep(500);
247         }
248         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
249         boolean output = this.powerMgmt.setPower(input);
250         Assert.assertEquals(false, output);
251     }*/
252
253     @Test
254     public void testSetPowerPresentNodes42() throws InterruptedException {
255         List<NodeId> nodes = TransactionUtils.getNodeIds();
256         for (NodeId nodeId : nodes) {
257             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
258             Thread.sleep(500);
259         }
260         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
261         boolean output = this.powerMgmt.setPower(input);
262         Assert.assertEquals(true, output);
263     }
264
265     @Test
266     public void testSetPowerPresentNodes422() throws InterruptedException {
267         List<NodeId> nodes = TransactionUtils.getNodeIds();
268         for (NodeId nodeId : nodes) {
269             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
270             Thread.sleep(500);
271         }
272         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
273         boolean output = this.powerMgmt.setPower(input);
274         Assert.assertEquals(true, output);
275     }
276
277     @Test
278     public void testSetPowerPresentNodes43() throws InterruptedException {
279         List<NodeId> nodes = TransactionUtils.getNodeIds();
280         for (NodeId nodeId : nodes) {
281             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
282             Thread.sleep(500);
283         }
284         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
285         boolean output = this.powerMgmt.setPower(input);
286         Assert.assertEquals(true, output);
287     }
288
289 }