33036ff38b1e5f4b7dcff9ffbf88ce7aa495cb4a
[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.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.rev210618.ServiceDeleteInputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.ServiceDeleteOutput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.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;
38
39 /**
40  * Test RendererServiceWrapper class.
41  *
42  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
43  *
44  */
45 public class RendererServiceWrapperTest extends AbstractTest {
46     @Mock
47     private RendererServiceOperations rendererServiceOperationsMock;
48     @Mock
49     private NotificationPublishService notificationPublishService;
50     @InjectMocks
51     private RendererServiceWrapper rendererServiceWrapperMock;
52
53     private AutoCloseable closeable;
54
55     @Before
56     public void openMocks() throws NoSuchMethodException {
57         closeable = MockitoAnnotations.openMocks(this);
58     }
59
60     @Test
61     public void performRendererNullServiceHandlerHeader() {
62         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
63         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.ServiceDeleteInput
64             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);
74     }
75
76     @Test
77     public void performRendererNullServiceName() {
78         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
79         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.ServiceDeleteInput
80             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);
90     }
91
92     @Test
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);
103     }
104
105
106     @Test
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")
111                 .build();
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.rev210618
117                 .ServiceDeleteInput.class), any())).thenReturn(response);
118         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
119         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev210618.ServiceDeleteInput
120             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.rev210618
132                         .ServiceDeleteInput.class), any());
133     }
134
135     @Test
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")
140                 .build();
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.rev210618
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.rev210618.ServiceDeleteInput
158                     .class), any());
159     }
160
161     @After public void releaseMocks() throws Exception {
162         closeable.close();
163     }
164 }