2 * Copyright © 2018 Orange, Inc. and others. All rights reserved.
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
9 package org.opendaylight.transportpce.olm.power;
11 import java.util.List;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Ignore;
15 import org.junit.Test;
16 import org.mockito.Mockito;
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.openroadminterfaces.OpenRoadmInterfaces;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
35 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
36 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
37 import org.opendaylight.transportpce.olm.stub.MountPointStub;
38 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
39 import org.opendaylight.transportpce.olm.util.TransactionUtils;
40 import org.opendaylight.transportpce.test.AbstractTest;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownInput;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
46 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 PortMappingVersion221 portMappingVersion22;
61 private PortMappingVersion121 portMappingVersion121;
65 this.mountPoint = new MountPointStub(this.getDataBroker());
66 this.mountPointService = new MountPointServiceStub(mountPoint);
67 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
68 this.mappingUtils = Mockito.spy(new MappingUtilsImpl(getDataBroker()));
69 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
70 .getOpenRoadmVersion(Mockito.anyString());
71 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
72 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
73 this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
74 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
75 this.crossConnectImpl22);
76 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
77 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
78 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
79 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
80 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
81 this.portMappingVersion22 =
82 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
83 this.portMappingVersion121 =
84 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
85 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.portMappingVersion121);
86 this.portMapping = Mockito.spy(this.portMapping);
87 this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
88 this.deviceTransactionManager);
92 public void testSetPower() {
93 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
94 boolean output = this.powerMgmt.setPower(input);
95 Assert.assertEquals(true, output);
99 public void testSetPower2() {
100 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
101 boolean output = this.powerMgmt.setPower(input);
102 Assert.assertEquals(true, output);
106 public void testSetPower3() {
107 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
108 boolean output = this.powerMgmt.setPower(input);
109 Assert.assertEquals(true, output);
113 public void testSetPower4() {
114 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
115 boolean output = this.powerMgmt.setPower(input);
116 Assert.assertEquals(true, output);
120 public void testPowerTurnDown() {
121 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
122 boolean output = this.powerMgmt.powerTurnDown(input);
123 Assert.assertEquals(true, output);
127 public void testPowerTurnDown2() {
128 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
129 boolean output = this.powerMgmt.powerTurnDown(input);
130 Assert.assertEquals(false, output);
134 public void testPowerTurnDown3() {
135 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput3();
136 boolean output = this.powerMgmt.powerTurnDown(input);
137 Assert.assertEquals(true, output);
141 public void testPowerTurnDown4() {
142 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput4();
143 boolean output = this.powerMgmt.powerTurnDown(input);
144 Assert.assertEquals(false, output);
148 public void testSetPowerPresentNodes() throws InterruptedException {
149 List<NodeId> nodes = TransactionUtils.getNodeIds();
150 for (NodeId nodeId : nodes) {
151 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
154 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
155 boolean output = this.powerMgmt.setPower(input);
156 Assert.assertEquals(true, output);
160 public void testSetPowerPresentNodes2() throws InterruptedException {
161 List<NodeId> nodes = TransactionUtils.getNodeIds();
162 for (NodeId nodeId : nodes) {
163 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
166 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
167 boolean output = this.powerMgmt.setPower(input);
168 Assert.assertEquals(true, output);
172 public void testSetPowerPresentNodes3() throws InterruptedException {
173 List<NodeId> nodes = TransactionUtils.getNodeIds();
174 for (NodeId nodeId : nodes) {
175 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
178 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
179 boolean output = this.powerMgmt.setPower(input);
180 Assert.assertEquals(true, output);
184 public void testSetPowerPresentNodes31() throws InterruptedException {
185 List<NodeId> nodes = TransactionUtils.getNodeIds();
186 for (NodeId nodeId : nodes) {
187 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
190 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
191 boolean output = this.powerMgmt.setPower(input);
192 Assert.assertEquals(false, output);
196 public void testSetPowerPresentNodes312() throws InterruptedException {
197 List<NodeId> nodes = TransactionUtils.getNodeIds();
198 for (NodeId nodeId : nodes) {
199 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
202 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
203 boolean output = this.powerMgmt.setPower(input);
204 Assert.assertEquals(true, output);
208 public void testSetPowerPresentNodes32() throws InterruptedException {
209 List<NodeId> nodes = TransactionUtils.getNodeIds();
210 for (NodeId nodeId : nodes) {
211 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
214 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
215 boolean output = this.powerMgmt.setPower(input);
216 Assert.assertEquals(true, output);
220 public void testSetPowerPresentNodes4() throws InterruptedException {
221 List<NodeId> nodes = TransactionUtils.getNodeIds();
222 for (NodeId nodeId : nodes) {
223 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
226 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
227 boolean output = this.powerMgmt.setPower(input);
228 Assert.assertEquals(true, output);
233 public void testSetPowerPresentNodes41() throws InterruptedException {
234 List<NodeId> nodes = TransactionUtils.getNodeIds();
235 for (NodeId nodeId : nodes) {
236 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
239 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
240 boolean output = this.powerMgmt.setPower(input);
241 Assert.assertEquals(false, output);
245 public void testSetPowerPresentNodes42() throws InterruptedException {
246 List<NodeId> nodes = TransactionUtils.getNodeIds();
247 for (NodeId nodeId : nodes) {
248 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
251 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
252 boolean output = this.powerMgmt.setPower(input);
253 Assert.assertEquals(true, output);
257 public void testSetPowerPresentNodes422() throws InterruptedException {
258 List<NodeId> nodes = TransactionUtils.getNodeIds();
259 for (NodeId nodeId : nodes) {
260 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
263 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
264 boolean output = this.powerMgmt.setPower(input);
265 Assert.assertEquals(true, output);
269 public void testSetPowerPresentNodes43() throws InterruptedException {
270 List<NodeId> nodes = TransactionUtils.getNodeIds();
271 for (NodeId nodeId : nodes) {
272 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
275 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
276 boolean output = this.powerMgmt.setPower(input);
277 Assert.assertEquals(true, output);