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;
45 public class PowerMgmtTest extends AbstractTest {
47 private MountPoint mountPoint;
48 private MountPointService mountPointService;
49 private DeviceTransactionManager deviceTransactionManager;
50 private CrossConnect crossConnect;
51 private OpenRoadmInterfaces openRoadmInterfaces;
52 private PortMapping portMapping;
53 private PowerMgmt powerMgmt;
54 private CrossConnectImpl121 crossConnectImpl121;
55 private CrossConnectImpl221 crossConnectImpl22;
56 private MappingUtils mappingUtils;
57 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
58 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
59 private PortMappingVersion221 portMappingVersion22;
60 private PortMappingVersion121 portMappingVersion121;
64 this.mountPoint = new MountPointStub(this.getDataBroker());
65 this.mountPointService = new MountPointServiceStub(mountPoint);
66 // this.mappingUtils = new MappingUtilsImpl(getDataBroker());
67 this.mappingUtils = Mockito.spy(new MappingUtilsImpl(getDataBroker()));
68 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
69 .getOpenRoadmVersion(Mockito.anyString());
70 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
71 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
72 this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
73 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
74 this.crossConnectImpl22);
75 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
76 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
77 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
78 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
79 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
80 this.portMappingVersion22 =
81 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
82 this.portMappingVersion121 =
83 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
84 this.portMapping = new PortMappingImpl(getDataBroker(),
85 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);