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.DataBroker;
17 import org.opendaylight.mdsal.binding.api.MountPoint;
18 import org.opendaylight.mdsal.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.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownInput;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
45 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;
60 private DataBroker dataBroker;
64 dataBroker = this.getNewDataBroker();
65 this.mountPoint = new MountPointStub(dataBroker);
66 this.mountPointService = new MountPointServiceStub(mountPoint);
67 // this.mappingUtils = new MappingUtilsImpl(getDataBroker());
68 this.mappingUtils = Mockito.spy(new MappingUtilsImpl(dataBroker));
69 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
70 .getOpenRoadmVersion(Mockito.anyString());
71 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
72 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
73 this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
74 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
75 this.crossConnectImpl22);
76 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
77 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
78 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
79 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
80 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
81 this.portMappingVersion22 =
82 new PortMappingVersion221(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
83 this.portMappingVersion121 =
84 new PortMappingVersion121(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
85 this.portMapping = new PortMappingImpl(dataBroker,
86 this.portMappingVersion22, this.portMappingVersion121);
87 this.portMapping = Mockito.spy(this.portMapping);
88 this.powerMgmt = new PowerMgmtImpl(this.dataBroker, this.openRoadmInterfaces, this.crossConnect,
89 this.deviceTransactionManager);
93 public void testSetPower() {
94 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
95 boolean output = this.powerMgmt.setPower(input);
96 Assert.assertEquals(true, output);
100 public void testSetPower2() {
101 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
102 boolean output = this.powerMgmt.setPower(input);
103 Assert.assertEquals(true, output);
107 public void testSetPower3() {
108 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
109 boolean output = this.powerMgmt.setPower(input);
110 Assert.assertEquals(true, output);
114 public void testSetPower4() {
115 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
116 boolean output = this.powerMgmt.setPower(input);
117 Assert.assertEquals(true, output);
121 public void testPowerTurnDown() {
122 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
123 boolean output = this.powerMgmt.powerTurnDown(input);
124 Assert.assertEquals(true, output);
128 public void testPowerTurnDown2() {
129 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
130 boolean output = this.powerMgmt.powerTurnDown(input);
131 Assert.assertEquals(false, output);
135 public void testPowerTurnDown3() {
136 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput3();
137 boolean output = this.powerMgmt.powerTurnDown(input);
138 Assert.assertEquals(true, output);
142 public void testPowerTurnDown4() {
143 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput4();
144 boolean output = this.powerMgmt.powerTurnDown(input);
145 Assert.assertEquals(false, output);
149 public void testSetPowerPresentNodes() throws InterruptedException {
150 List<NodeId> nodes = TransactionUtils.getNodeIds();
151 for (NodeId nodeId : nodes) {
152 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
155 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
156 boolean output = this.powerMgmt.setPower(input);
157 Assert.assertEquals(true, output);
161 public void testSetPowerPresentNodes2() throws InterruptedException {
162 List<NodeId> nodes = TransactionUtils.getNodeIds();
163 for (NodeId nodeId : nodes) {
164 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.dataBroker, null);
167 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
168 boolean output = this.powerMgmt.setPower(input);
169 Assert.assertEquals(true, output);
173 public void testSetPowerPresentNodes3() throws InterruptedException {
174 List<NodeId> nodes = TransactionUtils.getNodeIds();
175 for (NodeId nodeId : nodes) {
176 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
179 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
180 boolean output = this.powerMgmt.setPower(input);
181 Assert.assertEquals(true, output);
185 public void testSetPowerPresentNodes31() throws InterruptedException {
186 List<NodeId> nodes = TransactionUtils.getNodeIds();
187 for (NodeId nodeId : nodes) {
188 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
191 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
192 boolean output = this.powerMgmt.setPower(input);
193 Assert.assertEquals(false, output);
197 public void testSetPowerPresentNodes312() throws InterruptedException {
198 List<NodeId> nodes = TransactionUtils.getNodeIds();
199 for (NodeId nodeId : nodes) {
200 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, "deg");
203 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
204 boolean output = this.powerMgmt.setPower(input);
205 Assert.assertEquals(true, output);
209 public void testSetPowerPresentNodes32() throws InterruptedException {
210 List<NodeId> nodes = TransactionUtils.getNodeIds();
211 for (NodeId nodeId : nodes) {
212 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
215 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
216 boolean output = this.powerMgmt.setPower(input);
217 Assert.assertEquals(true, output);
221 public void testSetPowerPresentNodes4() throws InterruptedException {
222 List<NodeId> nodes = TransactionUtils.getNodeIds();
223 for (NodeId nodeId : nodes) {
224 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "network");
227 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
228 boolean output = this.powerMgmt.setPower(input);
229 Assert.assertEquals(true, output);
234 public void testSetPowerPresentNodes41() throws InterruptedException {
235 List<NodeId> nodes = TransactionUtils.getNodeIds();
236 for (NodeId nodeId : nodes) {
237 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
240 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
241 boolean output = this.powerMgmt.setPower(input);
242 Assert.assertEquals(false, output);
246 public void testSetPowerPresentNodes42() throws InterruptedException {
247 List<NodeId> nodes = TransactionUtils.getNodeIds();
248 for (NodeId nodeId : nodes) {
249 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
252 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
253 boolean output = this.powerMgmt.setPower(input);
254 Assert.assertEquals(true, output);
258 public void testSetPowerPresentNodes422() throws InterruptedException {
259 List<NodeId> nodes = TransactionUtils.getNodeIds();
260 for (NodeId nodeId : nodes) {
261 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
264 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
265 boolean output = this.powerMgmt.setPower(input);
266 Assert.assertEquals(true, output);
270 public void testSetPowerPresentNodes43() throws InterruptedException {
271 List<NodeId> nodes = TransactionUtils.getNodeIds();
272 for (NodeId nodeId : nodes) {
273 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
276 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
277 boolean output = this.powerMgmt.setPower(input);
278 Assert.assertEquals(true, output);