Bump upstream dependencies to Ca
[transportpce.git] / olm / src / test / java / org / opendaylight / transportpce / olm / OlmPowerServiceRpcImplTest.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;
10
11
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;
18
19 import com.google.common.util.concurrent.ListenableFuture;
20 import java.util.concurrent.ExecutionException;
21 import org.junit.jupiter.api.Test;
22 import org.junit.jupiter.api.extension.ExtendWith;
23 import org.mockito.Mock;
24 import org.mockito.junit.jupiter.MockitoExtension;
25 import org.opendaylight.mdsal.binding.api.RpcProviderService;
26 import org.opendaylight.transportpce.olm.rpc.impl.CalculateSpanlossBaseImpl;
27 import org.opendaylight.transportpce.olm.rpc.impl.CalculateSpanlossCurrentImpl;
28 import org.opendaylight.transportpce.olm.rpc.impl.GetPmImpl;
29 import org.opendaylight.transportpce.olm.rpc.impl.ServicePowerResetImpl;
30 import org.opendaylight.transportpce.olm.rpc.impl.ServicePowerSetupImpl;
31 import org.opendaylight.transportpce.olm.rpc.impl.ServicePowerTurndownImpl;
32 import org.opendaylight.transportpce.olm.service.OlmPowerService;
33 import org.opendaylight.transportpce.olm.util.OlmPowerServiceRpcImplUtil;
34 import org.opendaylight.transportpce.test.AbstractTest;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseInput;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossBaseOutputBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInput;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentInputBuilder;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.CalculateSpanlossCurrentOutputBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInput;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmInputBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutput;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.GetPmOutputBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetInput;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerResetOutputBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupInput;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutput;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerSetupOutputBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownInput;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.olm.rev210618.ServicePowerTurndownOutputBuilder;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.resource.types.rev161014.ResourceTypeEnum;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.PmGranularity;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.common.types.rev220926.olm.get.pm.input.ResourceIdentifierBuilder;
54 import org.opendaylight.yangtools.yang.common.ErrorSeverity;
55 import org.opendaylight.yangtools.yang.common.ErrorTag;
56 import org.opendaylight.yangtools.yang.common.ErrorType;
57 import org.opendaylight.yangtools.yang.common.RpcResult;
58
59 @ExtendWith(MockitoExtension.class)
60 class OlmPowerServiceRpcImplTest extends AbstractTest {
61
62     @Mock
63     private OlmPowerService olmPowerService;
64     @Mock
65     private RpcProviderService rpcProviderService;
66
67     @Test
68     void testGetPmFailWithNodeIdNull() throws InterruptedException, ExecutionException {
69         GetPmInput input = new GetPmInputBuilder()
70             .setGranularity(PmGranularity._15min)
71             .setResourceIdentifier(new ResourceIdentifierBuilder()
72                     .setResourceName("ots-deg1").build())
73             .setResourceType(ResourceTypeEnum.Interface)
74             .build();
75         ListenableFuture<RpcResult<GetPmOutput>> output = new GetPmImpl(olmPowerService).invoke(input);
76         assertFalse(output.get().isSuccessful());
77         assertNull(output.get().getResult());
78         assertEquals(ErrorType.RPC, output.get().getErrors().get(0).getErrorType());
79         assertEquals("Error with input parameters", output.get().getErrors().get(0).getMessage());
80         assertEquals(ErrorSeverity.ERROR, output.get().getErrors().get(0).getSeverity());
81         assertEquals(ErrorTag.OPERATION_FAILED, output.get().getErrors().get(0).getTag());
82     }
83
84     @Test
85     void testGetPmWithSuccess() throws InterruptedException, ExecutionException {
86         GetPmInput input = new GetPmInputBuilder()
87             .setNodeId("nodeId")
88             .build();
89         when(this.olmPowerService.getPm(any())).thenReturn(new GetPmOutputBuilder().build());
90         ListenableFuture<RpcResult<GetPmOutput>> output = new GetPmImpl(olmPowerService).invoke(input);
91         assertTrue(output.get().isSuccessful());
92         assertEquals(new GetPmOutputBuilder().build(), output.get().getResult());
93     }
94
95     @Test
96     void testServicePowerSetup() throws InterruptedException, ExecutionException {
97         ServicePowerSetupInput input = OlmPowerServiceRpcImplUtil.getServicePowerSetupInput();
98         when(this.olmPowerService.servicePowerSetup(any())).thenReturn(new ServicePowerSetupOutputBuilder().build());
99         ListenableFuture<RpcResult<ServicePowerSetupOutput>> output =
100             new ServicePowerSetupImpl(olmPowerService).invoke(input);
101         assertTrue(output.get().isSuccessful());
102         assertEquals(new ServicePowerSetupOutputBuilder().build(), output.get().getResult());
103     }
104
105     @Test
106     void testServicePowerTurndown() throws InterruptedException, ExecutionException {
107         ServicePowerTurndownInput input = OlmPowerServiceRpcImplUtil.getServicePowerTurndownInput();
108         when(this.olmPowerService.servicePowerTurndown(any()))
109             .thenReturn(new ServicePowerTurndownOutputBuilder().build());
110         var output = new ServicePowerTurndownImpl(olmPowerService).invoke(input);
111         assertTrue(output.get().isSuccessful());
112         assertEquals(new ServicePowerTurndownOutputBuilder().build(), output.get().getResult());
113     }
114
115     @Test
116     void testCalculateSpanlossBase() throws InterruptedException, ExecutionException {
117         CalculateSpanlossBaseInput input = OlmPowerServiceRpcImplUtil.getCalculateSpanlossBaseInputAll();
118         when(this.olmPowerService.calculateSpanlossBase(any()))
119             .thenReturn(new CalculateSpanlossBaseOutputBuilder().build());
120         var output = new CalculateSpanlossBaseImpl(olmPowerService).invoke(input);
121         assertTrue(output.get().isSuccessful());
122         assertEquals(new CalculateSpanlossBaseOutputBuilder().build(), output.get().getResult());
123     }
124
125     @Test
126     void testCalculateSpanlossCurrent() throws InterruptedException, ExecutionException {
127         CalculateSpanlossCurrentInput input = new CalculateSpanlossCurrentInputBuilder().build();
128         when(this.olmPowerService.calculateSpanlossCurrent(any()))
129             .thenReturn(new CalculateSpanlossCurrentOutputBuilder().build());
130         var output = new CalculateSpanlossCurrentImpl(olmPowerService).invoke(input);
131         assertTrue(output.get().isSuccessful());
132         assertEquals(new CalculateSpanlossCurrentOutputBuilder().build(), output.get().getResult());
133     }
134
135     @Test
136     void testServicePowerReset() throws InterruptedException, ExecutionException {
137         ServicePowerResetInput input = OlmPowerServiceRpcImplUtil.getServicePowerResetInput();
138         when(this.olmPowerService.servicePowerReset(any()))
139             .thenReturn(new ServicePowerResetOutputBuilder().build());
140         var output = new ServicePowerResetImpl(olmPowerService).invoke(input);
141         assertTrue(output.get().isSuccessful());
142         assertEquals(new ServicePowerResetOutputBuilder().build(), output.get().getResult());
143     }
144 }