Fix locally failing TCs in catalog-be
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / servlets / InputsServletTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 Fujitsu Limited. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.servlets;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.eq;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.never;
29 import static org.mockito.Mockito.times;
30 import static org.mockito.Mockito.verify;
31 import static org.mockito.Mockito.when;
32
33 import fj.data.Either;
34 import java.util.ArrayList;
35 import java.util.Collections;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Map;
39 import javax.servlet.ServletContext;
40 import javax.servlet.http.HttpServletRequest;
41 import javax.servlet.http.HttpSession;
42 import javax.ws.rs.client.Entity;
43 import javax.ws.rs.client.Invocation;
44 import javax.ws.rs.core.Application;
45 import javax.ws.rs.core.MediaType;
46 import javax.ws.rs.core.Response;
47 import org.glassfish.grizzly.http.util.HttpStatus;
48 import org.glassfish.hk2.utilities.binding.AbstractBinder;
49 import org.glassfish.jersey.server.ResourceConfig;
50 import org.glassfish.jersey.test.JerseyTest;
51 import org.glassfish.jersey.test.TestProperties;
52 import org.junit.jupiter.api.AfterEach;
53 import org.junit.jupiter.api.BeforeAll;
54 import org.junit.jupiter.api.BeforeEach;
55 import org.junit.jupiter.api.Test;
56 import org.mockito.ArgumentCaptor;
57 import org.mockito.Mockito;
58 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
59 import org.openecomp.sdc.be.components.impl.DataTypeBusinessLogic;
60 import org.openecomp.sdc.be.components.impl.GroupBusinessLogic;
61 import org.openecomp.sdc.be.components.impl.InputsBusinessLogic;
62 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
63 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
64 import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
65 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
66 import org.openecomp.sdc.be.config.ConfigurationManager;
67 import org.openecomp.sdc.be.config.SpringConfig;
68 import org.openecomp.sdc.be.dao.api.ActionStatus;
69 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
70 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
71 import org.openecomp.sdc.be.impl.ComponentsUtils;
72 import org.openecomp.sdc.be.impl.ServletUtils;
73 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
74 import org.openecomp.sdc.be.model.ComponentInstInputsMap;
75 import org.openecomp.sdc.be.model.ComponentInstListInput;
76 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
77 import org.openecomp.sdc.be.model.DataTypeDefinition;
78 import org.openecomp.sdc.be.model.InputDefinition;
79 import org.openecomp.sdc.be.model.User;
80 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
81 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
82 import org.openecomp.sdc.be.servlets.exception.ComponentExceptionMapper;
83 import org.openecomp.sdc.be.user.UserBusinessLogic;
84 import org.openecomp.sdc.common.api.ConfigurationSource;
85 import org.openecomp.sdc.common.api.Constants;
86 import org.openecomp.sdc.common.impl.ExternalConfiguration;
87 import org.openecomp.sdc.common.impl.FSConfigurationSource;
88 import org.openecomp.sdc.exception.ResponseFormat;
89 import org.springframework.context.ApplicationContext;
90 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
91 import org.springframework.web.context.WebApplicationContext;
92
93 class InputsServletTest extends JerseyTest {
94
95     /* Constants */
96     private static final String RESOURCE_ID = "serviceId";
97     private static final String USER_ID = "userId";
98     private static final String COMPONENT_INSTANCE_ID = "instanceId";
99     private static final String COMPONENT_ID = "componentId";
100     private static final String INSTANCE_INPUT_ID = "inputId";
101     private static final String LISTINPUT_NAME = "listInput";
102     private static final String LISTINPUT_SCHEMA_TYPE = "org.onap.datatypes.listinput";
103     private static final String LISTINPUT_PROP1_NAME = "prop1";
104     private static final String LISTINPUT_PROP1_TYPE = "string";
105     private static final String LISTINPUT_PROP2_NAME = "prop2";
106     private static final String LISTINPUT_PROP2_TYPE = "integer";
107
108     /* Mocks */
109     private static UserBusinessLogic userBusinessLogic;
110     private static InputsBusinessLogic inputsBusinessLogic;
111     private static DataTypeBusinessLogic dataTypeBusinessLogic;
112     private static GroupBusinessLogic groupBL;
113     private static ComponentInstanceBusinessLogic componentInstanceBL;
114     private static HttpSession httpSession;
115     private static ServletContext servletContext;
116     private static WebApplicationContext webApplicationContext;
117     private static ComponentsUtils componentsUtils;
118     private static ServletUtils servletUtils;
119     private static ResourceImportManager resourceImportManager;
120     private static HttpServletRequest request;
121
122     String appConfigDir = "src/test/resources/config/catalog-be";
123     ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
124         appConfigDir);
125     ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
126
127     @BeforeAll
128     public static void configureMocks() {
129         request = mock(HttpServletRequest.class);
130         userBusinessLogic = mock(UserBusinessLogic.class);
131         inputsBusinessLogic = mock(InputsBusinessLogic.class);
132         groupBL = mock(GroupBusinessLogic.class);
133         componentInstanceBL = mock(ComponentInstanceBusinessLogic.class);
134         dataTypeBusinessLogic = mock(DataTypeBusinessLogic.class);
135         servletContext = mock(ServletContext.class);
136         httpSession = mock(HttpSession.class);
137         webApplicationContext = mock(WebApplicationContext.class);
138         componentsUtils = mock(ComponentsUtils.class);
139         servletUtils = mock(ServletUtils.class);
140         resourceImportManager = mock(ResourceImportManager.class);
141
142
143     }
144
145     @BeforeEach
146     public void before() throws Exception {
147         super.setUp();
148         Mockito.reset(resourceImportManager);
149         Mockito.reset(servletUtils);
150         Mockito.reset(componentsUtils);
151         Mockito.reset(webApplicationContext);
152         Mockito.reset(httpSession);
153         Mockito.reset(servletContext);
154         Mockito.reset(dataTypeBusinessLogic);
155         Mockito.reset(componentInstanceBL);
156         Mockito.reset(groupBL);
157         Mockito.reset(inputsBusinessLogic);
158         Mockito.reset(userBusinessLogic);
159         Mockito.reset(request);
160
161         when(request.getSession()).thenReturn(httpSession);
162         when(httpSession.getServletContext()).thenReturn(servletContext);
163         when(servletContext.getAttribute(
164             Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(new WebAppContextWrapper());
165         when(servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE))
166             .thenReturn(webApplicationContext);
167         when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
168     }
169
170     @AfterEach
171     public void tearDown() throws Exception {
172         super.tearDown();
173     }
174
175     @Override
176     protected Application configure() {
177         InputsServlet inputsServlet = new InputsServlet(userBusinessLogic, inputsBusinessLogic,
178             componentInstanceBL, componentsUtils,
179             servletUtils, resourceImportManager, dataTypeBusinessLogic);
180         forceSet(TestProperties.CONTAINER_PORT, "0");
181         ResourceConfig resourceConfig = new ResourceConfig()
182             .register(inputsServlet)
183             .register(new ComponentExceptionMapper(componentsUtils))
184             .register(new AbstractBinder() {
185                 @Override
186                 protected void configure() {
187                     bind(request).to(HttpServletRequest.class);
188                 }
189             });
190
191         ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
192         resourceConfig.property("contextConfig", context);
193         return resourceConfig;
194     }
195
196     private InputDefinition setUpListInput() {
197         InputDefinition listInput = new InputDefinition();
198         listInput.setName(LISTINPUT_NAME);
199         listInput.setType("list");
200         SchemaDefinition listInputSchema = new SchemaDefinition();
201         listInputSchema.setProperty(new PropertyDataDefinitionBuilder()
202             .setType(LISTINPUT_SCHEMA_TYPE)
203             .setIsRequired(false)
204             .build()
205         );
206         listInput.setSchema(listInputSchema);
207         return listInput;
208     }
209
210     private ComponentInstListInput setUpCreateListInputParams() {
211         ComponentInstListInput componentInstListInput = new ComponentInstListInput();
212
213         // Create a "list input"
214         InputDefinition listInput = setUpListInput();
215         componentInstListInput.setListInput(listInput);
216
217         // Create ComponentInstancePropInputs
218         // for inputs in the ComponentInstance
219         Map<String, List<ComponentInstancePropInput>> propInputsListMap = new HashMap<>();
220         // Add 2 PropInputs. property owner is COMPONENT_INSTANCE_ID
221         List<ComponentInstancePropInput> propInputsList = new ArrayList<>();
222         ComponentInstancePropInput propInput = new ComponentInstancePropInput();
223         propInput.setName(LISTINPUT_PROP1_NAME);
224         propInput.setType(LISTINPUT_PROP1_TYPE);
225         propInput.setUniqueId(COMPONENT_INSTANCE_ID + "." + LISTINPUT_PROP1_NAME);
226         propInputsList.add(propInput);
227         propInput = new ComponentInstancePropInput();
228         propInput.setName(LISTINPUT_PROP2_NAME);
229         propInput.setType(LISTINPUT_PROP2_TYPE);
230         propInput.setUniqueId(COMPONENT_INSTANCE_ID + "." + LISTINPUT_PROP2_NAME);
231         propInputsList.add(propInput);
232         propInputsListMap.put(COMPONENT_INSTANCE_ID, propInputsList);
233         ComponentInstInputsMap componentInstInputsMap = new ComponentInstInputsMap();
234         componentInstInputsMap.setComponentInstanceInputsMap(propInputsListMap);
235         componentInstListInput.setComponentInstInputsMap(componentInstInputsMap);
236
237         return componentInstListInput;
238     }
239
240     @Test
241     void test_createListInput_success() throws Exception {
242         ComponentInstListInput requestBodyObj = setUpCreateListInputParams();
243         Entity<ComponentInstListInput> entity = Entity.entity(requestBodyObj, MediaType.APPLICATION_JSON);
244
245         doReturn(Either.left(requestBodyObj)).when(componentsUtils)
246             .convertJsonToObjectUsingObjectMapper(any(), any(), eq(ComponentInstListInput.class),
247                 eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE));
248
249         doReturn(Either.left(Collections.emptyList())).when(inputsBusinessLogic)
250             .createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE),
251                 any(), eq(true), eq(false));
252
253         ResponseFormat responseFormat = new ResponseFormat(HttpStatus.OK_200.getStatusCode());
254         doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.OK);
255
256         Response response = buildCreateListInputCall().post(entity);
257         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
258         verify(inputsBusinessLogic, times(1)).createListInput(USER_ID, RESOURCE_ID,
259             ComponentTypeEnum.SERVICE, requestBodyObj, true, false);
260     }
261
262     @Test
263     void test_createListInput_fail_parse() throws Exception {
264         ComponentInstListInput requestBodyObj = setUpCreateListInputParams();
265         Entity<ComponentInstListInput> entity = Entity.entity(requestBodyObj, MediaType.APPLICATION_JSON);
266
267         // for parseToComponentInstListInput
268         ArgumentCaptor<User> userCaptor = ArgumentCaptor.forClass(User.class);
269         when(componentsUtils
270             .convertJsonToObjectUsingObjectMapper(any(), userCaptor.capture(), eq(ComponentInstListInput.class),
271                 eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE)))
272             .thenReturn(Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode())));
273
274         when(inputsBusinessLogic.createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE),
275             any(), eq(true), eq(false)))
276             .thenReturn(Either.left(Collections.emptyList()));
277
278         Response response = buildCreateListInputCall().post(entity);
279         assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
280         verify(componentsUtils, times(1))
281             .convertJsonToObjectUsingObjectMapper(any(), any(), eq(ComponentInstListInput.class),
282                 eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE));
283         assertThat(userCaptor.getValue().getUserId()).isEqualTo(USER_ID);
284         verify(inputsBusinessLogic, never()).createListInput(USER_ID, RESOURCE_ID,
285             ComponentTypeEnum.SERVICE, requestBodyObj, true, false);
286     }
287
288
289     @Test
290     void test_createListInput_fail_createInput() throws Exception {
291         ComponentInstListInput requestBodyObj = setUpCreateListInputParams();
292         Entity<ComponentInstListInput> entity = Entity.entity(requestBodyObj, MediaType.APPLICATION_JSON);
293
294         // for parseToComponentInstListInput
295         ArgumentCaptor<User> userCaptor = ArgumentCaptor.forClass(User.class);
296         when(componentsUtils
297             .convertJsonToObjectUsingObjectMapper(any(), userCaptor.capture(), eq(ComponentInstListInput.class),
298                 eq(AuditingActionEnum.CREATE_RESOURCE), eq(ComponentTypeEnum.SERVICE)))
299             .thenReturn(Either.left(requestBodyObj));
300
301         when(inputsBusinessLogic.createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE),
302             any(), eq(true), eq(false)))
303             .thenReturn(Either.right(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode())));
304
305         Response response = buildCreateListInputCall().post(entity);
306         assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
307         verify(inputsBusinessLogic, times(1))
308             .createListInput(eq(USER_ID), eq(RESOURCE_ID), eq(ComponentTypeEnum.SERVICE),
309                 any(), eq(true), eq(false));
310     }
311
312
313     @Test
314     void test_createListInput_fail_exception() throws Exception {
315         ComponentInstListInput requestBodyObj = setUpCreateListInputParams();
316         Entity<ComponentInstListInput> entity = Entity.entity(requestBodyObj, MediaType.APPLICATION_JSON);
317
318         when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR))
319             .thenReturn(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode()));
320
321         Response response = buildCreateListInputCall().post(entity);
322         assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
323     }
324
325     @Test
326     void test_getDataType_success() throws Exception {
327         when(dataTypeBusinessLogic.getPrivateDataType(eq(RESOURCE_ID), eq(LISTINPUT_SCHEMA_TYPE)))
328             .thenReturn(Either.left(new DataTypeDefinition()));
329
330         ResponseFormat responseFormat = new ResponseFormat();
331         responseFormat.setStatus(HttpStatus.OK_200.getStatusCode());
332         when(componentsUtils.getResponseFormat(eq(ActionStatus.OK))).thenReturn(responseFormat);
333
334         Response response = buildGetDataTypeCall().get();
335         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
336     }
337
338     @Test
339     void test_getDataType_fail() throws Exception {
340         when(dataTypeBusinessLogic.getPrivateDataType(eq(RESOURCE_ID), eq(LISTINPUT_SCHEMA_TYPE)))
341             .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
342
343         ResponseFormat responseFormat = new ResponseFormat();
344         responseFormat.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
345         when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.BAD_REQUEST)))
346             .thenReturn(ActionStatus.GENERAL_ERROR);
347         when(componentsUtils.getResponseFormat(eq(ActionStatus.GENERAL_ERROR))).thenReturn(responseFormat);
348
349         Response response = buildGetDataTypeCall().get();
350         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
351     }
352
353     @Test
354     void test_getDataType_fail_exception() throws Exception {
355         when(dataTypeBusinessLogic.getPrivateDataType(eq(RESOURCE_ID), eq(LISTINPUT_SCHEMA_TYPE)))
356             .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
357         when(componentsUtils.getResponseFormat(eq(ActionStatus.GENERAL_ERROR)))
358             .thenReturn(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode()));
359
360         Response response = buildGetDataTypeCall().get();
361         assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
362     }
363
364     @Test
365     void test_getDataTypes_success() throws Exception {
366         when(dataTypeBusinessLogic.getPrivateDataTypes(eq(RESOURCE_ID)))
367             .thenReturn(Either.left(Collections.emptyList()));
368
369         ResponseFormat responseFormat = new ResponseFormat();
370         responseFormat.setStatus(HttpStatus.OK_200.getStatusCode());
371         when(componentsUtils.getResponseFormat(eq(ActionStatus.OK))).thenReturn(responseFormat);
372
373         Response response = buildGetDataTypesCall().get();
374         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
375     }
376
377     @Test
378     void test_getDataTypes_fail() throws Exception {
379         when(dataTypeBusinessLogic.getPrivateDataTypes(eq(RESOURCE_ID)))
380             .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
381
382         ResponseFormat responseFormat = new ResponseFormat();
383         responseFormat.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
384         when(componentsUtils.convertFromStorageResponse(eq(StorageOperationStatus.BAD_REQUEST)))
385             .thenReturn(ActionStatus.GENERAL_ERROR);
386         when(componentsUtils.getResponseFormat(eq(ActionStatus.GENERAL_ERROR))).thenReturn(responseFormat);
387
388         Response response = buildGetDataTypesCall().get();
389         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
390     }
391
392     @Test
393     void test_getDataTypes_fail_exception() throws Exception {
394         when(dataTypeBusinessLogic.getPrivateDataType(eq(RESOURCE_ID), eq(LISTINPUT_SCHEMA_TYPE)))
395             .thenReturn(Either.right(StorageOperationStatus.BAD_REQUEST));
396         when(componentsUtils.getResponseFormat(eq(ActionStatus.GENERAL_ERROR)))
397             .thenReturn(new ResponseFormat(HttpStatus.BAD_REQUEST_400.getStatusCode()));
398
399         Response response = buildGetDataTypesCall().get();
400         assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
401     }
402
403     @Test
404     void test_deleteDataType_success() throws Exception {
405         when(dataTypeBusinessLogic.deletePrivateDataType(RESOURCE_ID, LISTINPUT_SCHEMA_TYPE))
406             .thenReturn(Either.left(new DataTypeDefinition()));
407
408         when(componentsUtils.getResponseFormat(ActionStatus.OK))
409             .thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
410
411         Response response = buildGetDataTypeCall().delete();
412         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
413     }
414
415     @Test
416     void test_deleteDataType_failure_exception() throws Exception {
417         when(componentsUtils.getResponseFormat(ActionStatus.OK))
418             .thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
419         when(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR))
420             .thenReturn(new ResponseFormat(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode()));
421         Response response = buildGetDataTypeCall().delete();
422         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500.getStatusCode());
423         verify(componentsUtils, never()).getResponseFormat(ActionStatus.OK);
424     }
425
426     @Test
427     void test_deleteDataType_failure_notFound() throws Exception {
428         when(componentsUtils.getResponseFormat(ActionStatus.OK))
429             .thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
430         when(dataTypeBusinessLogic.deletePrivateDataType(RESOURCE_ID, LISTINPUT_SCHEMA_TYPE))
431             .thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
432         when(componentsUtils.convertFromStorageResponse(StorageOperationStatus.NOT_FOUND))
433             .thenReturn(ActionStatus.ARTIFACT_NOT_FOUND);
434         when(componentsUtils.getResponseFormat(ActionStatus.ARTIFACT_NOT_FOUND))
435             .thenReturn(new ResponseFormat(HttpStatus.NOT_FOUND_404.getStatusCode()));
436         Response response = buildGetDataTypeCall().delete();
437         assertThat(response.getStatus()).isEqualTo(HttpStatus.NOT_FOUND_404.getStatusCode());
438         verify(componentsUtils, never()).getResponseFormat(ActionStatus.OK);
439     }
440
441     @Test
442     void test_deleteInput_success() throws Exception {
443         when(inputsBusinessLogic.deleteInput(RESOURCE_ID, USER_ID, LISTINPUT_NAME))
444             .thenReturn(new InputDefinition());
445         when(componentsUtils.getResponseFormat(ActionStatus.OK))
446             .thenReturn(new ResponseFormat(HttpStatus.OK_200.getStatusCode()));
447
448         // invoke delete call
449         Response response = target("/v1/catalog/services/{id}/delete/{inputId}/input")
450             .resolveTemplate("id", RESOURCE_ID)
451             .resolveTemplate("inputId", LISTINPUT_NAME)
452             .request(MediaType.APPLICATION_JSON)
453             .header(Constants.USER_ID_HEADER, USER_ID)
454             .delete();
455         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200.getStatusCode());
456         verify(inputsBusinessLogic, times(1)).deleteInput(RESOURCE_ID, USER_ID, LISTINPUT_NAME);
457     }
458
459     @Test
460     void test_deleteInput_failure_deleteInput() throws Exception {
461         ComponentException componentException = new ByActionStatusComponentException(ActionStatus.INVALID_CONTENT);
462         when(inputsBusinessLogic.deleteInput(RESOURCE_ID, USER_ID, LISTINPUT_NAME))
463             .thenThrow(componentException);
464
465         // invoke delete call
466         Response response = target("/v1/catalog/services/{id}/delete/{inputId}/input")
467             .resolveTemplate("id", RESOURCE_ID)
468             .resolveTemplate("inputId", LISTINPUT_NAME)
469             .request(MediaType.APPLICATION_JSON)
470             .header(Constants.USER_ID_HEADER, USER_ID)
471             .delete();
472         assertThat(response.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST_400.getStatusCode());
473         verify(componentsUtils, never()).getResponseFormat(ActionStatus.OK);
474     }
475
476     private Invocation.Builder buildCreateListInputCall() {
477         return target("/v1/catalog/services/{id}/create/listInput")
478             .resolveTemplate("id", RESOURCE_ID)
479             .request(MediaType.APPLICATION_JSON)
480             .header(Constants.USER_ID_HEADER, USER_ID);
481     }
482
483     private Invocation.Builder buildGetDataTypeCall() {
484         return target("/v1/catalog/services/{id}/dataType/{dataTypeName}")
485             .resolveTemplate("id", RESOURCE_ID)
486             .resolveTemplate("dataTypeName", LISTINPUT_SCHEMA_TYPE)
487             .request(MediaType.APPLICATION_JSON)
488             .header(Constants.USER_ID_HEADER, USER_ID);
489     }
490
491     private Invocation.Builder buildGetDataTypesCall() {
492         return target("/v1/catalog/services/{id}/dataTypes")
493             .resolveTemplate("id", RESOURCE_ID)
494             .request(MediaType.APPLICATION_JSON)
495             .header(Constants.USER_ID_HEADER, USER_ID);
496     }
497
498 }