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;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16 import static org.mockito.ArgumentMatchers.any;
17 import static org.mockito.Mockito.when;
19 import com.google.common.util.concurrent.ListenableFuture;
20 import java.util.concurrent.ExecutionException;
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23 import org.junit.jupiter.api.extension.ExtendWith;
24 import org.mockito.Mock;
25 import org.mockito.junit.jupiter.MockitoExtension;
26 import org.opendaylight.mdsal.binding.api.RpcProviderService;
27 import org.opendaylight.transportpce.olm.service.OlmPowerService;
28 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
29 import org.opendaylight.transportpce.test.AbstractTest;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutputBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInput;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInputBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutputBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInputBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutputBuilder;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.TransportpceOlmService;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
48 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.PmGranularity;
49 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.olm.get.pm.input.ResourceIdentifierBuilder;
50 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
51 import org.opendaylight.yangtools.yang.common.ErrorTag;
52 import org.opendaylight.yangtools.yang.common.ErrorType;
53 import org.opendaylight.yangtools.yang.common.RpcResult;
55 @ExtendWith(MockitoExtension.class)
56 class OlmPowerServiceRpcImplTest extends AbstractTest {
59 private OlmPowerService olmPowerService;
61 private RpcProviderService rpcProviderService;
62 private TransportpceOlmService olmPowerServiceRpc;
66 this.olmPowerServiceRpc = new OlmPowerServiceRpcImpl(this.olmPowerService, rpcProviderService);
70 void testGetPmFailWithNodeIdNull() throws InterruptedException, ExecutionException {
71 GetPmInput input = new GetPmInputBuilder()
72 .setGranularity(PmGranularity._15min)
73 .setResourceIdentifier(new ResourceIdentifierBuilder()
74 .setResourceName("ots-deg1").build())
75 .setResourceType(ResourceTypeEnum.Interface)
77 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
78 assertFalse(output.get().isSuccessful());
79 assertNull(output.get().getResult());
80 assertEquals(ErrorType.RPC, output.get().getErrors().get(0).getErrorType());
81 assertEquals("Error with input parameters", output.get().getErrors().get(0).getMessage());
82 assertEquals(ErrorSeverity.ERROR, output.get().getErrors().get(0).getSeverity());
83 assertEquals(ErrorTag.OPERATION_FAILED, output.get().getErrors().get(0).getTag());
87 void testGetPmWithSuccess() throws InterruptedException, ExecutionException {
88 GetPmInput input = new GetPmInputBuilder()
91 when(this.olmPowerService.getPm(any())).thenReturn(new GetPmOutputBuilder().build());
92 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
93 assertTrue(output.get().isSuccessful());
94 assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
98 void testServicePowerSetup() throws InterruptedException, ExecutionException {
99 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
100 when(this.olmPowerService.servicePowerSetup(any())).thenReturn(new ServicePowerSetupOutputBuilder().build());
101 ListenableFuture<RpcResult<ServicePowerSetupOutput>> output = this.olmPowerServiceRpc.servicePowerSetup(input);
102 assertTrue(output.get().isSuccessful());
103 assertEquals(new ServicePowerSetupOutputBuilder().build(), output.get().getResult());
107 void testServicePowerTurndown() throws InterruptedException, ExecutionException {
108 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
109 when(this.olmPowerService.servicePowerTurndown(any()))
110 .thenReturn(new ServicePowerTurndownOutputBuilder().build());
111 var output = this.olmPowerServiceRpc.servicePowerTurndown(input);
112 assertTrue(output.get().isSuccessful());
113 assertEquals(new ServicePowerTurndownOutputBuilder().build(), output.get().getResult());
117 void testCalculateSpanlossBase() throws InterruptedException, ExecutionException {
118 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInputAll();
119 when(this.olmPowerService.calculateSpanlossBase(any()))
120 .thenReturn(new CalculateSpanlossBaseOutputBuilder().build());
121 var output = this.olmPowerServiceRpc.calculateSpanlossBase(input);
122 assertTrue(output.get().isSuccessful());
123 assertEquals(new CalculateSpanlossBaseOutputBuilder().build(), output.get().getResult());
127 void testCalculateSpanlossCurrent() throws InterruptedException, ExecutionException {
128 CalculateSpanlossCurrentInput input = new CalculateSpanlossCurrentInputBuilder().build();
129 when(this.olmPowerService.calculateSpanlossCurrent(any()))
130 .thenReturn(new CalculateSpanlossCurrentOutputBuilder().build());
131 var output = this.olmPowerServiceRpc.calculateSpanlossCurrent(input);
132 assertTrue(output.get().isSuccessful());
133 assertEquals(new CalculateSpanlossCurrentOutputBuilder().build(), output.get().getResult());
137 void testServicePowerReset() throws InterruptedException, ExecutionException {
138 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
139 when(this.olmPowerService.servicePowerReset(any()))
140 .thenReturn(new ServicePowerResetOutputBuilder().build());
141 var output = this.olmPowerServiceRpc.servicePowerReset(input);
142 assertTrue(output.get().isSuccessful());
143 assertEquals(new ServicePowerResetOutputBuilder().build(), output.get().getResult());