Add node-info in portmapping structure
[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.portMappingVersion121);
83         this.portMapping = Mockito.spy(this.portMapping);
84         this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
85             this.deviceTransactionManager);
86     }
87
88     @Test
89     public void testSetPower() {
90
91         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
92         boolean output = this.powerMgmt.setPower(input);
93         Assert.assertEquals(true, output);
94
95     }
96
97     @Test
98     public void testSetPower2() {
99
100         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
101         boolean output = this.powerMgmt.setPower(input);
102         Assert.assertEquals(true, output);
103
104     }
105
106     @Test
107     public void testSetPower3() {
108
109         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
110         boolean output = this.powerMgmt.setPower(input);
111         Assert.assertEquals(true, output);
112
113     }
114
115     @Test
116     public void testSetPower4() {
117
118         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
119         boolean output = this.powerMgmt.setPower(input);
120         Assert.assertEquals(true, output);
121
122     }
123
124     @Test
125     public void testSetPowerPresentNodes() throws InterruptedException {
126         List<NodeId> nodes = TransactionUtils.getNodeIds();
127         for (NodeId nodeId : nodes) {
128             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
129             Thread.sleep(500);
130         }
131         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
132         boolean output = this.powerMgmt.setPower(input);
133         Assert.assertEquals(true, output);
134     }
135
136     @Test
137     public void testSetPowerPresentNodes2() throws InterruptedException {
138         List<NodeId> nodes = TransactionUtils.getNodeIds();
139         for (NodeId nodeId : nodes) {
140             TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
141             Thread.sleep(500);
142         }
143         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
144         boolean output = this.powerMgmt.setPower(input);
145         Assert.assertEquals(true, output);
146     }
147
148     @Test
149     public void testSetPowerPresentNodes3() throws InterruptedException {
150         List<NodeId> nodes = TransactionUtils.getNodeIds();
151         for (NodeId nodeId : nodes) {
152             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
153             Thread.sleep(500);
154         }
155         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
156         boolean output = this.powerMgmt.setPower(input);
157         Assert.assertEquals(true, output);
158     }
159     /*
160     @Test
161     public void testSetPowerPresentNodes31() throws InterruptedException {
162         List<NodeId> nodes = TransactionUtils.getNodeIds();
163         for (NodeId nodeId : nodes) {
164             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
165             Thread.sleep(500);
166         }
167         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
168         boolean output = this.powerMgmt.setPower(input);
169         Assert.assertEquals(false, output);
170     }*/
171
172     @Test
173     public void testSetPowerPresentNodes312() throws InterruptedException {
174         List<NodeId> nodes = TransactionUtils.getNodeIds();
175         for (NodeId nodeId : nodes) {
176             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
177             Thread.sleep(500);
178         }
179         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
180         boolean output = this.powerMgmt.setPower(input);
181         Assert.assertEquals(true, output);
182     }
183
184     @Test
185     public void testSetPowerPresentNodes32() throws InterruptedException {
186         List<NodeId> nodes = TransactionUtils.getNodeIds();
187         for (NodeId nodeId : nodes) {
188             TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
189             Thread.sleep(500);
190         }
191         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
192         boolean output = this.powerMgmt.setPower(input);
193         Assert.assertEquals(true, output);
194     }
195
196     @Test
197     public void testSetPowerPresentNodes4() throws InterruptedException {
198         List<NodeId> nodes = TransactionUtils.getNodeIds();
199         for (NodeId nodeId : nodes) {
200             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
201             Thread.sleep(500);
202         }
203         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
204         boolean output = this.powerMgmt.setPower(input);
205         Assert.assertEquals(true, output);
206     }
207
208     /*
209     @Test
210     public void testSetPowerPresentNodes41() throws InterruptedException {
211         List<NodeId> nodes = TransactionUtils.getNodeIds();
212         for (NodeId nodeId : nodes) {
213             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
214             Thread.sleep(500);
215         }
216         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
217         boolean output = this.powerMgmt.setPower(input);
218         Assert.assertEquals(false, output);
219     }*/
220
221     @Test
222     public void testSetPowerPresentNodes42() throws InterruptedException {
223         List<NodeId> nodes = TransactionUtils.getNodeIds();
224         for (NodeId nodeId : nodes) {
225             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
226             Thread.sleep(500);
227         }
228         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
229         boolean output = this.powerMgmt.setPower(input);
230         Assert.assertEquals(true, output);
231     }
232
233     @Test
234     public void testSetPowerPresentNodes422() throws InterruptedException {
235         List<NodeId> nodes = TransactionUtils.getNodeIds();
236         for (NodeId nodeId : nodes) {
237             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
238             Thread.sleep(500);
239         }
240         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
241         boolean output = this.powerMgmt.setPower(input);
242         Assert.assertEquals(true, output);
243     }
244
245     @Test
246     public void testSetPowerPresentNodes43() throws InterruptedException {
247         List<NodeId> nodes = TransactionUtils.getNodeIds();
248         for (NodeId nodeId : nodes) {
249             TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
250             Thread.sleep(500);
251         }
252         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
253         boolean output = this.powerMgmt.setPower(input);
254         Assert.assertEquals(true, output);
255     }
256
257 }