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;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
18 import org.opendaylight.controller.md.sal.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.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 MappingUtils mappingUtils;
54 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
55 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl221;
56 private PortMappingVersion221 portMappingVersion22;
57 private PortMappingVersion121 portMappingVersion121;
58 private CrossConnectImpl121 crossConnectImpl121;
59 private CrossConnectImpl221 crossConnectImpl221;
63 this.mountPoint = new MountPointStub(this.getDataBroker());
64 this.mountPointService = new MountPointServiceStub(mountPoint);
65 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
66 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
67 this.mappingUtils = Mockito.spy(this.mappingUtils);
68 this.crossConnectImpl121 = new CrossConnectImpl121(this.deviceTransactionManager);
69 this.crossConnectImpl221 = new CrossConnectImpl221(this.deviceTransactionManager);
70 this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager, this.mappingUtils,
71 this.crossConnectImpl121, this.crossConnectImpl221);
72 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(this.deviceTransactionManager);
73 this.openRoadmInterfacesImpl221 = new OpenRoadmInterfacesImpl221(this.deviceTransactionManager);
74 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl(deviceTransactionManager, mappingUtils,
75 openRoadmInterfacesImpl121, openRoadmInterfacesImpl221);
76 this.portMappingVersion22 =
77 new PortMappingVersion221(getDataBroker(), this.deviceTransactionManager, this.openRoadmInterfaces);
78 this.portMappingVersion121 =
79 new PortMappingVersion121(getDataBroker(), this.deviceTransactionManager, this.openRoadmInterfaces);
80 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
81 this.portMappingVersion121);
82 this.powerMgmt = new PowerMgmt(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
83 this.deviceTransactionManager);
87 public void testSetPower() {
89 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
90 boolean output = this.powerMgmt.setPower(input);
91 Assert.assertEquals(true, output);
96 public void testSetPower2() {
98 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
99 boolean output = this.powerMgmt.setPower(input);
100 Assert.assertEquals(true, output);
105 public void testSetPower3() {
107 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
108 boolean output = this.powerMgmt.setPower(input);
109 Assert.assertEquals(true, output);
114 public void testSetPower4() {
116 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
117 boolean output = this.powerMgmt.setPower(input);
118 Assert.assertEquals(true, output);
123 public void testSetPowerPresentNodes() throws InterruptedException {
124 List<NodeId> nodes = TransactionUtils.getNodeIds();
125 for (NodeId nodeId : nodes) {
126 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
129 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
130 boolean output = this.powerMgmt.setPower(input);
131 Assert.assertEquals(true, output);
135 public void testSetPowerPresentNodes2() throws InterruptedException {
136 List<NodeId> nodes = TransactionUtils.getNodeIds();
137 for (NodeId nodeId : nodes) {
138 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
141 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
142 boolean output = this.powerMgmt.setPower(input);
143 Assert.assertEquals(true, output);
147 public void testSetPowerPresentNodes3() throws InterruptedException {
148 List<NodeId> nodes = TransactionUtils.getNodeIds();
149 for (NodeId nodeId : nodes) {
150 TransactionUtils.writeNodeTransaction3(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 testSetPowerPresentNodes31() throws InterruptedException {
160 List<NodeId> nodes = TransactionUtils.getNodeIds();
161 for (NodeId nodeId : nodes) {
162 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
165 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
166 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
167 .getOpenRoadmVersion("node 1");
168 boolean output = this.powerMgmt.setPower(input);
169 Assert.assertEquals(false, output);
173 public void testSetPowerPresentNodes312() throws InterruptedException {
174 List<NodeId> nodes = TransactionUtils.getNodeIds();
175 for (NodeId nodeId : nodes) {
176 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
179 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
180 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
181 .getOpenRoadmVersion("node 1");
182 boolean output = this.powerMgmt.setPower(input);
183 Assert.assertEquals(true, output);
187 public void testSetPowerPresentNodes32() throws InterruptedException {
188 List<NodeId> nodes = TransactionUtils.getNodeIds();
189 for (NodeId nodeId : nodes) {
190 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
193 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
194 boolean output = this.powerMgmt.setPower(input);
195 Assert.assertEquals(true, output);
199 public void testSetPowerPresentNodes4() throws InterruptedException {
200 List<NodeId> nodes = TransactionUtils.getNodeIds();
201 for (NodeId nodeId : nodes) {
202 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
205 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
206 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(this.mappingUtils)
207 .getOpenRoadmVersion("node 1");
208 boolean output = this.powerMgmt.setPower(input);
209 Assert.assertEquals(true, output);
213 public void testSetPowerPresentNodes41() throws InterruptedException {
214 List<NodeId> nodes = TransactionUtils.getNodeIds();
215 for (NodeId nodeId : nodes) {
216 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
219 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
220 boolean output = this.powerMgmt.setPower(input);
221 Assert.assertEquals(false, output);
225 public void testSetPowerPresentNodes42() throws InterruptedException {
226 List<NodeId> nodes = TransactionUtils.getNodeIds();
227 for (NodeId nodeId : nodes) {
228 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
231 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
232 boolean output = this.powerMgmt.setPower(input);
233 Assert.assertEquals(true, output);
237 public void testSetPowerPresentNodes422() throws InterruptedException {
238 List<NodeId> nodes = TransactionUtils.getNodeIds();
239 for (NodeId nodeId : nodes) {
240 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
243 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
244 boolean output = this.powerMgmt.setPower(input);
245 Assert.assertEquals(true, output);
249 public void testSetPowerPresentNodes43() throws InterruptedException {
250 List<NodeId> nodes = TransactionUtils.getNodeIds();
251 for (NodeId nodeId : nodes) {
252 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
255 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
256 boolean output = this.powerMgmt.setPower(input);
257 Assert.assertEquals(true, output);