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.controller.md.sal.binding.api.MountPoint;
17 import org.opendaylight.controller.md.sal.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.*;
26 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
27 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
28 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
29 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
30 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
31 import org.opendaylight.transportpce.olm.stub.MountPointStub;
32 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
33 import org.opendaylight.transportpce.olm.util.TransactionUtils;
34 import org.opendaylight.transportpce.test.AbstractTest;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
38 public class PowerMgmtTest extends AbstractTest {
40 private MountPoint mountPoint;
41 private MountPointService mountPointService;
42 private DeviceTransactionManager deviceTransactionManager;
43 private CrossConnect crossConnect;
44 private OpenRoadmInterfaces openRoadmInterfaces;
45 private PortMapping portMapping;
46 private PowerMgmt powerMgmt;
47 private CrossConnectImpl121 crossConnectImpl121;
48 private CrossConnectImpl221 crossConnectImpl22;
49 private MappingUtils mappingUtils;
50 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
51 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
52 private PortMappingVersion221 portMappingVersion22;
53 private PortMappingVersion121 portMappingVersion121;
57 this.mountPoint = new MountPointStub(this.getDataBroker());
58 this.mountPointService = new MountPointServiceStub(mountPoint);
59 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
60 this.mappingUtils = Mockito.spy(MappingUtils.class);
61 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
62 .getOpenRoadmVersion(Mockito.anyString());
63 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
64 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
65 this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
66 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
67 this.crossConnectImpl22);
68 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
69 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
70 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
71 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
72 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
73 this.portMappingVersion22 =
74 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
75 this.portMappingVersion121 =
76 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
77 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
78 this.portMappingVersion121);
79 this.portMapping = Mockito.spy(this.portMapping);
80 this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
81 this.deviceTransactionManager);
85 public void testSetPower() {
87 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
88 boolean output = this.powerMgmt.setPower(input);
89 Assert.assertEquals(true, output);
94 public void testSetPower2() {
96 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
97 boolean output = this.powerMgmt.setPower(input);
98 Assert.assertEquals(true, output);
103 public void testSetPower3() {
105 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
106 boolean output = this.powerMgmt.setPower(input);
107 Assert.assertEquals(true, output);
112 public void testSetPower4() {
114 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
115 boolean output = this.powerMgmt.setPower(input);
116 Assert.assertEquals(true, output);
121 public void testSetPowerPresentNodes() throws InterruptedException {
122 List<NodeId> nodes = TransactionUtils.getNodeIds();
123 for (NodeId nodeId : nodes) {
124 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
127 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
128 boolean output = this.powerMgmt.setPower(input);
129 Assert.assertEquals(true, output);
133 public void testSetPowerPresentNodes2() throws InterruptedException {
134 List<NodeId> nodes = TransactionUtils.getNodeIds();
135 for (NodeId nodeId : nodes) {
136 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
139 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
140 boolean output = this.powerMgmt.setPower(input);
141 Assert.assertEquals(true, output);
145 public void testSetPowerPresentNodes3() throws InterruptedException {
146 List<NodeId> nodes = TransactionUtils.getNodeIds();
147 for (NodeId nodeId : nodes) {
148 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
151 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
152 boolean output = this.powerMgmt.setPower(input);
153 Assert.assertEquals(true, output);
157 public void testSetPowerPresentNodes31() throws InterruptedException {
158 List<NodeId> nodes = TransactionUtils.getNodeIds();
159 for (NodeId nodeId : nodes) {
160 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
163 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
164 boolean output = this.powerMgmt.setPower(input);
165 Assert.assertEquals(false, output);
169 public void testSetPowerPresentNodes312() throws InterruptedException {
170 List<NodeId> nodes = TransactionUtils.getNodeIds();
171 for (NodeId nodeId : nodes) {
172 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
175 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
176 boolean output = this.powerMgmt.setPower(input);
177 Assert.assertEquals(true, output);
181 public void testSetPowerPresentNodes32() throws InterruptedException {
182 List<NodeId> nodes = TransactionUtils.getNodeIds();
183 for (NodeId nodeId : nodes) {
184 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
187 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
188 boolean output = this.powerMgmt.setPower(input);
189 Assert.assertEquals(true, output);
193 public void testSetPowerPresentNodes4() throws InterruptedException {
194 List<NodeId> nodes = TransactionUtils.getNodeIds();
195 for (NodeId nodeId : nodes) {
196 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
199 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
200 boolean output = this.powerMgmt.setPower(input);
201 Assert.assertEquals(true, output);
206 public void testSetPowerPresentNodes41() throws InterruptedException {
207 List<NodeId> nodes = TransactionUtils.getNodeIds();
208 for (NodeId nodeId : nodes) {
209 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
212 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
213 boolean output = this.powerMgmt.setPower(input);
214 Assert.assertEquals(false, output);
218 public void testSetPowerPresentNodes42() throws InterruptedException {
219 List<NodeId> nodes = TransactionUtils.getNodeIds();
220 for (NodeId nodeId : nodes) {
221 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
224 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
225 boolean output = this.powerMgmt.setPower(input);
226 Assert.assertEquals(true, output);
230 public void testSetPowerPresentNodes422() throws InterruptedException {
231 List<NodeId> nodes = TransactionUtils.getNodeIds();
232 for (NodeId nodeId : nodes) {
233 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
236 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
237 boolean output = this.powerMgmt.setPower(input);
238 Assert.assertEquals(true, output);
242 public void testSetPowerPresentNodes43() throws InterruptedException {
243 List<NodeId> nodes = TransactionUtils.getNodeIds();
244 for (NodeId nodeId : nodes) {
245 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
248 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
249 boolean output = this.powerMgmt.setPower(input);
250 Assert.assertEquals(true, output);