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(), 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() {
91 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
92 boolean output = this.powerMgmt.setPower(input);
93 Assert.assertEquals(true, output);
97 public void testSetPower2() {
98 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
99 boolean output = this.powerMgmt.setPower(input);
100 Assert.assertEquals(true, output);
104 public void testSetPower3() {
105 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
106 boolean output = this.powerMgmt.setPower(input);
107 Assert.assertEquals(true, output);
111 public void testSetPower4() {
112 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
113 boolean output = this.powerMgmt.setPower(input);
114 Assert.assertEquals(true, output);
118 public void testPowerTurnDown() {
119 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
120 boolean output = this.powerMgmt.powerTurnDown(input);
121 Assert.assertEquals(true, output);
125 public void testPowerTurnDown2() {
126 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
127 boolean output = this.powerMgmt.powerTurnDown(input);
128 Assert.assertEquals(false, output);
132 public void testPowerTurnDown3() {
133 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput3();
134 boolean output = this.powerMgmt.powerTurnDown(input);
135 Assert.assertEquals(true, output);
139 public void testPowerTurnDown4() {
140 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput4();
141 boolean output = this.powerMgmt.powerTurnDown(input);
142 Assert.assertEquals(false, output);
146 public void testSetPowerPresentNodes() throws InterruptedException {
147 List<NodeId> nodes = TransactionUtils.getNodeIds();
148 for (NodeId nodeId : nodes) {
149 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
152 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
153 boolean output = this.powerMgmt.setPower(input);
154 Assert.assertEquals(true, output);
158 public void testSetPowerPresentNodes2() throws InterruptedException {
159 List<NodeId> nodes = TransactionUtils.getNodeIds();
160 for (NodeId nodeId : nodes) {
161 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
164 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
165 boolean output = this.powerMgmt.setPower(input);
166 Assert.assertEquals(true, output);
170 public void testSetPowerPresentNodes3() throws InterruptedException {
171 List<NodeId> nodes = TransactionUtils.getNodeIds();
172 for (NodeId nodeId : nodes) {
173 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
176 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
177 boolean output = this.powerMgmt.setPower(input);
178 Assert.assertEquals(true, output);
182 public void testSetPowerPresentNodes31() throws InterruptedException {
183 List<NodeId> nodes = TransactionUtils.getNodeIds();
184 for (NodeId nodeId : nodes) {
185 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
188 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
189 boolean output = this.powerMgmt.setPower(input);
190 Assert.assertEquals(false, output);
194 public void testSetPowerPresentNodes312() throws InterruptedException {
195 List<NodeId> nodes = TransactionUtils.getNodeIds();
196 for (NodeId nodeId : nodes) {
197 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
200 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
201 boolean output = this.powerMgmt.setPower(input);
202 Assert.assertEquals(true, output);
206 public void testSetPowerPresentNodes32() throws InterruptedException {
207 List<NodeId> nodes = TransactionUtils.getNodeIds();
208 for (NodeId nodeId : nodes) {
209 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
212 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
213 boolean output = this.powerMgmt.setPower(input);
214 Assert.assertEquals(true, output);
218 public void testSetPowerPresentNodes4() throws InterruptedException {
219 List<NodeId> nodes = TransactionUtils.getNodeIds();
220 for (NodeId nodeId : nodes) {
221 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
224 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
225 boolean output = this.powerMgmt.setPower(input);
226 Assert.assertEquals(true, output);
231 public void testSetPowerPresentNodes41() throws InterruptedException {
232 List<NodeId> nodes = TransactionUtils.getNodeIds();
233 for (NodeId nodeId : nodes) {
234 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
237 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
238 boolean output = this.powerMgmt.setPower(input);
239 Assert.assertEquals(false, output);
243 public void testSetPowerPresentNodes42() throws InterruptedException {
244 List<NodeId> nodes = TransactionUtils.getNodeIds();
245 for (NodeId nodeId : nodes) {
246 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
249 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
250 boolean output = this.powerMgmt.setPower(input);
251 Assert.assertEquals(true, output);
255 public void testSetPowerPresentNodes422() throws InterruptedException {
256 List<NodeId> nodes = TransactionUtils.getNodeIds();
257 for (NodeId nodeId : nodes) {
258 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
261 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
262 boolean output = this.powerMgmt.setPower(input);
263 Assert.assertEquals(true, output);
267 public void testSetPowerPresentNodes43() throws InterruptedException {
268 List<NodeId> nodes = TransactionUtils.getNodeIds();
269 for (NodeId nodeId : nodes) {
270 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
273 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
274 boolean output = this.powerMgmt.setPower(input);
275 Assert.assertEquals(true, output);