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(new MappingUtilsImpl(getDataBroker()));
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(),
84 this.portMappingVersion22, this.portMappingVersion121);
85 this.portMapping = Mockito.spy(this.portMapping);
86 this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
87 this.deviceTransactionManager);
91 public void testSetPower() {
92 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
93 boolean output = this.powerMgmt.setPower(input);
94 Assert.assertEquals(true, output);
98 public void testSetPower2() {
99 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
100 boolean output = this.powerMgmt.setPower(input);
101 Assert.assertEquals(true, output);
105 public void testSetPower3() {
106 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
107 boolean output = this.powerMgmt.setPower(input);
108 Assert.assertEquals(true, output);
112 public void testSetPower4() {
113 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
114 boolean output = this.powerMgmt.setPower(input);
115 Assert.assertEquals(true, output);
119 public void testPowerTurnDown() {
120 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
121 boolean output = this.powerMgmt.powerTurnDown(input);
122 Assert.assertEquals(true, output);
126 public void testPowerTurnDown2() {
127 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
128 boolean output = this.powerMgmt.powerTurnDown(input);
129 Assert.assertEquals(false, output);
133 public void testPowerTurnDown3() {
134 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput3();
135 boolean output = this.powerMgmt.powerTurnDown(input);
136 Assert.assertEquals(true, output);
140 public void testPowerTurnDown4() {
141 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput4();
142 boolean output = this.powerMgmt.powerTurnDown(input);
143 Assert.assertEquals(false, output);
147 public void testSetPowerPresentNodes() throws InterruptedException {
148 List<NodeId> nodes = TransactionUtils.getNodeIds();
149 for (NodeId nodeId : nodes) {
150 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
153 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
154 boolean output = this.powerMgmt.setPower(input);
155 Assert.assertEquals(true, output);
159 public void testSetPowerPresentNodes2() throws InterruptedException {
160 List<NodeId> nodes = TransactionUtils.getNodeIds();
161 for (NodeId nodeId : nodes) {
162 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
165 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
166 boolean output = this.powerMgmt.setPower(input);
167 Assert.assertEquals(true, output);
171 public void testSetPowerPresentNodes3() throws InterruptedException {
172 List<NodeId> nodes = TransactionUtils.getNodeIds();
173 for (NodeId nodeId : nodes) {
174 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
177 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
178 boolean output = this.powerMgmt.setPower(input);
179 Assert.assertEquals(true, output);
183 public void testSetPowerPresentNodes31() throws InterruptedException {
184 List<NodeId> nodes = TransactionUtils.getNodeIds();
185 for (NodeId nodeId : nodes) {
186 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
189 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
190 boolean output = this.powerMgmt.setPower(input);
191 Assert.assertEquals(false, output);
195 public void testSetPowerPresentNodes312() throws InterruptedException {
196 List<NodeId> nodes = TransactionUtils.getNodeIds();
197 for (NodeId nodeId : nodes) {
198 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
201 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
202 boolean output = this.powerMgmt.setPower(input);
203 Assert.assertEquals(true, output);
207 public void testSetPowerPresentNodes32() throws InterruptedException {
208 List<NodeId> nodes = TransactionUtils.getNodeIds();
209 for (NodeId nodeId : nodes) {
210 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
213 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
214 boolean output = this.powerMgmt.setPower(input);
215 Assert.assertEquals(true, output);
219 public void testSetPowerPresentNodes4() throws InterruptedException {
220 List<NodeId> nodes = TransactionUtils.getNodeIds();
221 for (NodeId nodeId : nodes) {
222 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
225 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
226 boolean output = this.powerMgmt.setPower(input);
227 Assert.assertEquals(true, output);
232 public void testSetPowerPresentNodes41() throws InterruptedException {
233 List<NodeId> nodes = TransactionUtils.getNodeIds();
234 for (NodeId nodeId : nodes) {
235 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
238 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
239 boolean output = this.powerMgmt.setPower(input);
240 Assert.assertEquals(false, output);
244 public void testSetPowerPresentNodes42() throws InterruptedException {
245 List<NodeId> nodes = TransactionUtils.getNodeIds();
246 for (NodeId nodeId : nodes) {
247 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
250 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
251 boolean output = this.powerMgmt.setPower(input);
252 Assert.assertEquals(true, output);
256 public void testSetPowerPresentNodes422() throws InterruptedException {
257 List<NodeId> nodes = TransactionUtils.getNodeIds();
258 for (NodeId nodeId : nodes) {
259 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
262 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
263 boolean output = this.powerMgmt.setPower(input);
264 Assert.assertEquals(true, output);
268 public void testSetPowerPresentNodes43() throws InterruptedException {
269 List<NodeId> nodes = TransactionUtils.getNodeIds();
270 for (NodeId nodeId : nodes) {
271 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
274 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
275 boolean output = this.powerMgmt.setPower(input);
276 Assert.assertEquals(true, output);