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.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.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NodeId;
43 public class PowerMgmtTest extends AbstractTest {
45 private MountPoint mountPoint;
46 private MountPointService mountPointService;
47 private DeviceTransactionManager deviceTransactionManager;
48 private CrossConnect crossConnect;
49 private OpenRoadmInterfaces openRoadmInterfaces;
50 private PortMapping portMapping;
51 private PowerMgmt powerMgmt;
52 private CrossConnectImpl121 crossConnectImpl121;
53 private CrossConnectImpl221 crossConnectImpl22;
54 private MappingUtils mappingUtils;
55 private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
56 private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
57 private PortMappingVersion221 portMappingVersion22;
58 private PortMappingVersion121 portMappingVersion121;
62 this.mountPoint = new MountPointStub(this.getDataBroker());
63 this.mountPointService = new MountPointServiceStub(mountPoint);
64 this.mappingUtils = new MappingUtilsImpl(getDataBroker());
65 this.mappingUtils = Mockito.spy(MappingUtils.class);
66 Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
67 .getOpenRoadmVersion(Mockito.anyString());
68 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
69 this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
70 this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
71 this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
72 this.crossConnectImpl22);
73 this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
74 this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
75 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
76 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
77 this.openRoadmInterfaces = Mockito.spy(this.openRoadmInterfaces);
78 this.portMappingVersion22 =
79 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
80 this.portMappingVersion121 =
81 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
82 this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.mappingUtils,
83 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() {
92 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
93 boolean output = this.powerMgmt.setPower(input);
94 Assert.assertEquals(true, output);
99 public void testSetPower2() {
101 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
102 boolean output = this.powerMgmt.setPower(input);
103 Assert.assertEquals(true, output);
108 public void testSetPower3() {
110 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
111 boolean output = this.powerMgmt.setPower(input);
112 Assert.assertEquals(true, output);
117 public void testSetPower4() {
119 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
120 boolean output = this.powerMgmt.setPower(input);
121 Assert.assertEquals(true, output);
126 public void testSetPowerPresentNodes() throws InterruptedException {
127 List<NodeId> nodes = TransactionUtils.getNodeIds();
128 for (NodeId nodeId : nodes) {
129 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
132 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
133 boolean output = this.powerMgmt.setPower(input);
134 Assert.assertEquals(true, output);
138 public void testSetPowerPresentNodes2() throws InterruptedException {
139 List<NodeId> nodes = TransactionUtils.getNodeIds();
140 for (NodeId nodeId : nodes) {
141 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
144 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
145 boolean output = this.powerMgmt.setPower(input);
146 Assert.assertEquals(true, output);
150 public void testSetPowerPresentNodes3() throws InterruptedException {
151 List<NodeId> nodes = TransactionUtils.getNodeIds();
152 for (NodeId nodeId : nodes) {
153 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
156 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
157 boolean output = this.powerMgmt.setPower(input);
158 Assert.assertEquals(true, output);
162 public void testSetPowerPresentNodes31() throws InterruptedException {
163 List<NodeId> nodes = TransactionUtils.getNodeIds();
164 for (NodeId nodeId : nodes) {
165 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
168 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
169 boolean output = this.powerMgmt.setPower(input);
170 Assert.assertEquals(false, output);
174 public void testSetPowerPresentNodes312() throws InterruptedException {
175 List<NodeId> nodes = TransactionUtils.getNodeIds();
176 for (NodeId nodeId : nodes) {
177 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
180 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
181 boolean output = this.powerMgmt.setPower(input);
182 Assert.assertEquals(true, output);
186 public void testSetPowerPresentNodes32() throws InterruptedException {
187 List<NodeId> nodes = TransactionUtils.getNodeIds();
188 for (NodeId nodeId : nodes) {
189 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
192 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
193 boolean output = this.powerMgmt.setPower(input);
194 Assert.assertEquals(true, output);
198 public void testSetPowerPresentNodes4() throws InterruptedException {
199 List<NodeId> nodes = TransactionUtils.getNodeIds();
200 for (NodeId nodeId : nodes) {
201 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
204 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
205 boolean output = this.powerMgmt.setPower(input);
206 Assert.assertEquals(true, output);
211 public void testSetPowerPresentNodes41() throws InterruptedException {
212 List<NodeId> nodes = TransactionUtils.getNodeIds();
213 for (NodeId nodeId : nodes) {
214 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
217 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
218 boolean output = this.powerMgmt.setPower(input);
219 Assert.assertEquals(false, output);
223 public void testSetPowerPresentNodes42() throws InterruptedException {
224 List<NodeId> nodes = TransactionUtils.getNodeIds();
225 for (NodeId nodeId : nodes) {
226 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
229 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
230 boolean output = this.powerMgmt.setPower(input);
231 Assert.assertEquals(true, output);
235 public void testSetPowerPresentNodes422() throws InterruptedException {
236 List<NodeId> nodes = TransactionUtils.getNodeIds();
237 for (NodeId nodeId : nodes) {
238 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
241 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
242 boolean output = this.powerMgmt.setPower(input);
243 Assert.assertEquals(true, output);
247 public void testSetPowerPresentNodes43() throws InterruptedException {
248 List<NodeId> nodes = TransactionUtils.getNodeIds();
249 for (NodeId nodeId : nodes) {
250 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
253 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
254 boolean output = this.powerMgmt.setPower(input);
255 Assert.assertEquals(true, output);