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