Technical debt - fix SH deprecated warnings
[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.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.verify;
12
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;
37
38 /**
39  * Test RendererServiceWrapper class.
40  *
41  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
42  *
43  */
44 public class RendererServiceWrapperTest extends AbstractTest {
45     @Mock
46     private RendererServiceOperations rendererServiceOperationsMock;
47     @Mock
48     private NotificationPublishService notificationPublishService;
49     @InjectMocks
50     private RendererServiceWrapper rendererServiceWrapperMock;
51
52     @Before
53     public void init() throws NoSuchMethodException {
54         MockitoAnnotations.initMocks(this);
55     }
56
57     @Test
58     public void performRendererNullServiceHandlerHeader() {
59         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
60         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
61             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);
71     }
72
73     @Test
74     public void performRendererNullServiceName() {
75         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
76         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev200520.ServiceDeleteInput
77             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);
87     }
88
89     @Test
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);
100     }
101
102
103     @Test
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")
108                 .build();
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
117             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());
130     }
131
132     @Test
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")
137                 .build();
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
155                     .class), any());
156     }
157 }