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.transportpce.olm.service.OlmPowerService;
27 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
28 import org.opendaylight.transportpce.test.AbstractTest;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutputBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInput;
32 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInputBuilder;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutputBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInputBuilder;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutputBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutputBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
46 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.PmGranularity;
47 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.olm.get.pm.input.ResourceIdentifierBuilder;
48 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
49 import org.opendaylight.yangtools.yang.common.ErrorTag;
50 import org.opendaylight.yangtools.yang.common.ErrorType;
51 import org.opendaylight.yangtools.yang.common.RpcResult;
53 @ExtendWith(MockitoExtension.class)
54 class OlmPowerServiceRpcImplTest extends AbstractTest {
57 private OlmPowerService olmPowerService;
58 private OlmPowerServiceRpcImpl olmPowerServiceRpc;
62 this.olmPowerServiceRpc = new OlmPowerServiceRpcImpl(this.olmPowerService);
66 void testGetPmFailWithNodeIdNull() throws InterruptedException, ExecutionException {
67 GetPmInput input = new GetPmInputBuilder()
68 .setGranularity(PmGranularity._15min)
69 .setResourceIdentifier(new ResourceIdentifierBuilder()
70 .setResourceName("ots-deg1").build())
71 .setResourceType(ResourceTypeEnum.Interface)
73 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
74 assertFalse(output.get().isSuccessful());
75 assertNull(output.get().getResult());
76 assertEquals(ErrorType.RPC, output.get().getErrors().get(0).getErrorType());
77 assertEquals("Error with input parameters", output.get().getErrors().get(0).getMessage());
78 assertEquals(ErrorSeverity.ERROR, output.get().getErrors().get(0).getSeverity());
79 assertEquals(ErrorTag.OPERATION_FAILED, output.get().getErrors().get(0).getTag());
83 void testGetPmWithSuccess() throws InterruptedException, ExecutionException {
84 GetPmInput input = new GetPmInputBuilder()
87 when(this.olmPowerService.getPm(any())).thenReturn(new GetPmOutputBuilder().build());
88 ListenableFuture<RpcResult<GetPmOutput>> output = this.olmPowerServiceRpc.getPm(input);
89 assertTrue(output.get().isSuccessful());
90 assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
94 void testServicePowerSetup() throws InterruptedException, ExecutionException {
95 ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
96 when(this.olmPowerService.servicePowerSetup(any())).thenReturn(new ServicePowerSetupOutputBuilder().build());
97 ListenableFuture<RpcResult<ServicePowerSetupOutput>> output = this.olmPowerServiceRpc.servicePowerSetup(input);
98 assertTrue(output.get().isSuccessful());
99 assertEquals(new ServicePowerSetupOutputBuilder().build(), output.get().getResult());
103 void testServicePowerTurndown() throws InterruptedException, ExecutionException {
104 ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
105 when(this.olmPowerService.servicePowerTurndown(any()))
106 .thenReturn(new ServicePowerTurndownOutputBuilder().build());
107 var output = this.olmPowerServiceRpc.servicePowerTurndown(input);
108 assertTrue(output.get().isSuccessful());
109 assertEquals(new ServicePowerTurndownOutputBuilder().build(), output.get().getResult());
113 void testCalculateSpanlossBase() throws InterruptedException, ExecutionException {
114 CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInputAll();
115 when(this.olmPowerService.calculateSpanlossBase(any()))
116 .thenReturn(new CalculateSpanlossBaseOutputBuilder().build());
117 var output = this.olmPowerServiceRpc.calculateSpanlossBase(input);
118 assertTrue(output.get().isSuccessful());
119 assertEquals(new CalculateSpanlossBaseOutputBuilder().build(), output.get().getResult());
123 void testCalculateSpanlossCurrent() throws InterruptedException, ExecutionException {
124 CalculateSpanlossCurrentInput input = new CalculateSpanlossCurrentInputBuilder().build();
125 when(this.olmPowerService.calculateSpanlossCurrent(any()))
126 .thenReturn(new CalculateSpanlossCurrentOutputBuilder().build());
127 var output = this.olmPowerServiceRpc.calculateSpanlossCurrent(input);
128 assertTrue(output.get().isSuccessful());
129 assertEquals(new CalculateSpanlossCurrentOutputBuilder().build(), output.get().getResult());
133 void testServicePowerReset() throws InterruptedException, ExecutionException {
134 ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
135 when(this.olmPowerService.servicePowerReset(any()))
136 .thenReturn(new ServicePowerResetOutputBuilder().build());
137 var output = this.olmPowerServiceRpc.servicePowerReset(input);
138 assertTrue(output.get().isSuccessful());
139 assertEquals(new ServicePowerResetOutputBuilder().build(), output.get().getResult());