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