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