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