Merge "Refactor ConvertORTopoToTapiTopoTest"
[transportpce.git] / servicehandler / src / test / java / org / opendaylight / transportpce / servicehandler / service / RendererServiceWrapperTest.java
1 /*
2  * Copyright © 2017 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 package org.opendaylight.transportpce.servicehandler.service;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.Mockito.verifyNoInteractions;
14 import static org.mockito.Mockito.when;
15
16 import com.google.common.util.concurrent.ListenableFuture;
17 import org.junit.jupiter.api.Test;
18 import org.junit.jupiter.api.extension.ExtendWith;
19 import org.mockito.InjectMocks;
20 import org.mockito.Mock;
21 import org.mockito.junit.jupiter.MockitoExtension;
22 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
23 import org.opendaylight.transportpce.common.ResponseCodes;
24 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
25 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
26 import org.opendaylight.transportpce.servicehandler.ServiceInput;
27 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
28 import org.opendaylight.transportpce.test.AbstractTest;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteOutputBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.ServiceNotificationTypes;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommon;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.configuration.response.common.ConfigurationResponseCommonBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.ServiceDeleteInput;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDeleteInput;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.TempServiceDeleteInputBuilder;
38
39 /**
40  * Test RendererServiceWrapper class.
41  *
42  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
43  *
44  */
45 @ExtendWith(MockitoExtension.class)
46 public class RendererServiceWrapperTest extends AbstractTest {
47     @Mock
48     private RendererServiceOperations rendererServiceOperationsMock;
49     @Mock
50     private NotificationPublishService notificationPublishService;
51     @InjectMocks
52     private RendererServiceWrapper rendererServiceWrapperMock;
53
54
55     @Test
56     void performRendererNullServiceHandlerHeader() {
57         var serviceDeleteInput = ModelMappingUtils
58             .createServiceDeleteInput(new ServiceInput(ServiceDataUtils.buildServiceDeleteInput()));
59         serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceHandlerHeader(null).build();
60         ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
61                 ServiceNotificationTypes.ServiceDeleteResult, null);
62         assertEquals(ResponseCodes.FINAL_ACK_YES,
63                 response.getConfigurationResponseCommon().getAckFinalIndicator());
64         assertEquals(ResponseCodes.RESPONSE_FAILED,
65                 response.getConfigurationResponseCommon().getResponseCode());
66         verifyNoInteractions(this.rendererServiceOperationsMock);
67     }
68
69     @Test
70     void performRendererNullServiceName() {
71         var serviceDeleteInput = ModelMappingUtils
72             .createServiceDeleteInput(new ServiceInput(ServiceDataUtils.buildServiceDeleteInput()));
73         serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceName(null).build();
74         ServiceDeleteOutput response = this.rendererServiceWrapperMock
75             .performRenderer(serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, null);
76         assertEquals(ResponseCodes.FINAL_ACK_YES, response.getConfigurationResponseCommon().getAckFinalIndicator());
77         assertEquals(ResponseCodes.RESPONSE_FAILED, response.getConfigurationResponseCommon().getResponseCode());
78         verifyNoInteractions(this.rendererServiceOperationsMock);
79     }
80
81     @Test
82     void performRendererNullCommonId() {
83         TempServiceDeleteInput input = new TempServiceDeleteInputBuilder(ServiceDataUtils.buildTempServiceDeleteInput())
84             .setCommonId(null).build();
85         ServiceDeleteOutput response = this.rendererServiceWrapperMock
86             .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult, null);
87         assertEquals(ResponseCodes.FINAL_ACK_YES, response.getConfigurationResponseCommon().getAckFinalIndicator());
88         assertEquals(ResponseCodes.RESPONSE_FAILED, response.getConfigurationResponseCommon().getResponseCode());
89         verifyNoInteractions(this.rendererServiceOperationsMock);
90     }
91
92     @Test
93     void performRendererValid() {
94         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
95             .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
96             .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
97             .build();
98         ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
99             .setConfigurationResponseCommon(configurationResponseCommon).build();
100         ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
101         when(this.rendererServiceOperationsMock.serviceDelete(any(
102                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
103                     .class), any()))
104             .thenReturn(response);
105         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
106         var serviceDeleteInput = ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
107         ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock
108             .performRenderer(serviceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, null);
109         assertEquals(
110             ResponseCodes.FINAL_ACK_NO,
111             rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
112         assertEquals(ResponseCodes.RESPONSE_OK, rendereResponse.getConfigurationResponseCommon().getResponseCode());
113         assertEquals(
114             "Renderer service delete in progress",
115             rendereResponse.getConfigurationResponseCommon().getResponseMessage());
116         verify(this.rendererServiceOperationsMock).serviceDelete(any(
117                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
118                     .class), any());
119     }
120
121     @Test
122     void performRendererTempValid() {
123         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
124             .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
125             .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
126             .build();
127         ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
128             .setConfigurationResponseCommon(configurationResponseCommon).build();
129         ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
130         when(this.rendererServiceOperationsMock.serviceDelete(any(
131                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
132                     .class), any()))
133             .thenReturn(response);
134         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
135         var tempServiceDeleteInput = ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
136         ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock
137             .performRenderer(tempServiceDeleteInput, ServiceNotificationTypes.ServiceDeleteResult, null);
138         assertEquals(
139             ResponseCodes.FINAL_ACK_NO,
140             rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
141         assertEquals(ResponseCodes.RESPONSE_OK, rendereResponse.getConfigurationResponseCommon().getResponseCode());
142         assertEquals(
143             "Renderer service delete in progress",
144             rendereResponse.getConfigurationResponseCommon().getResponseMessage());
145         verify(this.rendererServiceOperationsMock).serviceDelete(any(
146                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput
147                     .class), any());
148     }
149 }