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.service;
11 import org.junit.Assert;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.mockito.InjectMocks;
15 import org.mockito.Mockito;
16 import org.mockito.MockitoAnnotations;
17 import org.opendaylight.controller.md.sal.binding.api.MountPoint;
18 import org.opendaylight.controller.md.sal.binding.api.MountPointService;
19 import org.opendaylight.transportpce.common.NetworkUtils;
20 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
21 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
22 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
23 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
24 import org.opendaylight.transportpce.common.mapping.PortMapping;
25 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
26 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
27 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
28 import org.opendaylight.transportpce.olm.power.PowerMgmt;
29 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
30 import org.opendaylight.transportpce.olm.stub.MountPointStub;
31 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
32 import org.opendaylight.transportpce.olm.util.TransactionUtils;
33 import org.opendaylight.transportpce.test.AbstractTest;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossBaseInput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossBaseOutput;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossCurrentInput;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossCurrentOutput;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInput;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutput;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutputBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerResetInput;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerResetOutput;
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.ServicePowerSetupOutput;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupOutputBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownInput;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutput;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutputBuilder;
49 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.Network;
50 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NetworkId;
51 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608.NetworkKey;
52 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev150608.Network1;
53 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
57 public class OlmPowerServiceImplTest extends AbstractTest {
59 private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceImplTest.class);
60 private MountPoint mountPoint;
61 private MountPointService mountPointService;
62 private DeviceTransactionManager deviceTransactionManager;
63 private CrossConnect crossConnect;
64 private OpenRoadmInterfaces openRoadmInterfaces;
65 private PortMapping portMapping;
66 private PowerMgmt powerMgmt;
67 private OlmPowerService olmPowerService;
68 private PowerMgmt powerMgmtMock;
70 private OlmPowerService olmPowerServiceMock;
76 this.mountPoint = new MountPointStub(this.getDataBroker());
77 this.mountPointService = new MountPointServiceStub(mountPoint);
78 this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
79 this.crossConnect = new CrossConnectImpl(this.deviceTransactionManager);
80 this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager));
81 this.portMapping = new PortMappingImpl(this.getDataBroker(), this.deviceTransactionManager,
82 this.openRoadmInterfaces);
83 this.powerMgmt = new PowerMgmt(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
84 this.deviceTransactionManager);
85 this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt,
86 this.deviceTransactionManager, this.portMapping);
87 this.powerMgmtMock = Mockito.mock(PowerMgmt.class);
88 this.olmPowerServiceMock = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmtMock,
89 this.deviceTransactionManager, this.portMapping);
90 MockitoAnnotations.initMocks(this);
94 public void dummyTest() {
95 OlmPowerServiceImpl olmPowerServiceImpl = (OlmPowerServiceImpl) this.olmPowerService;
96 olmPowerServiceImpl.init();
97 olmPowerServiceImpl.close();
102 public void testGetPm() {
103 GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
104 GetPmOutput output = this.olmPowerService.getPm(input);
105 Assert.assertEquals(new GetPmOutputBuilder().build(), output);
106 Assert.assertEquals(null, output.getResourceId());
110 public void testServicePowerSetupSuccess() {
111 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
112 Mockito.when(this.powerMgmtMock.setPower(Mockito.any())).thenReturn(true);
113 ServicePowerSetupOutput output = this.olmPowerServiceMock.servicePowerSetup(input);
114 Assert.assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), output);
115 Assert.assertEquals("Success", output.getResult());
119 public void testServicePowerSetupFailed() {
120 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
121 Mockito.when(this.powerMgmtMock.setPower(Mockito.any())).thenReturn(false);
122 ServicePowerSetupOutput output = this.olmPowerServiceMock.servicePowerSetup(input);
123 Assert.assertEquals("Failed", output.getResult());
127 public void testServicePowerTurnDownSuccess() {
128 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
129 Mockito.when(this.powerMgmtMock.powerTurnDown(Mockito.any())).thenReturn(true);
130 ServicePowerTurndownOutput output = this.olmPowerServiceMock.servicePowerTurndown(input);
131 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output);
132 Assert.assertEquals("Success", output.getResult());
136 public void testServicePowerTurnDownFailed() {
137 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
138 Mockito.when(this.powerMgmtMock.powerTurnDown(Mockito.any())).thenReturn(false);
139 ServicePowerTurndownOutput output = this.olmPowerServiceMock.servicePowerTurndown(input);
140 Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Failed").build(), output);
141 Assert.assertEquals("Failed", output.getResult());
145 public void testCalculateSpanlossBase() {
146 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
147 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
148 Assert.assertEquals("Failed", output.getResult());
153 public void testCalculateSpanlossBase2() {
154 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
155 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
156 .augmentation(Network1.class)
158 Network1 network = TransactionUtils.getNetwork();
159 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
162 } catch (InterruptedException e) {
163 LOG.error("Write transaction failed !",e);
165 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
166 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
167 Assert.assertEquals("Failed", output.getResult());
172 public void testCalculateSpanlossBase3() {
173 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
174 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
175 .augmentation(Network1.class)
177 Network1 network = TransactionUtils.getNetwork();
178 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
181 } catch (InterruptedException e) {
182 LOG.error("Write transaction failed !",e);
184 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
185 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
186 Assert.assertEquals("Failed", output.getResult());
192 public void testCalculateSpanlossBase4() {
193 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
194 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
195 .augmentation(Network1.class)
197 Network1 network = TransactionUtils.getEmptyNetwork();
198 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
201 } catch (InterruptedException e) {
202 LOG.error("Write transaction failed !",e);
204 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
205 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
206 Assert.assertEquals("Failed", output.getResult());
211 public void testCalculateSpanlossBase5() {
212 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
213 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
214 .augmentation(Network1.class)
216 Network1 network = TransactionUtils.getNullNetwork();
217 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
220 } catch (InterruptedException e) {
221 LOG.error("Write transaction failed !",e);
223 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
224 CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
225 Assert.assertEquals("Failed", output.getResult());
230 // public void testCalculateSpanlossBase4() throws InterruptedException {
231 // NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
232 // InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
233 // .augmentation(Network1.class)
235 // Network1 network = TransactionUtils.getNetwork2();
236 // TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
238 // Thread.sleep(500);
240 // List<NodeId> nodes = TransactionUtils.getNodes();
242 // SupportingNode sn;
244 // List<SupportingNode> snl;
245 // NodeId n5 = new NodeId("node 5");
246 // KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII2 =
247 // InstanceIdentifiers.UNDERLAY_NETWORK_II.child(Node.class, new NodeKey(n5));
249 // sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
250 // .setNodeRef(n5).build();
251 // snl = new ArrayList<>();
253 // n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
254 // .network.NodeBuilder().setNodeId(n5).build();
255 // TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII2, n);
256 // Thread.sleep(500);
258 // for(int i=0; i < nodes.size(); i++) {
259 // KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII =
260 // InstanceIdentifiers.OVERLAY_NETWORK_II.child(Node.class, new NodeKey(nodes.get(i)));
262 // sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
263 // .setNodeRef(nodes.get(i-1)).build();
265 // sn = new SupportingNodeBuilder().setNodeRef(n5).build();
267 // snl = new ArrayList<>();
269 // n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
270 // .network.NodeBuilder().setNodeId(nodes.get(i)).setSupportingNode(snl).build();
271 // TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII, n);
272 // Thread.sleep(500);
275 // Thread.sleep(1000);
277 // CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
278 // CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
279 // Assert.assertEquals("Failed", output.getResult());
284 public void testCalculateSpanlossCurrent1() {
285 CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
286 CalculateSpanlossCurrentOutput output = this.olmPowerService.calculateSpanlossCurrent(input);
287 Assert.assertEquals(null, output);
291 public void testCalculateSpanlossCurrent2() {
292 NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
293 InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
294 .augmentation(Network1.class)
296 Network1 network = TransactionUtils.getNetwork();
297 TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
300 } catch (InterruptedException e) {
301 LOG.error("Write transaction failed !",e);
303 CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
304 CalculateSpanlossCurrentOutput output = this.olmPowerService.calculateSpanlossCurrent(input);
305 Assert.assertEquals(null, output);
309 public void testServicePowerReset() {
310 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
311 ServicePowerResetOutput output = this.olmPowerService.servicePowerReset(input);
312 Assert.assertEquals(null, output);