Delete node_filter capabilities
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / servlets / ComponentNodeFilterServletTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation
4  *  ================================================================================
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.openecomp.sdc.be.servlets;
21
22 import static org.assertj.core.api.Assertions.assertThat;
23 import static org.junit.Assert.assertNotNull;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.ArgumentMatchers.anyBoolean;
26 import static org.mockito.ArgumentMatchers.anyInt;
27 import static org.mockito.ArgumentMatchers.anyList;
28 import static org.mockito.ArgumentMatchers.anyString;
29 import static org.mockito.ArgumentMatchers.nullable;
30 import static org.mockito.Mockito.mock;
31 import static org.mockito.Mockito.reset;
32 import static org.mockito.Mockito.times;
33 import static org.mockito.Mockito.verify;
34 import static org.mockito.Mockito.when;
35 import static org.openecomp.sdc.common.api.Constants.USER_ID_HEADER;
36
37 import com.fasterxml.jackson.core.JsonProcessingException;
38 import com.fasterxml.jackson.databind.ObjectMapper;
39 import fj.data.Either;
40 import java.util.Arrays;
41 import java.util.Collections;
42 import java.util.LinkedList;
43 import java.util.List;
44 import java.util.Map;
45 import java.util.Optional;
46 import javax.servlet.ServletContext;
47 import javax.servlet.http.HttpServletRequest;
48 import javax.servlet.http.HttpSession;
49 import javax.ws.rs.client.Entity;
50 import javax.ws.rs.core.MediaType;
51 import javax.ws.rs.core.Response;
52 import org.eclipse.jetty.http.HttpStatus;
53 import org.glassfish.hk2.utilities.binding.AbstractBinder;
54 import org.glassfish.jersey.server.ResourceConfig;
55 import org.glassfish.jersey.test.JerseyTest;
56 import org.glassfish.jersey.test.TestProperties;
57 import org.junit.jupiter.api.AfterEach;
58 import org.junit.jupiter.api.BeforeAll;
59 import org.junit.jupiter.api.BeforeEach;
60 import org.junit.jupiter.api.Test;
61 import org.mockito.ArgumentMatchers;
62 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
63 import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic;
64 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
65 import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
66 import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
67 import org.openecomp.sdc.be.components.validation.UserValidations;
68 import org.openecomp.sdc.be.config.SpringConfig;
69 import org.openecomp.sdc.be.dao.api.ActionStatus;
70 import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
71 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
72 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
73 import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
74 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
75 import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
76 import org.openecomp.sdc.be.impl.ComponentsUtils;
77 import org.openecomp.sdc.be.impl.ServletUtils;
78 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
79 import org.openecomp.sdc.be.model.User;
80 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
81 import org.openecomp.sdc.be.ui.model.UIConstraint;
82 import org.openecomp.sdc.be.user.Role;
83 import org.openecomp.sdc.be.user.UserBusinessLogic;
84 import org.openecomp.sdc.common.api.Constants;
85 import org.openecomp.sdc.exception.ResponseFormat;
86 import org.springframework.context.ApplicationContext;
87 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
88 import org.springframework.web.context.WebApplicationContext;
89
90 public class ComponentNodeFilterServletTest extends JerseyTest {
91     private static final String USER_ID = "jh0003";
92     private static final String servicePropertyName = "resourceType";
93     private static final String constraintOperator = "equal";
94     private static final String sourceType = "static";
95     private static final String sourceName = sourceType;
96     private static final String propertyValue = "resourceTypeValue";
97     private static final String componentId = "dac65869-dfb4-40d2-aa20-084324659ec1";
98     private static final String componentInstance = "dac65869-dfb4-40d2-aa20-084324659ec1.resource0";
99     private static final String componentType = "resources";
100
101     private static HttpServletRequest request;
102     private static HttpSession session;
103     private static ServletContext servletContext;
104     private static WebAppContextWrapper webAppContextWrapper;
105     private static WebApplicationContext webApplicationContext;
106     private static UserBusinessLogic userBusinessLogic;
107     private static ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
108     private static ComponentsUtils componentsUtils;
109     private static ServletUtils servletUtils;
110     private static ResourceImportManager resourceImportManager;
111     private static ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
112     private static ResponseFormat responseFormat;
113     private static UserValidations userValidations;
114
115     private CINodeFilterDataDefinition ciNodeFilterDataDefinition;
116     private RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition;
117     private UIConstraint uiConstraint;
118     private String constraint;
119     private String inputJson;
120     private User user;
121
122     @BeforeAll
123     public static void initClass() {
124         createMocks();
125         when(request.getSession()).thenReturn(session);
126         when(session.getServletContext()).thenReturn(servletContext);
127         when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
128         when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
129         when(webApplicationContext.getBean(ComponentNodeFilterBusinessLogic.class)).thenReturn(componentNodeFilterBusinessLogic);
130         when(request.getHeader("USER_ID")).thenReturn(USER_ID);
131         when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
132         when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
133     }
134
135     @BeforeEach
136     public void resetMock() throws Exception {
137         super.setUp();
138         reset(componentNodeFilterBusinessLogic);
139     }
140
141     @AfterEach
142     void after() throws Exception {
143         super.tearDown();
144     }
145
146     @Test
147     public void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
148         initComponentData();
149         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
150         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
151             NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
152
153         when(userValidations.validateUserExists(user)).thenReturn(user);
154         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
155         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
156         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
157
158         assertNotNull(uiConstraint);
159         assertThat(servicePropertyName).isEqualToIgnoringCase(uiConstraint.getServicePropertyName());
160         assertThat(constraintOperator).isEqualToIgnoringCase(uiConstraint.getConstraintOperator());
161         assertThat(sourceType).isEqualToIgnoringCase(uiConstraint.getSourceType());
162         assertThat(sourceName).isEqualToIgnoringCase(uiConstraint.getSourceName());
163         assertThat(propertyValue).isEqualToIgnoringCase(uiConstraint.getValue().toString());
164
165         when(componentsUtils.parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class)))
166             .thenReturn(Optional.of(uiConstraint));
167
168         assertNotNull(constraint);
169         assertNotNull(ciNodeFilterDataDefinition);
170         assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
171         assertThat("resourceType: {equal: resourceTypeValue}\n").isEqualToIgnoringCase(constraint);
172         when(componentNodeFilterBusinessLogic
173             .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
174                 uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
175                 NodeFilterConstraintType.PROPERTIES))
176             .thenReturn(Optional.of(ciNodeFilterDataDefinition));
177
178         final Response response = target()
179             .path(path)
180             .request(MediaType.APPLICATION_JSON)
181             .header(USER_ID_HEADER, USER_ID)
182             .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
183
184         verify(componentNodeFilterBusinessLogic, times(1))
185             .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(),
186                 anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
187                 ArgumentMatchers.any(NodeFilterConstraintType.class));
188
189         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
190     }
191
192     @Test
193     public void addNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
194         initComponentData();
195         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
196         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
197             NodeFilterConstraintType.CAPABILITIES_PARAM_NAME);
198
199         when(userValidations.validateUserExists(user)).thenReturn(user);
200         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
201         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
202         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
203         when(componentsUtils.parseToConstraint(anyString(), any(User.class),ArgumentMatchers.any(ComponentTypeEnum.class)))
204             .thenReturn(Optional.of(uiConstraint));
205
206         assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
207         when(componentNodeFilterBusinessLogic
208             .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
209                 uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
210                 NodeFilterConstraintType.CAPABILITIES))
211             .thenReturn(Optional.of(ciNodeFilterDataDefinition));
212
213         final Response response = target()
214             .path(path)
215             .request(MediaType.APPLICATION_JSON)
216             .header(USER_ID_HEADER, USER_ID)
217             .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
218
219         verify(componentNodeFilterBusinessLogic, times(1))
220             .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(),
221                 anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
222                 ArgumentMatchers.any(NodeFilterConstraintType.class));
223
224         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
225     }
226
227     @Test
228     public void addNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
229         initComponentData();
230         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
231         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
232             NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
233
234         when(userValidations.validateUserExists(user)).thenReturn(user);
235         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
236         when(responseFormat.getStatus()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR_500);
237         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
238
239         when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
240             ArgumentMatchers.<Class<UIConstraint>>any(),
241             nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class))).thenReturn(Either.left(uiConstraint));
242
243         when(componentNodeFilterBusinessLogic
244             .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
245                 uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
246                 NodeFilterConstraintType.PROPERTIES))
247             .thenReturn(Optional.empty());
248
249         final Response response = target()
250             .path(path)
251             .request(MediaType.APPLICATION_JSON)
252             .header(USER_ID_HEADER, USER_ID)
253             .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
254
255         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
256     }
257
258     @Test
259     public void addNodeFilterFailConstraintParseTest() throws JsonProcessingException {
260         initComponentData();
261         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
262         final String path = String.format(pathFormat, componentType, componentId, componentInstance, NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
263
264         when(userValidations.validateUserExists(user)).thenReturn(user);
265         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
266
267         when(responseFormat.getStatus()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR_500);
268         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
269
270         when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
271             ArgumentMatchers.<Class<UIConstraint>>any(),
272             nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class)))
273             .thenReturn(Either.right(new ResponseFormat(HttpStatus.INTERNAL_SERVER_ERROR_500)));
274
275         final Response response = target()
276             .path(path)
277             .request(MediaType.APPLICATION_JSON)
278             .header(USER_ID_HEADER, USER_ID)
279             .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
280
281         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
282     }
283
284     @Test
285     public void addNodeFilterFailConvertTest() throws JsonProcessingException, BusinessLogicException {
286         initComponentData();
287         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
288         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
289             NodeFilterConstraintType.PROPERTIES.getType());
290
291         when(userValidations.validateUserExists(user)).thenReturn(user);
292         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
293
294         when(responseFormat.getStatus()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR_500);
295         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
296
297         when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
298             ArgumentMatchers.<Class<UIConstraint>>any(),
299             nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class)))
300             .thenReturn(Either.left(null));
301
302         final Response response = target()
303             .path(path)
304             .request(MediaType.APPLICATION_JSON)
305             .header(USER_ID_HEADER, USER_ID)
306             .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
307
308         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
309     }
310
311     @Test
312     public void updateNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException {
313         initComponentData();
314         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
315         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
316             NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
317
318         when(userValidations.validateUserExists(user)).thenReturn(user);
319         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
320
321         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
322         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
323
324         when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
325             ArgumentMatchers.<Class<List>>any(),
326             nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class)))
327             .thenReturn(Either.left(Arrays.asList(new ObjectMapper().convertValue(uiConstraint, Map.class))));
328
329         when(componentNodeFilterBusinessLogic
330             .updateNodeFilter(componentId, componentInstance, Collections.singletonList(constraint),
331                 true, ComponentTypeEnum.RESOURCE)).thenReturn(Optional.of(ciNodeFilterDataDefinition));
332         final Response response = target()
333             .path(path)
334             .request(MediaType.APPLICATION_JSON)
335             .header(USER_ID_HEADER, USER_ID)
336             .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
337
338         verify(componentNodeFilterBusinessLogic, times(1))
339             .updateNodeFilter(anyString(), anyString(), anyList(), anyBoolean(),
340                 ArgumentMatchers.any(ComponentTypeEnum.class));
341
342         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
343     }
344
345     @Test
346     public void updateNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
347         initComponentData();
348         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
349         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
350             NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
351
352         when(userValidations.validateUserExists(user)).thenReturn(user);
353         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
354
355         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
356
357         when(componentsUtils.validateAndParseConstraint(ArgumentMatchers.any(ComponentTypeEnum.class), anyString(), any(User.class)))
358             .thenReturn(Collections.singletonList(uiConstraint));
359
360         when(componentNodeFilterBusinessLogic
361             .updateNodeFilter(componentId, componentInstance, Collections.singletonList(constraint),
362                 true, ComponentTypeEnum.RESOURCE))
363             .thenReturn(Optional.empty());
364         final Response response = target()
365             .path(path)
366             .request(MediaType.APPLICATION_JSON)
367             .header(USER_ID_HEADER, USER_ID)
368             .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
369
370         verify(componentNodeFilterBusinessLogic, times(1))
371             .updateNodeFilter(anyString(), anyString(), anyList(), anyBoolean(),
372                 ArgumentMatchers.any(ComponentTypeEnum.class));
373
374
375         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
376     }
377
378     @Test
379     public void updateNodeFilterFailConstraintParseTest() throws JsonProcessingException {
380         initComponentData();
381         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
382         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
383             NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
384
385         when(userValidations.validateUserExists(user)).thenReturn(user);
386         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
387         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
388
389         when(componentsUtils.validateAndParseConstraint(ArgumentMatchers.any(ComponentTypeEnum.class), anyString(), any(User.class)))
390             .thenReturn(Collections.emptyList());
391
392         final Response response = target()
393             .path(path)
394             .request(MediaType.APPLICATION_JSON)
395             .header(USER_ID_HEADER, USER_ID)
396             .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
397
398         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
399     }
400
401     @Test
402     public void updateNodeFilterFailConvertTest() throws JsonProcessingException {
403         initComponentData();
404         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s";
405         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
406             NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
407
408         when(userValidations.validateUserExists(user)).thenReturn(user);
409         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
410         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
411
412         when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
413             ArgumentMatchers.<Class<List>>any(),
414             nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class)))
415             .thenReturn(Either.left(null));
416
417         final Response response = target()
418             .path(path)
419             .request(MediaType.APPLICATION_JSON)
420             .header(USER_ID_HEADER, USER_ID)
421             .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
422
423         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
424     }
425
426     @Test
427     public void deleteNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException {
428         initComponentData();
429         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s/%s";
430         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
431             NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
432
433         when(userValidations.validateUserExists(user)).thenReturn(user);
434         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
435
436         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
437         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
438
439         when(componentNodeFilterBusinessLogic.deleteNodeFilter(componentId, componentInstance,
440             NodeFilterConstraintAction.DELETE, null, 0, true, ComponentTypeEnum.RESOURCE,
441             NodeFilterConstraintType.PROPERTIES))
442             .thenReturn(Optional.of(ciNodeFilterDataDefinition));
443
444         final Response response = target()
445             .path(path)
446             .request(MediaType.APPLICATION_JSON)
447             .accept(MediaType.APPLICATION_JSON)
448             .header(USER_ID_HEADER, USER_ID)
449             .delete(Response.class);
450
451         verify(componentNodeFilterBusinessLogic, times(1))
452             .deleteNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class),
453                 nullable(String.class), anyInt(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
454                 ArgumentMatchers.any(NodeFilterConstraintType.class));
455
456         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
457     }
458
459     @Test
460     public void deleteNodeFilterFailTest() {
461         final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s/%s";
462         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
463             NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 1);
464         final Response response = target()
465             .path(path)
466             .request(MediaType.APPLICATION_JSON)
467             .accept(MediaType.APPLICATION_JSON)
468             .header(USER_ID_HEADER, USER_ID)
469             .delete(Response.class);
470
471         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
472     }
473
474     private static void createMocks() {
475         request = mock(HttpServletRequest.class);
476         userBusinessLogic = mock(UserBusinessLogic.class);
477         componentInstanceBusinessLogic = mock(ComponentInstanceBusinessLogic.class);
478         componentsUtils = mock(ComponentsUtils.class);
479         servletUtils = mock(ServletUtils.class);
480         resourceImportManager = mock(ResourceImportManager.class);
481         componentNodeFilterBusinessLogic = mock(ComponentNodeFilterBusinessLogic.class);
482
483         session = mock(HttpSession.class);
484         servletContext = mock(ServletContext.class);
485         webAppContextWrapper = mock(WebAppContextWrapper.class);
486         webApplicationContext = mock(WebApplicationContext.class);
487         responseFormat = mock(ResponseFormat.class);
488         userValidations = mock(UserValidations.class);
489     }
490
491     @Override
492     protected ResourceConfig configure() {
493         forceSet(TestProperties.CONTAINER_PORT, "0");
494         final ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
495         return new ResourceConfig(ComponentNodeFilterServlet.class)
496             .register(new AbstractBinder() {
497                 @Override
498                 protected void configure() {
499                     bind(request).to(HttpServletRequest.class);
500                     bind(userBusinessLogic).to(UserBusinessLogic.class);
501                     bind(componentInstanceBusinessLogic).to(ComponentInstanceBusinessLogic.class);
502                     bind(componentsUtils).to(ComponentsUtils.class);
503                     bind(servletUtils).to(ServletUtils.class);
504                     bind(resourceImportManager).to(ResourceImportManager.class);
505                     bind(componentNodeFilterBusinessLogic).to(ComponentNodeFilterBusinessLogic.class);
506                 }
507             })
508             .property("contextConfig", context);
509     }
510
511     private void initComponentData() throws JsonProcessingException {
512         uiConstraint = new UIConstraint("resourceType", "equal", "static", "static", "resourceTypeValue");
513         constraint = new ConstraintConvertor().convert(uiConstraint);
514         inputJson = buildConstraintDataJson(uiConstraint);
515
516         requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
517         requirementNodeFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
518         requirementNodeFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
519
520         final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
521             new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterPropertyDataDefinition)));
522
523         ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
524         ciNodeFilterDataDefinition.setProperties(listDataDefinition);
525         ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
526
527         user = new User();
528         user.setUserId(USER_ID);
529         user.setRole(Role.ADMIN.name());
530     }
531
532     private String buildConstraintDataJson(final UIConstraint uiConstraint) throws JsonProcessingException {
533         final ObjectMapper mapper = new ObjectMapper();
534         return mapper.writeValueAsString(uiConstraint);
535     }
536
537 }