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.mapping.PortMappingVersion710;
33 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
34 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
35 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
36 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
37 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl710;
38 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
39 import org.opendaylight.transportpce.olm.stub.MountPointStub;
40 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
41 import org.opendaylight.transportpce.olm.util.TransactionUtils;
42 import org.opendaylight.transportpce.test.AbstractTest;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownInput;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
47 public class PowerMgmtTest extends AbstractTest {
48 private MountPoint mountPoint;
49 private MountPointService mountPointService;
50 private DeviceTransactionManager deviceTransactionManager;
51 private CrossConnect crossConnect;
52 private OpenRoadmInterfaces openRoadmInterfaces;
53 private PortMapping portMapping;
54 private PowerMgmt powerMgmt;
55 private CrossConnectImpl121 crossConnectImpl121;
56 private CrossConnectImpl221 crossConnectImpl22;
57 private MappingUtils mappingUtils;
58 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
59 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
60 private OpenRoadmInterfacesImpl710 openRoadmInterfacesImpl710;
61 private PortMappingVersion710 portMappingVersion710;
62 private PortMappingVersion221 portMappingVersion22;
63 private PortMappingVersion121 portMappingVersion121;
64 private DataBroker dataBroker;
68 dataBroker = this.getNewDataBroker();
69 this.mountPoint = new MountPointStub(dataBroker);
70 this.mountPointService = new MountPointServiceStub(mountPoint);
71 // this.mappingUtils = new MappingUtilsImpl(getDataBroker());
72 this.mappingUtils = Mockito.spy(new MappingUtilsImpl(dataBroker));
73 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
74 .getOpenRoadmVersion(Mockito.anyString());
75 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
76 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
77 this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
78 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
79 this.crossConnectImpl22);
80 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
81 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
82 this.openRoadmInterfacesImpl710 = new OpenRoadmInterfacesImpl710(deviceTransactionManager);
83 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
84 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22,
85 this.openRoadmInterfacesImpl710);
86 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
87 this.portMappingVersion22 =
88 new PortMappingVersion221(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
89 this.portMappingVersion121 =
90 new PortMappingVersion121(dataBroker, deviceTransactionManager, this.openRoadmInterfaces);
91 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion710,
92 this.portMappingVersion22, this.portMappingVersion121);
93 this.portMapping = Mockito.spy(this.portMapping);
94 this.powerMgmt = new PowerMgmtImpl(this.dataBroker, this.openRoadmInterfaces, this.crossConnect,
95 this.deviceTransactionManager);
99 public void testSetPower() {
100 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
101 boolean output = this.powerMgmt.setPower(input);
102 Assert.assertEquals(true, output);
106 public void testSetPower2() {
107 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
108 boolean output = this.powerMgmt.setPower(input);
109 Assert.assertEquals(true, output);
113 public void testSetPower3() {
114 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
115 boolean output = this.powerMgmt.setPower(input);
116 Assert.assertEquals(true, output);
120 public void testSetPower4() {
121 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
122 boolean output = this.powerMgmt.setPower(input);
123 Assert.assertEquals(true, output);
127 public void testPowerTurnDown() {
128 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
129 boolean output = this.powerMgmt.powerTurnDown(input);
130 Assert.assertEquals(true, output);
134 public void testPowerTurnDown2() {
135 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
136 boolean output = this.powerMgmt.powerTurnDown(input);
137 Assert.assertEquals(false, output);
141 public void testPowerTurnDown3() {
142 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput3();
143 boolean output = this.powerMgmt.powerTurnDown(input);
144 Assert.assertEquals(true, output);
148 public void testPowerTurnDown4() {
149 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput4();
150 boolean output = this.powerMgmt.powerTurnDown(input);
151 Assert.assertEquals(false, output);
155 public void testSetPowerPresentNodes() throws InterruptedException {
156 List<NodeId> nodes = TransactionUtils.getNodeIds();
157 for (NodeId nodeId : nodes) {
158 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
161 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
162 boolean output = this.powerMgmt.setPower(input);
163 Assert.assertEquals(true, output);
167 public void testSetPowerPresentNodes2() throws InterruptedException {
168 List<NodeId> nodes = TransactionUtils.getNodeIds();
169 for (NodeId nodeId : nodes) {
170 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.dataBroker, null);
173 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
174 boolean output = this.powerMgmt.setPower(input);
175 Assert.assertEquals(true, output);
179 public void testSetPowerPresentNodes3() throws InterruptedException {
180 List<NodeId> nodes = TransactionUtils.getNodeIds();
181 for (NodeId nodeId : nodes) {
182 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
185 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
186 boolean output = this.powerMgmt.setPower(input);
187 Assert.assertEquals(true, output);
191 public void testSetPowerPresentNodes31() throws InterruptedException {
192 List<NodeId> nodes = TransactionUtils.getNodeIds();
193 for (NodeId nodeId : nodes) {
194 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
197 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
198 boolean output = this.powerMgmt.setPower(input);
199 Assert.assertEquals(false, output);
203 public void testSetPowerPresentNodes312() throws InterruptedException {
204 List<NodeId> nodes = TransactionUtils.getNodeIds();
205 for (NodeId nodeId : nodes) {
206 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, "deg");
209 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
210 boolean output = this.powerMgmt.setPower(input);
211 Assert.assertEquals(true, output);
215 public void testSetPowerPresentNodes32() throws InterruptedException {
216 List<NodeId> nodes = TransactionUtils.getNodeIds();
217 for (NodeId nodeId : nodes) {
218 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.dataBroker, null);
221 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
222 boolean output = this.powerMgmt.setPower(input);
223 Assert.assertEquals(true, output);
227 public void testSetPowerPresentNodes4() throws InterruptedException {
228 List<NodeId> nodes = TransactionUtils.getNodeIds();
229 for (NodeId nodeId : nodes) {
230 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "network");
233 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
234 boolean output = this.powerMgmt.setPower(input);
235 Assert.assertEquals(true, output);
240 public void testSetPowerPresentNodes41() throws InterruptedException {
241 List<NodeId> nodes = TransactionUtils.getNodeIds();
242 for (NodeId nodeId : nodes) {
243 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
246 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
247 boolean output = this.powerMgmt.setPower(input);
248 Assert.assertEquals(false, output);
252 public void testSetPowerPresentNodes42() throws InterruptedException {
253 List<NodeId> nodes = TransactionUtils.getNodeIds();
254 for (NodeId nodeId : nodes) {
255 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
258 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
259 boolean output = this.powerMgmt.setPower(input);
260 Assert.assertEquals(true, output);
264 public void testSetPowerPresentNodes422() throws InterruptedException {
265 List<NodeId> nodes = TransactionUtils.getNodeIds();
266 for (NodeId nodeId : nodes) {
267 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, "deg");
270 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
271 boolean output = this.powerMgmt.setPower(input);
272 Assert.assertEquals(true, output);
276 public void testSetPowerPresentNodes43() throws InterruptedException {
277 List<NodeId> nodes = TransactionUtils.getNodeIds();
278 for (NodeId nodeId : nodes) {
279 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.dataBroker, null);
282 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
283 boolean output = this.powerMgmt.setPower(input);
284 Assert.assertEquals(true, output);