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