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.opendaylight.controller.md.sal.binding.api.MountPoint;
16 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
17 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
18 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
19 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
20 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
21 import org.opendaylight.transportpce.common.mapping.PortMapping;
22 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
23 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
24 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
25 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
26 import org.opendaylight.transportpce.olm.stub.MountPointStub;
27 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
28 import org.opendaylight.transportpce.olm.util.TransactionUtils;
29 import org.opendaylight.transportpce.test.AbstractTest;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
31 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NodeId;
33 public class PowerMgmtTest extends AbstractTest {
35 private MountPoint mountPoint;
36 private MountPointService mountPointService;
37 private DeviceTransactionManager deviceTransactionManager;
38 private CrossConnect crossConnect;
39 private OpenRoadmInterfaces openRoadmInterfaces;
40 private PortMapping portMapping;
41 private PowerMgmt powerMgmt;
45 this.mountPoint = new MountPointStub(this.getDataBroker());
46 this.mountPointService = new MountPointServiceStub(mountPoint);
47 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
48 this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager);
49 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager));
50 this.portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager,
51 this.openRoadmInterfaces);
52 this.powerMgmt = new PowerMgmt(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
53 this.deviceTransactionManager);
57 public void testSetPower() {
59 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
60 boolean output = this.powerMgmt.setPower(input);
61 Assert.assertEquals(true, output);
66 public void testSetPower2() {
68 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
69 boolean output = this.powerMgmt.setPower(input);
70 Assert.assertEquals(true, output);
75 public void testSetPower3() {
77 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
78 boolean output = this.powerMgmt.setPower(input);
79 Assert.assertEquals(true, output);
84 public void testSetPower4() {
86 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
87 boolean output = this.powerMgmt.setPower(input);
88 Assert.assertEquals(true, output);
93 public void testSetPowerPresentNodes() throws InterruptedException {
94 List<NodeId> nodes = TransactionUtils.getNodeIds();
95 for (NodeId nodeId : nodes) {
96 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
99 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
100 boolean output = this.powerMgmt.setPower(input);
101 Assert.assertEquals(true, output);
105 public void testSetPowerPresentNodes2() throws InterruptedException {
106 List<NodeId> nodes = TransactionUtils.getNodeIds();
107 for (NodeId nodeId : nodes) {
108 TransactionUtils.writeNodeTransaction2(nodeId.getValue(), this.getDataBroker(), null);
111 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
112 boolean output = this.powerMgmt.setPower(input);
113 Assert.assertEquals(true, output);
117 public void testSetPowerPresentNodes3() throws InterruptedException {
118 List<NodeId> nodes = TransactionUtils.getNodeIds();
119 for (NodeId nodeId : nodes) {
120 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
123 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
124 boolean output = this.powerMgmt.setPower(input);
125 Assert.assertEquals(true, output);
129 public void testSetPowerPresentNodes31() throws InterruptedException {
130 List<NodeId> nodes = TransactionUtils.getNodeIds();
131 for (NodeId nodeId : nodes) {
132 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
135 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
136 boolean output = this.powerMgmt.setPower(input);
137 Assert.assertEquals(false, output);
141 public void testSetPowerPresentNodes312() throws InterruptedException {
142 List<NodeId> nodes = TransactionUtils.getNodeIds();
143 for (NodeId nodeId : nodes) {
144 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), "deg");
147 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
148 boolean output = this.powerMgmt.setPower(input);
149 Assert.assertEquals(true, output);
153 public void testSetPowerPresentNodes32() throws InterruptedException {
154 List<NodeId> nodes = TransactionUtils.getNodeIds();
155 for (NodeId nodeId : nodes) {
156 TransactionUtils.writeNodeTransaction3(nodeId.getValue(), this.getDataBroker(), null);
159 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
160 boolean output = this.powerMgmt.setPower(input);
161 Assert.assertEquals(true, output);
165 public void testSetPowerPresentNodes4() throws InterruptedException {
166 List<NodeId> nodes = TransactionUtils.getNodeIds();
167 for (NodeId nodeId : nodes) {
168 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "network");
171 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
172 boolean output = this.powerMgmt.setPower(input);
173 Assert.assertEquals(true, output);
177 public void testSetPowerPresentNodes41() throws InterruptedException {
178 List<NodeId> nodes = TransactionUtils.getNodeIds();
179 for (NodeId nodeId : nodes) {
180 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
183 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput2();
184 boolean output = this.powerMgmt.setPower(input);
185 Assert.assertEquals(false, output);
189 public void testSetPowerPresentNodes42() throws InterruptedException {
190 List<NodeId> nodes = TransactionUtils.getNodeIds();
191 for (NodeId nodeId : nodes) {
192 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
195 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
196 boolean output = this.powerMgmt.setPower(input);
197 Assert.assertEquals(true, output);
201 public void testSetPowerPresentNodes422() throws InterruptedException {
202 List<NodeId> nodes = TransactionUtils.getNodeIds();
203 for (NodeId nodeId : nodes) {
204 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), "deg");
207 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput4();
208 boolean output = this.powerMgmt.setPower(input);
209 Assert.assertEquals(true, output);
213 public void testSetPowerPresentNodes43() throws InterruptedException {
214 List<NodeId> nodes = TransactionUtils.getNodeIds();
215 for (NodeId nodeId : nodes) {
216 TransactionUtils.writeNodeTransaction(nodeId.getValue(), this.getDataBroker(), null);
219 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput3();
220 boolean output = this.powerMgmt.setPower(input);
221 Assert.assertEquals(true, output);