Add PowerMock library in OLM module
[transportpce.git] / olm / src / test / java / org / opendaylight / transportpce / olm / service / OlmPowerServiceImplTest.java
1 /*
2  * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.transportpce.olm.service;
10
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.mdsal.binding.api.DataBroker;
18 import org.opendaylight.mdsal.binding.api.MountPoint;
19 import org.opendaylight.mdsal.binding.api.MountPointService;
20 import org.opendaylight.transportpce.common.NetworkUtils;
21 import org.opendaylight.transportpce.common.ResponseCodes;
22 import org.opendaylight.transportpce.common.StringConstants;
23 import org.opendaylight.transportpce.common.crossconnect.CrossConnect;
24 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl;
25 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl121;
26 import org.opendaylight.transportpce.common.crossconnect.CrossConnectImpl221;
27 import org.opendaylight.transportpce.common.device.DeviceTransactionManager;
28 import org.opendaylight.transportpce.common.device.DeviceTransactionManagerImpl;
29 import org.opendaylight.transportpce.common.mapping.MappingUtils;
30 import org.opendaylight.transportpce.common.mapping.MappingUtilsImpl;
31 import org.opendaylight.transportpce.common.mapping.PortMapping;
32 import org.opendaylight.transportpce.common.mapping.PortMappingImpl;
33 import org.opendaylight.transportpce.common.mapping.PortMappingVersion121;
34 import org.opendaylight.transportpce.common.mapping.PortMappingVersion221;
35 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfaces;
36 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl;
37 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl121;
38 import org.opendaylight.transportpce.common.openroadminterfaces.OpenRoadmInterfacesImpl221;
39 import org.opendaylight.transportpce.olm.power.PowerMgmt;
40 import org.opendaylight.transportpce.olm.power.PowerMgmtImpl;
41 import org.opendaylight.transportpce.olm.stub.MountPointServiceStub;
42 import org.opendaylight.transportpce.olm.stub.MountPointStub;
43 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
44 import org.opendaylight.transportpce.olm.util.OtsPmHolder;
45 import org.opendaylight.transportpce.olm.util.TransactionUtils;
46 import org.opendaylight.transportpce.test.AbstractTest;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossBaseInput;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossBaseOutput;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossBaseOutputBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossCurrentInput;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.CalculateSpanlossCurrentOutput;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmInput;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutput;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.GetPmOutputBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerResetInput;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerResetOutput;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupInput;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupOutput;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerSetupOutputBuilder;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownInput;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutput;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev170418.ServicePowerTurndownOutputBuilder;
63 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.NetworkId;
64 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.Networks;
65 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.Network;
66 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev180226.networks.NetworkKey;
67 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.topology.rev180226.Network1;
68 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
69 import org.powermock.api.mockito.PowerMockito;
70 import org.slf4j.Logger;
71 import org.slf4j.LoggerFactory;
72
73 public class OlmPowerServiceImplTest  extends AbstractTest {
74
75     private static final Logger LOG = LoggerFactory.getLogger(OlmPowerServiceImplTest.class);
76     private MountPoint mountPoint;
77     private MountPointService mountPointService;
78     private DeviceTransactionManager deviceTransactionManager;
79     private CrossConnect crossConnect;
80     private OpenRoadmInterfaces openRoadmInterfaces;
81     private PortMapping portMapping;
82     private PowerMgmt powerMgmt;
83     private CrossConnectImpl121 crossConnectImpl121;
84     private CrossConnectImpl221 crossConnectImpl22;
85     private MappingUtils mappingUtils;
86     private OpenRoadmInterfacesImpl121 openRoadmInterfacesImpl121;
87     private OpenRoadmInterfacesImpl221 openRoadmInterfacesImpl22;
88     private PortMappingVersion221 portMappingVersion22;
89     private PortMappingVersion121 portMappingVersion121;
90     private OlmPowerService olmPowerService;
91     private DataBroker dataBroker;
92     private PowerMgmt powerMgmtMock;
93     @InjectMocks
94     private OlmPowerService olmPowerServiceMock;
95     private OtsPmHolder otsPmHolder;
96
97
98     @Before
99     public void setUp() {
100         this.mountPoint = new MountPointStub(this.getDataBroker());
101         this.mountPointService = new MountPointServiceStub(mountPoint);
102         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
103         this.mappingUtils = Mockito.spy(new MappingUtilsImpl(getDataBroker()));
104         Mockito.doReturn(StringConstants.OPENROADM_DEVICE_VERSION_1_2_1).when(mappingUtils)
105                 .getOpenRoadmVersion(Mockito.anyString());
106         this.deviceTransactionManager = new DeviceTransactionManagerImpl(mountPointService, 3000);
107         this.crossConnectImpl121 = new CrossConnectImpl121(deviceTransactionManager);
108         this.crossConnectImpl22 = new CrossConnectImpl221(deviceTransactionManager);
109         this.crossConnect = new CrossConnectImpl(deviceTransactionManager, this.mappingUtils, this.crossConnectImpl121,
110                 this.crossConnectImpl22);
111         this.openRoadmInterfacesImpl121 = new OpenRoadmInterfacesImpl121(deviceTransactionManager);
112         this.openRoadmInterfacesImpl22 = new OpenRoadmInterfacesImpl221(deviceTransactionManager);
113         this.openRoadmInterfaces = new OpenRoadmInterfacesImpl((this.deviceTransactionManager),
114                 this.mappingUtils,this.openRoadmInterfacesImpl121,this.openRoadmInterfacesImpl22);
115         this.portMappingVersion22 =
116                 new PortMappingVersion221(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
117         this.portMappingVersion121 =
118                 new PortMappingVersion121(getDataBroker(), deviceTransactionManager, this.openRoadmInterfaces);
119         this.portMapping = new PortMappingImpl(getDataBroker(), this.portMappingVersion22, this.portMappingVersion121);
120         this.portMapping = Mockito.spy(this.portMapping);
121         this.powerMgmt = new PowerMgmtImpl(this.getDataBroker(), this.openRoadmInterfaces, this.crossConnect,
122             this.deviceTransactionManager);
123         this.olmPowerService = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmt,
124             this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
125         this.dataBroker =  PowerMockito.spy(getDataBroker());
126         this.powerMgmtMock = PowerMockito.mock(PowerMgmtImpl.class);
127         this.olmPowerServiceMock = new OlmPowerServiceImpl(this.getDataBroker(), this.powerMgmtMock,
128             this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
129         this.olmPowerServiceMock = Mockito.mock(OlmPowerServiceImpl.class);
130         MockitoAnnotations.initMocks(this);
131     }
132
133     @Test
134     public void dummyTest() {
135         OlmPowerServiceImpl olmPowerServiceImpl = (OlmPowerServiceImpl) this.olmPowerService;
136         olmPowerServiceImpl.init();
137         olmPowerServiceImpl.close();
138     }
139
140
141     @Test
142     public void testGetPm() {
143         GetPmInput input = OlmPowerServiceRpcImplUtil.getGetPmInput();
144         GetPmOutput output = this.olmPowerService.getPm(input);
145         Assert.assertEquals(new GetPmOutputBuilder().build(), output);
146         Assert.assertEquals(null, output.getResourceId());
147     }
148
149     @Test
150     public void testServicePowerSetupSuccess() {
151         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
152         Mockito.when(this.powerMgmtMock.setPower(Mockito.any())).thenReturn(true);
153         //TODO
154         Mockito.when(this.olmPowerServiceMock.servicePowerSetup(Mockito.any()))
155                 .thenReturn(new ServicePowerSetupOutputBuilder().setResult("Success").build());
156         ServicePowerSetupOutput output = this.olmPowerServiceMock.servicePowerSetup(input);
157         Assert.assertEquals(new ServicePowerSetupOutputBuilder().setResult("Success").build(), output);
158         Assert.assertEquals("Success", output.getResult());
159     }
160
161     @Test
162     public void testServicePowerSetupFailed() {
163         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
164         Mockito.when(this.powerMgmtMock.setPower(Mockito.any())).thenReturn(false);
165         //TODO
166         Mockito.when(this.olmPowerServiceMock.servicePowerSetup(Mockito.any()))
167                 .thenReturn(new ServicePowerSetupOutputBuilder().setResult("Failed").build());
168         ServicePowerSetupOutput output = this.olmPowerServiceMock.servicePowerSetup(input);
169         Assert.assertEquals("Failed", output.getResult());
170     }
171
172     @Test
173     public void testServicePowerTurnDownSuccess() {
174         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
175         Mockito.when(this.powerMgmtMock.powerTurnDown(Mockito.any())).thenReturn(true);
176         //TODO
177         Mockito.when(this.olmPowerServiceMock.servicePowerTurndown(Mockito.any()))
178                 .thenReturn(new ServicePowerTurndownOutputBuilder().setResult("Success").build());
179         ServicePowerTurndownOutput output = this.olmPowerServiceMock.servicePowerTurndown(input);
180         Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Success").build(), output);
181         Assert.assertEquals("Success", output.getResult());
182     }
183
184     @Test
185     public void testServicePowerTurnDownFailed() {
186         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
187         Mockito.when(this.powerMgmtMock.powerTurnDown(Mockito.any())).thenReturn(false);
188         //TODO
189         Mockito.when(this.olmPowerServiceMock.servicePowerTurndown(Mockito.any()))
190                 .thenReturn(new ServicePowerTurndownOutputBuilder().setResult("Failed").build());
191         ServicePowerTurndownOutput output = this.olmPowerServiceMock.servicePowerTurndown(input);
192         Assert.assertEquals(new ServicePowerTurndownOutputBuilder().setResult("Failed").build(), output);
193         Assert.assertEquals("Failed", output.getResult());
194     }
195
196     /*
197     @Test
198     public void testCalculateSpanlossBase() {
199         CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
200         //TODO
201         Mockito.when(this.olmPowerServiceMock.calculateSpanlossBase(Mockito.any()))
202                 .thenReturn(new CalculateSpanlossBaseOutputBuilder().setResult("Failed").build());
203         CalculateSpanlossBaseOutput output = this.olmPowerServiceMock.calculateSpanlossBase(input);
204         Assert.assertEquals("Failed", output.getResult());
205
206     }
207     */
208
209     /*
210     @Test
211     public void testCalculateSpanlossBase2() {
212         NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
213 <<<<<<< HEAD
214         InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
215             .child(Network.class, overlayTopologyKey)
216 =======
217         InstanceIdentifier<Network1> networkTopoIID = InstanceIdentifier.builder(Networks.class)
218                 .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
219                                 .ietf.network.rev180226.networks.Network.class,
220                         overlayTopologyKey)
221 >>>>>>> 87d8bf0... Retrieve OLM modifs from change 80051
222             .augmentation(Network1.class)
223             .build();
224         InstanceIdentifier<Network> networkIID = InstanceIdentifier.builder(Networks.class)
225                 .child(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang
226                                 .ietf.network.rev180226.networks.Network.class,
227                         overlayTopologyKey)
228                 .build();
229         Network1 network = TransactionUtils.getNetwork();
230         Network ietfNetwork = TransactionUtils.getOverLayNetwork();
231         TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, ietfNetwork);
232         TransactionUtils.writeTransaction(this.getDataBroker(), networkTopoIID, network);
233         try {
234             Thread.sleep(1000);
235         } catch (InterruptedException e) {
236             LOG.error("Write transaction failed !",e);
237         }
238         CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput();
239         //TODO
240         Mockito.when(this.olmPowerServiceMock.calculateSpanlossBase(Mockito.any()))
241                 .thenReturn(new CalculateSpanlossBaseOutputBuilder().setResult("Failed").build());
242         CalculateSpanlossBaseOutput output = this.olmPowerServiceMock.calculateSpanlossBase(input);
243         Assert.assertEquals("Failed", output.getResult());
244
245     }
246     */
247     @Test
248     public void testCalculateSpanlossBase3() {
249         NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
250         InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
251             .child(Network.class, overlayTopologyKey)
252             .augmentation(Network1.class)
253             .build();
254         Network1 network = TransactionUtils.getNetwork();
255         TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
256         try {
257             Thread.sleep(1000);
258         } catch (InterruptedException e) {
259             LOG.error("Write transaction failed !",e);
260         }
261         CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
262         //TODO
263         Mockito.when(this.olmPowerServiceMock.calculateSpanlossBase(Mockito.any()))
264                 .thenReturn(new CalculateSpanlossBaseOutputBuilder().setResult("Failed").build());
265         CalculateSpanlossBaseOutput output = this.olmPowerServiceMock.calculateSpanlossBase(input);
266         Assert.assertEquals("Failed", output.getResult());
267
268     }
269
270
271     @Test
272     public void testCalculateSpanlossBase4() {
273         NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
274         InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
275             .child(Network.class, overlayTopologyKey)
276             .augmentation(Network1.class)
277             .build();
278         Network1 network = TransactionUtils.getEmptyNetwork();
279         TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
280         try {
281             Thread.sleep(1000);
282         } catch (InterruptedException e) {
283             LOG.error("Write transaction failed !",e);
284         }
285         CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
286         CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
287         Assert.assertEquals("Failed", output.getResult());
288
289     }
290
291     @Test
292     public void testCalculateSpanlossBase5() {
293         NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
294         InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
295             .child(Network.class, overlayTopologyKey)
296             .augmentation(Network1.class)
297             .build();
298         Network1 network = TransactionUtils.getNullNetwork();
299         TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
300         try {
301             Thread.sleep(1000);
302         } catch (InterruptedException e) {
303             LOG.error("Write transaction failed !",e);
304         }
305         CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
306         CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
307         Assert.assertEquals("Failed", output.getResult());
308
309     }
310
311 //    @Test
312 //    public void testCalculateSpanlossBase4() throws InterruptedException {
313 //        NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
314 //        InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Network.class, overlayTopologyKey)
315 //            .augmentation(Network1.class)
316 //            .build();
317 //        Network1 network = TransactionUtils.getNetwork2();
318 //        TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
319 //
320 //        Thread.sleep(500);
321 //
322 //        List<NodeId> nodes = TransactionUtils.getNodes();
323 //        Node n;
324 //        SupportingNode sn;
325 //
326 //        List<SupportingNode> snl;
327 //        NodeId n5 = new NodeId("node 5");
328 //        KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII2 =
329 //            InstanceIdentifiers.UNDERLAY_NETWORK_II.child(Node.class, new NodeKey(n5));
330 //
331 //        sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
332 //            .setNodeRef(n5).build();
333 //        snl = new ArrayList<>();
334 //        snl.add(sn);
335 //        n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
336 //            .network.NodeBuilder().setNodeId(n5).build();
337 //        TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII2, n);
338 //        Thread.sleep(500);
339 //
340 //        for(int i=0; i < nodes.size(); i++) {
341 //            KeyedInstanceIdentifier<Node, NodeKey> mappedNodeII =
342 //                InstanceIdentifiers.OVERLAY_NETWORK_II.child(Node.class, new NodeKey(nodes.get(i)));
343 //            if (i != 0){
344 //                sn = new SupportingNodeBuilder().setNetworkRef(new NetworkId(NetworkUtils.UNDERLAY_NETWORK_ID))
345 //                    .setNodeRef(nodes.get(i-1)).build();
346 //            }else {
347 //                sn = new SupportingNodeBuilder().setNodeRef(n5).build();
348 //            }
349 //            snl = new ArrayList<>();
350 //            snl.add(sn);
351 //            n = new org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.network.rev150608
352 //                .network.NodeBuilder().setNodeId(nodes.get(i)).setSupportingNode(snl).build();
353 //            TransactionUtils.writeTransaction(this.getDataBroker(), mappedNodeII, n);
354 //            Thread.sleep(500);
355 //        }
356 //
357 //        Thread.sleep(1000);
358 //
359 //        CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInput2();
360 //        CalculateSpanlossBaseOutput output = this.olmPowerService.calculateSpanlossBase(input);
361 //        Assert.assertEquals("Failed", output.getResult());
362 //
363 //    }
364
365     @Test
366     public void testCalculateSpanlossCurrent1() {
367         CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
368         CalculateSpanlossCurrentOutput output = this.olmPowerService.calculateSpanlossCurrent(input);
369         Assert.assertEquals(null, output);
370     }
371
372     @Test
373     public void testCalculateSpanlossCurrent2() {
374         NetworkKey overlayTopologyKey = new NetworkKey(new NetworkId(NetworkUtils.OVERLAY_NETWORK_ID));
375         InstanceIdentifier<Network1> networkIID = InstanceIdentifier.builder(Networks.class)
376             .child(Network.class, overlayTopologyKey)
377             .augmentation(Network1.class)
378             .build();
379         Network1 network = TransactionUtils.getNetwork();
380         TransactionUtils.writeTransaction(this.getDataBroker(), networkIID, network);
381         try {
382             Thread.sleep(1000);
383         } catch (InterruptedException e) {
384             LOG.error("Write transaction failed !",e);
385         }
386         CalculateSpanlossCurrentInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossCurrentInput();
387         CalculateSpanlossCurrentOutput output = this.olmPowerService.calculateSpanlossCurrent(input);
388         Assert.assertEquals(null, output);
389     }
390
391     @Test
392     public void testServicePowerReset() {
393         ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
394         ServicePowerResetOutput output = this.olmPowerService.servicePowerReset(input);
395         Assert.assertEquals(null, output);
396     }
397
398     @Test
399     public void testServicePowerTurndownSuccessResult() {
400         ServicePowerTurndownInput servicePowerTurndownInput = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
401         ServicePowerTurndownOutput servicePowerTurndownOutput =
402                 this.olmPowerService.servicePowerTurndown(servicePowerTurndownInput);
403         Assert.assertEquals(ResponseCodes.SUCCESS_RESULT, servicePowerTurndownOutput.getResult());
404     }
405
406     @Test
407     public void testServicePowerTurndownFailResult() {
408         ServicePowerTurndownInput servicePowerTurndownInput =
409                 OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput2();
410         ServicePowerTurndownOutput servicePowerTurndownOutput =
411                 this.olmPowerService.servicePowerTurndown(servicePowerTurndownInput);
412         Assert.assertEquals(ResponseCodes.FAILED_RESULT, servicePowerTurndownOutput.getResult());
413     }
414
415     @Test
416     public void testServicePowerSetupSuccessResult() {
417         ServicePowerSetupInput servicePowerSetupInput =
418                 OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
419         ServicePowerSetupOutput servicePowerSetupOutput =
420                 this.olmPowerService.servicePowerSetup(servicePowerSetupInput);
421         Assert.assertEquals(ResponseCodes.SUCCESS_RESULT, servicePowerSetupOutput.getResult());
422     }
423
424     @Test
425     public void testServicePowerSetupFailResult() {
426         ServicePowerSetupInput servicePowerSetupInput = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
427         Mockito.when(powerMgmtMock.setPower(servicePowerSetupInput)).thenReturn(Boolean.FALSE);
428         OlmPowerService olmPowerServiceWithMock = new OlmPowerServiceImpl(dataBroker, powerMgmtMock,
429                 this.deviceTransactionManager, this.portMapping, this.mappingUtils, this.openRoadmInterfaces);
430         ServicePowerSetupOutput servicePowerSetupOutput =
431                 olmPowerServiceWithMock.servicePowerSetup(servicePowerSetupInput);
432         Assert.assertEquals(ResponseCodes.FAILED_RESULT, servicePowerSetupOutput.getResult());
433     }
434 }