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.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;
44 public class PowerMgmtTest extends AbstractTest {
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;
63 this.mountPoint = new MountPointStub(this.getDataBroker());
64 this.mountPointService = new MountPointServiceStub(mountPoint);
65 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
66 this.mappingUtils = Mockito.spy(MappingUtils.class);
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(), this.portMappingVersion22, this.portMappingVersion121);
84 this.portMapping = Mockito.spy(this.portMapping);
85 this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
86 this.deviceTransactionManager);
90 public void testSetPower() {
92 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
93 boolean output = this.powerMgmt.setPower(input);
94 Assert.assertEquals(true, output);
99 public void testSetPower2() {
101 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
102 boolean output = this.powerMgmt.setPower(input);
103 Assert.assertEquals(true, output);
108 public void testSetPower3() {
110 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
111 boolean output = this.powerMgmt.setPower(input);
112 Assert.assertEquals(true, output);
117 public void testSetPower4() {
119 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
120 boolean output = this.powerMgmt.setPower(input);
121 Assert.assertEquals(true, output);
126 public void testPowerTurnDown() {
127 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
128 boolean output = this.powerMgmt.powerTurnDown(input);
129 Assert.assertEquals(true, output);
133 public void testPowerTurnDown2() {
134 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
135 boolean output = this.powerMgmt.powerTurnDown(input);
136 Assert.assertEquals(false, output);
140 public void testPowerTurnDown3() {
141 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput3();
142 boolean output = this.powerMgmt.powerTurnDown(input);
143 Assert.assertEquals(true, output);
147 public void testPowerTurnDown4() {
148 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput4();
149 boolean output = this.powerMgmt.powerTurnDown(input);
150 Assert.assertEquals(false, output);
154 public void testSetPowerPresentNodes() throws InterruptedException {
155 List<NodeId> nodes = TransactionUtils.getNodeIds();
156 for (NodeId nodeId : nodes) {
157 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
160 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
161 boolean output = this.powerMgmt.setPower(input);
162 Assert.assertEquals(true, output);
166 public void testSetPowerPresentNodes2() throws InterruptedException {
167 List<NodeId> nodes = TransactionUtils.getNodeIds();
168 for (NodeId nodeId : nodes) {
169 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
172 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
173 boolean output = this.powerMgmt.setPower(input);
174 Assert.assertEquals(true, output);
178 public void testSetPowerPresentNodes3() throws InterruptedException {
179 List<NodeId> nodes = TransactionUtils.getNodeIds();
180 for (NodeId nodeId : nodes) {
181 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
184 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
185 boolean output = this.powerMgmt.setPower(input);
186 Assert.assertEquals(true, output);
190 public void testSetPowerPresentNodes31() throws InterruptedException {
191 List<NodeId> nodes = TransactionUtils.getNodeIds();
192 for (NodeId nodeId : nodes) {
193 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
196 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
197 boolean output = this.powerMgmt.setPower(input);
198 Assert.assertEquals(false, output);
202 public void testSetPowerPresentNodes312() throws InterruptedException {
203 List<NodeId> nodes = TransactionUtils.getNodeIds();
204 for (NodeId nodeId : nodes) {
205 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
208 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
209 boolean output = this.powerMgmt.setPower(input);
210 Assert.assertEquals(true, output);
214 public void testSetPowerPresentNodes32() throws InterruptedException {
215 List<NodeId> nodes = TransactionUtils.getNodeIds();
216 for (NodeId nodeId : nodes) {
217 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
220 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
221 boolean output = this.powerMgmt.setPower(input);
222 Assert.assertEquals(true, output);
226 public void testSetPowerPresentNodes4() throws InterruptedException {
227 List<NodeId> nodes = TransactionUtils.getNodeIds();
228 for (NodeId nodeId : nodes) {
229 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
232 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
233 boolean output = this.powerMgmt.setPower(input);
234 Assert.assertEquals(true, output);
239 public void testSetPowerPresentNodes41() throws InterruptedException {
240 List<NodeId> nodes = TransactionUtils.getNodeIds();
241 for (NodeId nodeId : nodes) {
242 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
245 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
246 boolean output = this.powerMgmt.setPower(input);
247 Assert.assertEquals(false, output);
251 public void testSetPowerPresentNodes42() throws InterruptedException {
252 List<NodeId> nodes = TransactionUtils.getNodeIds();
253 for (NodeId nodeId : nodes) {
254 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
257 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
258 boolean output = this.powerMgmt.setPower(input);
259 Assert.assertEquals(true, output);
263 public void testSetPowerPresentNodes422() throws InterruptedException {
264 List<NodeId> nodes = TransactionUtils.getNodeIds();
265 for (NodeId nodeId : nodes) {
266 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
269 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
270 boolean output = this.powerMgmt.setPower(input);
271 Assert.assertEquals(true, output);
275 public void testSetPowerPresentNodes43() throws InterruptedException {
276 List<NodeId> nodes = TransactionUtils.getNodeIds();
277 for (NodeId nodeId : nodes) {
278 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
281 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
282 boolean output = this.powerMgmt.setPower(input);
283 Assert.assertEquals(true, output);