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