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.After;
15 import org.junit.Assert;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.InjectMocks;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.MockitoAnnotations;
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.rev201125.ServiceDeleteInputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteOutput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteOutputBuilder;
32 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.ServiceNotificationTypes;
33 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommon;
34 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev190531.configuration.response.common.ConfigurationResponseCommonBuilder;
35 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.ServiceDeleteInput;
36 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInput;
37 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev190531.TempServiceDeleteInputBuilder;
40 * Test RendererServiceWrapper class.
42 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
45 public class RendererServiceWrapperTest extends AbstractTest {
47 private RendererServiceOperations rendererServiceOperationsMock;
49 private NotificationPublishService notificationPublishService;
51 private RendererServiceWrapper rendererServiceWrapperMock;
53 private AutoCloseable closeable;
56 public void openMocks() throws NoSuchMethodException {
57 closeable = MockitoAnnotations.openMocks(this);
61 public void performRendererNullServiceHandlerHeader() {
62 ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
63 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteInput
65 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
66 serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceHandlerHeader(null).build();
67 ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
68 ServiceNotificationTypes.ServiceDeleteResult, null);
69 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
70 response.getConfigurationResponseCommon().getAckFinalIndicator());
71 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
72 response.getConfigurationResponseCommon().getResponseCode());
73 Mockito.verifyNoInteractions(this.rendererServiceOperationsMock);
77 public void performRendererNullServiceName() {
78 ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
79 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteInput
81 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
82 serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceName(null).build();
83 ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
84 ServiceNotificationTypes.ServiceDeleteResult, null);
85 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
86 response.getConfigurationResponseCommon().getAckFinalIndicator());
87 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
88 response.getConfigurationResponseCommon().getResponseCode());
89 Mockito.verifyNoInteractions(this.rendererServiceOperationsMock);
93 public void performRendererNullCommonId() {
94 TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
95 input = new TempServiceDeleteInputBuilder(input).setCommonId(null).build();
96 ServiceDeleteOutput response =
97 this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
98 Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
99 response.getConfigurationResponseCommon().getAckFinalIndicator());
100 Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
101 response.getConfigurationResponseCommon().getResponseCode());
102 Mockito.verifyNoInteractions(this.rendererServiceOperationsMock);
107 public void performRendererValid() {
108 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
109 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
110 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
112 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
113 .setConfigurationResponseCommon(configurationResponseCommon).build();
114 ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
115 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any(
116 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
117 .ServiceDeleteInput.class), any())).thenReturn(response);
118 ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
119 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteInput
121 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
122 ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
123 ServiceNotificationTypes.ServiceDeleteResult, null);
124 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
125 rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
126 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
127 rendereResponse.getConfigurationResponseCommon().getResponseCode());
128 Assert.assertEquals("Renderer service delete in progress",
129 rendereResponse.getConfigurationResponseCommon().getResponseMessage());
130 verify(this.rendererServiceOperationsMock).serviceDelete(any(
131 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
132 .ServiceDeleteInput.class), any());
136 public void performRendererTempValid() {
137 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
138 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
139 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
141 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
142 .setConfigurationResponseCommon(configurationResponseCommon).build();
143 ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
144 Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any(
145 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125
146 .ServiceDeleteInput.class), any())).thenReturn(response);
147 TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
148 ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(input,
149 ServiceNotificationTypes.ServiceDeleteResult);
150 Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
151 rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
152 Assert.assertEquals(ResponseCodes.RESPONSE_OK,
153 rendereResponse.getConfigurationResponseCommon().getResponseCode());
154 Assert.assertEquals("Renderer service delete in progress",
155 rendereResponse.getConfigurationResponseCommon().getResponseMessage());
156 verify(this.rendererServiceOperationsMock).serviceDelete(any(
157 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev201125.ServiceDeleteInput
161 @After public void releaseMocks() throws Exception {