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.portMappingVersion121);
83 this.portMapping = Mockito.spy(this.portMapping);
84 this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
85 this.deviceTransactionManager);
89 public void testSetPower() {
91 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
92 boolean output = this.powerMgmt.setPower(input);
93 Assert.assertEquals(true, output);
98 public void testSetPower2() {
100 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
101 boolean output = this.powerMgmt.setPower(input);
102 Assert.assertEquals(true, output);
107 public void testSetPower3() {
109 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
110 boolean output = this.powerMgmt.setPower(input);
111 Assert.assertEquals(true, output);
116 public void testSetPower4() {
118 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
119 boolean output = this.powerMgmt.setPower(input);
120 Assert.assertEquals(true, output);
125 public void testSetPowerPresentNodes() throws InterruptedException {
126 List<NodeId> nodes = TransactionUtils.getNodeIds();
127 for (NodeId nodeId : nodes) {
128 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
131 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
132 boolean output = this.powerMgmt.setPower(input);
133 Assert.assertEquals(true, output);
137 public void testSetPowerPresentNodes2() throws InterruptedException {
138 List<NodeId> nodes = TransactionUtils.getNodeIds();
139 for (NodeId nodeId : nodes) {
140 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
143 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
144 boolean output = this.powerMgmt.setPower(input);
145 Assert.assertEquals(true, output);
149 public void testSetPowerPresentNodes3() throws InterruptedException {
150 List<NodeId> nodes = TransactionUtils.getNodeIds();
151 for (NodeId nodeId : nodes) {
152 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
155 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
156 boolean output = this.powerMgmt.setPower(input);
157 Assert.assertEquals(true, output);
161 public void testSetPowerPresentNodes31() throws InterruptedException {
162 List<NodeId> nodes = TransactionUtils.getNodeIds();
163 for (NodeId nodeId : nodes) {
164 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
167 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
168 boolean output = this.powerMgmt.setPower(input);
169 Assert.assertEquals(false, output);
173 public void testSetPowerPresentNodes312() throws InterruptedException {
174 List<NodeId> nodes = TransactionUtils.getNodeIds();
175 for (NodeId nodeId : nodes) {
176 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
179 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
180 boolean output = this.powerMgmt.setPower(input);
181 Assert.assertEquals(true, output);
185 public void testSetPowerPresentNodes32() throws InterruptedException {
186 List<NodeId> nodes = TransactionUtils.getNodeIds();
187 for (NodeId nodeId : nodes) {
188 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
191 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
192 boolean output = this.powerMgmt.setPower(input);
193 Assert.assertEquals(true, output);
197 public void testSetPowerPresentNodes4() throws InterruptedException {
198 List<NodeId> nodes = TransactionUtils.getNodeIds();
199 for (NodeId nodeId : nodes) {
200 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
203 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
204 boolean output = this.powerMgmt.setPower(input);
205 Assert.assertEquals(true, output);
210 public void testSetPowerPresentNodes41() throws InterruptedException {
211 List<NodeId> nodes = TransactionUtils.getNodeIds();
212 for (NodeId nodeId : nodes) {
213 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
216 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
217 boolean output = this.powerMgmt.setPower(input);
218 Assert.assertEquals(false, output);
222 public void testSetPowerPresentNodes42() throws InterruptedException {
223 List<NodeId> nodes = TransactionUtils.getNodeIds();
224 for (NodeId nodeId : nodes) {
225 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
228 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
229 boolean output = this.powerMgmt.setPower(input);
230 Assert.assertEquals(true, output);
234 public void testSetPowerPresentNodes422() throws InterruptedException {
235 List<NodeId> nodes = TransactionUtils.getNodeIds();
236 for (NodeId nodeId : nodes) {
237 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
240 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
241 boolean output = this.powerMgmt.setPower(input);
242 Assert.assertEquals(true, output);
246 public void testSetPowerPresentNodes43() throws InterruptedException {
247 List<NodeId> nodes = TransactionUtils.getNodeIds();
248 for (NodeId nodeId : nodes) {
249 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
252 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
253 boolean output = this.powerMgmt.setPower(input);
254 Assert.assertEquals(true, output);