2 * Copyright © 2017 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
8 package org.opendaylight.transportpce.servicehandler.service;
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;
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.rev211210.ServiceNotificationTypes;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommon;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.configuration.response.common.ConfigurationResponseCommonBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.ServiceDeleteInput;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInput;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.TempServiceDeleteInputBuilder;
40 * Test RendererServiceWrapper class.
42 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
45 @ExtendWith(MockitoExtension.class)
46 public class RendererServiceWrapperTest extends AbstractTest {
48 private RendererServiceOperations rendererServiceOperationsMock;
50 private NotificationPublishService notificationPublishService;
52 private RendererServiceWrapper rendererServiceWrapperMock;
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);
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);
82 void performRendererNullCommonId() {
83 TempServiceDeleteInput input = new TempServiceDeleteInputBuilder(ServiceDataUtils.buildTempServiceDeleteInput())
84 .setCommonId(null).build();
85 ServiceDeleteOutput response = this.rendererServiceWrapperMock
86 .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
87 assertEquals(ResponseCodes.FINAL_ACK_YES, response.getConfigurationResponseCommon().getAckFinalIndicator());
88 assertEquals(ResponseCodes.RESPONSE_FAILED, response.getConfigurationResponseCommon().getResponseCode());
89 verifyNoInteractions(this.rendererServiceOperationsMock);
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")
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
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);
110 ResponseCodes.FINAL_ACK_NO,
111 rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
112 assertEquals(ResponseCodes.RESPONSE_OK, rendereResponse.getConfigurationResponseCommon().getResponseCode());
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
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")
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
133 .thenReturn(response);
134 TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
135 ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock
136 .performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
138 ResponseCodes.FINAL_ACK_NO,
139 rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
140 assertEquals(ResponseCodes.RESPONSE_OK, rendereResponse.getConfigurationResponseCommon().getResponseCode());
142 "Renderer service delete in progress",
143 rendereResponse.getConfigurationResponseCommon().getResponseMessage());
144 verify(this.rendererServiceOperationsMock).serviceDelete(any(
145 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210915.ServiceDeleteInput