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.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.verify;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.InjectMocks;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
22 import org.opendaylight.transportpce.common.ResponseCodes;
23 import org.opendaylight.transportpce.renderer.provisiondevice.RendererServiceOperations;
24 import org.opendaylight.transportpce.servicehandler.ModelMappingUtils;
25 import org.opendaylight.transportpce.servicehandler.ServiceInput;
26 import org.opendaylight.transportpce.servicehandler.utils.ServiceDataUtils;
27 import org.opendaylight.transportpce.test.AbstractTest;
28 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInputBuilder;
29 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteOutput;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteOutputBuilder;
31 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInput;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInputBuilder;
39 * Test RendererServiceWrapper class.
41 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
44 public class RendererServiceWrapperTest extends AbstractTest {
46 private RendererServiceOperations rendererServiceOperationsMock;
48 private NotificationPublishService notificationPublishService;
50 private RendererServiceWrapper rendererServiceWrapperMock;
53 public void init() throws NoSuchMethodException {
54 MockitoAnnotations.initMocks(this);
58 public void performRendererNullServiceHandlerHeader() {
59 ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
60 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
62 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
63 serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceHandlerHeader(null).build();
64 ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
65 ServiceNotificationTypes.ServiceDeleteResult, null);
66 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
67 response.getConfigurationResponseCommon().getAckFinalIndicator());
68 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
69 response.getConfigurationResponseCommon().getResponseCode());
70 Mockito.verifyNoInteractions(this.rendererServiceOperationsMock);
74 public void performRendererNullServiceName() {
75 ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
76 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
78 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
79 serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceName(null).build();
80 ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
81 ServiceNotificationTypes.ServiceDeleteResult, null);
82 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
83 response.getConfigurationResponseCommon().getAckFinalIndicator());
84 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
85 response.getConfigurationResponseCommon().getResponseCode());
86 Mockito.verifyNoInteractions(this.rendererServiceOperationsMock);
90 public void performRendererNullCommonId() {
91 TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
92 input = new TempServiceDeleteInputBuilder(input).setCommonId(null).build();
93 ServiceDeleteOutput response =
94 this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
95 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
96 response.getConfigurationResponseCommon().getAckFinalIndicator());
97 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
98 response.getConfigurationResponseCommon().getResponseCode());
99 Mockito.verifyNoInteractions(this.rendererServiceOperationsMock);
104 public void performRendererValid() {
105 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
106 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
107 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
109 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
110 .setConfigurationResponseCommon(configurationResponseCommon).build();
111 ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
112 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any(
113 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
114 .ServiceDeleteInput.class), any())).thenReturn(response);
115 ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
116 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
118 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
119 ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
120 ServiceNotificationTypes.ServiceDeleteResult, null);
121 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
122 rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
123 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
124 rendereResponse.getConfigurationResponseCommon().getResponseCode());
125 Assert.assertEquals("Renderer service delete in progress",
126 rendereResponse.getConfigurationResponseCommon().getResponseMessage());
127 verify(this.rendererServiceOperationsMock).serviceDelete(any(
128 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
129 .ServiceDeleteInput.class), any());
133 public void performRendererTempValid() {
134 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
135 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
136 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
138 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
139 .setConfigurationResponseCommon(configurationResponseCommon).build();
140 ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
141 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any(
142 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520
143 .ServiceDeleteInput.class), any())).thenReturn(response);
144 TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
145 ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(input,
146 ServiceNotificationTypes.ServiceDeleteResult);
147 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
148 rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
149 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
150 rendereResponse.getConfigurationResponseCommon().getResponseCode());
151 Assert.assertEquals("Renderer service delete in progress",
152 rendereResponse.getConfigurationResponseCommon().getResponseMessage());
153 verify(this.rendererServiceOperationsMock).serviceDelete(any(
154 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput