fix import extra separations
[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 import static org.mockito.Mockito.verifyZeroInteractions;
13
14 import com.google.common.util.concurrent.ListenableFuture;
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.rev171017.ServiceDeleteInputBuilder;
30 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.ServiceDeleteOutput;
31 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017.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     @Before
54     public void init() throws NoSuchMethodException {
55         MockitoAnnotations.initMocks(this);
56     }
57
58     @Test
59     public void performRendererNullServiceHandlerHeader() {
60         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
61         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer
62             .rev171017.ServiceDeleteInput serviceDeleteInput =
63                 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
64         serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceHandlerHeader(null).build();
65         ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
66                 ServiceNotificationTypes.ServiceDeleteResult);
67         Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
68                 response.getConfigurationResponseCommon().getAckFinalIndicator());
69         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
70                 response.getConfigurationResponseCommon().getResponseCode());
71         verifyZeroInteractions(this.rendererServiceOperationsMock);
72     }
73
74     @Test
75     public void performRendererNullServiceName() {
76         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
77         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer
78             .rev171017.ServiceDeleteInput serviceDeleteInput =
79                 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
80         serviceDeleteInput = new ServiceDeleteInputBuilder(serviceDeleteInput).setServiceName(null).build();
81         ServiceDeleteOutput response = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
82                 ServiceNotificationTypes.ServiceDeleteResult);
83         Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
84                 response.getConfigurationResponseCommon().getAckFinalIndicator());
85         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
86                 response.getConfigurationResponseCommon().getResponseCode());
87         verifyZeroInteractions(this.rendererServiceOperationsMock);
88     }
89
90     @Test
91     public void performRendererNullCommonId() {
92         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
93         input = new TempServiceDeleteInputBuilder(input).setCommonId(null).build();
94         ServiceDeleteOutput response =
95                 this.rendererServiceWrapperMock.performRenderer(input, ServiceNotificationTypes.ServiceDeleteResult);
96         Assert.assertEquals(ResponseCodes.FINAL_ACK_YES,
97                 response.getConfigurationResponseCommon().getAckFinalIndicator());
98         Assert.assertEquals(ResponseCodes.RESPONSE_FAILED,
99                 response.getConfigurationResponseCommon().getResponseCode());
100         verifyZeroInteractions(this.rendererServiceOperationsMock);
101     }
102
103
104     @Test
105     public void performRendererValid() {
106         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
107                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
108                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
109                 .build();
110         ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
111                 .setConfigurationResponseCommon(configurationResponseCommon).build();
112         ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
113         Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any(
114                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
115                 .ServiceDeleteInput.class))).thenReturn(response);
116         ServiceDeleteInput input = ServiceDataUtils.buildServiceDeleteInput();
117         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer
118             .rev171017.ServiceDeleteInput serviceDeleteInput =
119                 ModelMappingUtils.createServiceDeleteInput(new ServiceInput(input));
120         ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(serviceDeleteInput,
121                 ServiceNotificationTypes.ServiceDeleteResult);
122         Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
123                 rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
124         Assert.assertEquals(ResponseCodes.RESPONSE_OK,
125                 rendereResponse.getConfigurationResponseCommon().getResponseCode());
126         Assert.assertEquals("Renderer service delete in progress",
127                 rendereResponse.getConfigurationResponseCommon().getResponseMessage());
128         verify(this.rendererServiceOperationsMock).serviceDelete(any(
129                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
130                         .ServiceDeleteInput.class));
131     }
132
133     @Test
134     public void performRendererTempValid() {
135         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
136                 .setRequestId("request 1").setAckFinalIndicator(ResponseCodes.FINAL_ACK_NO)
137                 .setResponseCode(ResponseCodes.RESPONSE_OK).setResponseMessage("Renderer service delete in progress")
138                 .build();
139         ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
140                 .setConfigurationResponseCommon(configurationResponseCommon).build();
141         ListenableFuture<ServiceDeleteOutput> response = ServiceDataUtils.returnFuture(output);
142         Mockito.when(this.rendererServiceOperationsMock.serviceDelete(any(
143                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer.rev171017
144                 .ServiceDeleteInput.class))).thenReturn(response);
145         TempServiceDeleteInput input = ServiceDataUtils.buildTempServiceDeleteInput();
146         ServiceDeleteOutput rendereResponse = this.rendererServiceWrapperMock.performRenderer(input,
147                 ServiceNotificationTypes.ServiceDeleteResult);
148         Assert.assertEquals(ResponseCodes.FINAL_ACK_NO,
149                 rendereResponse.getConfigurationResponseCommon().getAckFinalIndicator());
150         Assert.assertEquals(ResponseCodes.RESPONSE_OK,
151                 rendereResponse.getConfigurationResponseCommon().getResponseCode());
152         Assert.assertEquals("Renderer service delete in progress",
153                 rendereResponse.getConfigurationResponseCommon().getResponseMessage());
154         verify(this.rendererServiceOperationsMock).serviceDelete(any(
155                 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.renderer
156                     .rev171017.ServiceDeleteInput.class));
157     }
158 }