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