Support TOSCA functions in Node Filters
[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.jupiter.api.Assertions.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.anyString;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.Mockito.doReturn;
30 import static org.mockito.Mockito.times;
31 import static org.mockito.Mockito.verify;
32 import static org.mockito.Mockito.when;
33 import static org.openecomp.sdc.common.api.Constants.USER_ID_HEADER;
34
35 import com.fasterxml.jackson.core.JsonProcessingException;
36 import com.fasterxml.jackson.databind.ObjectMapper;
37 import java.util.LinkedList;
38 import java.util.List;
39 import java.util.Optional;
40 import javax.servlet.ServletContext;
41 import javax.servlet.http.HttpServletRequest;
42 import javax.servlet.http.HttpSession;
43 import javax.ws.rs.client.Entity;
44 import javax.ws.rs.core.MediaType;
45 import javax.ws.rs.core.Response;
46 import org.eclipse.jetty.http.HttpStatus;
47 import org.glassfish.hk2.utilities.binding.AbstractBinder;
48 import org.glassfish.jersey.server.ResourceConfig;
49 import org.glassfish.jersey.test.JerseyTest;
50 import org.glassfish.jersey.test.TestProperties;
51 import org.junit.jupiter.api.AfterEach;
52 import org.junit.jupiter.api.BeforeAll;
53 import org.junit.jupiter.api.BeforeEach;
54 import org.junit.jupiter.api.Test;
55 import org.junit.jupiter.api.TestInstance;
56 import org.junit.jupiter.api.TestInstance.Lifecycle;
57 import org.junit.jupiter.api.extension.ExtendWith;
58 import org.mockito.Mock;
59 import org.mockito.MockitoAnnotations;
60 import org.mockito.junit.jupiter.MockitoExtension;
61 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
62 import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic;
63 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
64 import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
65 import org.openecomp.sdc.be.components.validation.UserValidations;
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.datamodel.utils.ConstraintConvertor;
70 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
71 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
72 import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition;
73 import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
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.model.dto.FilterConstraintDto;
81 import org.openecomp.sdc.be.ui.mapper.FilterConstraintMapper;
82 import org.openecomp.sdc.be.ui.model.UIConstraint;
83 import org.openecomp.sdc.be.user.Role;
84 import org.openecomp.sdc.be.user.UserBusinessLogic;
85 import org.openecomp.sdc.common.api.ConfigurationSource;
86 import org.openecomp.sdc.common.api.Constants;
87 import org.openecomp.sdc.common.impl.ExternalConfiguration;
88 import org.openecomp.sdc.common.impl.FSConfigurationSource;
89 import org.openecomp.sdc.exception.ResponseFormat;
90 import org.springframework.context.ApplicationContext;
91 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
92 import org.springframework.web.context.WebApplicationContext;
93
94 @ExtendWith(MockitoExtension.class)
95 @TestInstance(Lifecycle.PER_CLASS)
96 class ComponentNodeFilterServletTest extends JerseyTest {
97
98     private static final String USER_ID = "jh0003";
99     private static final String servicePropertyName = "resourceType";
100     private static final String constraintOperator = "equal";
101     private static final String sourceType = "static";
102     private static final String sourceName = sourceType;
103     private static final String propertyValue = "resourceTypeValue";
104     private static final String componentId = "dac65869-dfb4-40d2-aa20-084324659ec1";
105     private static final String componentInstance = "dac65869-dfb4-40d2-aa20-084324659ec1.resource0";
106     private static final String componentType = "resources";
107     private static final String capabilityName = "MyCapabilityName";
108     private static final String V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER = "/v1/catalog/%s/%s/componentInstance/%s/%s/%s/nodeFilter";
109     private static final String V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER = "/v1/catalog/%s/%s/componentInstance/%s/%s/nodeFilter";
110     private final UIConstraint uiConstraint = new UIConstraint("resourceType", "equal", "static", "static", "resourceTypeValue");
111     private final String constraint = new ConstraintConvertor().convert(uiConstraint);
112     private final FilterConstraintDto filterConstraintDto = new FilterConstraintMapper().mapFrom(uiConstraint);
113     private final String inputJson = buildConstraintDataJson(uiConstraint);
114     private final User user = new User("", "", USER_ID, "", Role.ADMIN.name(), null);
115     @Mock
116     private HttpServletRequest request;
117     @Mock
118     private HttpSession session;
119     @Mock
120     private ServletContext servletContext;
121     @Mock
122     private WebAppContextWrapper webAppContextWrapper;
123     @Mock
124     private WebApplicationContext webApplicationContext;
125     @Mock
126     private UserBusinessLogic userBusinessLogic;
127     @Mock
128     private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
129     @Mock
130     private ComponentsUtils componentsUtils;
131     @Mock
132     private ServletUtils servletUtils;
133     @Mock
134     private ResourceImportManager resourceImportManager;
135     @Mock
136     private ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
137     @Mock
138     private ResponseFormat responseFormat;
139     @Mock
140     private UserValidations userValidations;
141
142     private CINodeFilterDataDefinition ciNodeFilterDataDefinition;
143
144     public ComponentNodeFilterServletTest() throws JsonProcessingException {
145     }
146
147     @BeforeAll
148     public void initClass() {
149         MockitoAnnotations.openMocks(this);
150         when(request.getSession()).thenReturn(session);
151         when(session.getServletContext()).thenReturn(servletContext);
152         when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
153         when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
154         when(webApplicationContext.getBean(ComponentNodeFilterBusinessLogic.class)).thenReturn(componentNodeFilterBusinessLogic);
155         when(request.getHeader("USER_ID")).thenReturn(USER_ID);
156         when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
157         when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
158         final String appConfigDir = "src/test/resources/config/catalog-be";
159         final ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
160         final ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
161         final org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
162         configuration.setJanusGraphInMemoryGraph(true);
163         configurationManager.setConfiguration(configuration);
164         ExternalConfiguration.setAppName("catalog-be");
165     }
166
167     @BeforeEach
168     public void resetMock() throws Exception {
169         super.setUp();
170     }
171
172     @AfterEach
173     void after() throws Exception {
174         super.tearDown();
175     }
176
177     @Test
178     void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException {
179         initComponentData();
180         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
181         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
182             NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
183
184         doReturn(user).when(componentNodeFilterBusinessLogic).validateUser(USER_ID);
185         doReturn(HttpStatus.OK_200).when(responseFormat).getStatus();
186         doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.OK);
187         doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
188         assertNotNull(uiConstraint);
189         assertThat(servicePropertyName).isEqualToIgnoringCase(uiConstraint.getServicePropertyName());
190         assertThat(constraintOperator).isEqualToIgnoringCase(uiConstraint.getConstraintOperator());
191         assertThat(sourceType).isEqualToIgnoringCase(uiConstraint.getSourceType());
192         assertThat(sourceName).isEqualToIgnoringCase(uiConstraint.getSourceName());
193         assertThat(propertyValue).isEqualToIgnoringCase(uiConstraint.getValue().toString());
194
195         doReturn(Optional.of(uiConstraint)).when(componentsUtils)
196             .parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class));
197
198         assertNotNull(constraint);
199         assertNotNull(ciNodeFilterDataDefinition);
200         assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
201         assertThat("resourceType: {equal: resourceTypeValue}\n").isEqualToIgnoringCase(constraint);
202
203         doReturn(Optional.of(ciNodeFilterDataDefinition)).when(componentNodeFilterBusinessLogic)
204             .addNodeFilter(componentId, componentInstance, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
205                 NodeFilterConstraintType.PROPERTIES, "");
206
207         final Response response = target()
208             .path(path)
209             .request(MediaType.APPLICATION_JSON)
210             .header(USER_ID_HEADER, USER_ID)
211             .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
212
213         verify(componentNodeFilterBusinessLogic, times(1))
214             .addNodeFilter(anyString(), anyString(), any(FilterConstraintDto.class), anyBoolean(), any(ComponentTypeEnum.class),
215                 any(NodeFilterConstraintType.class), anyString()
216             );
217
218         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
219         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
220     }
221
222     @Test
223     void addNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
224         initComponentData();
225         final String path = String.format(V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER, componentType, componentId, componentInstance,
226             NodeFilterConstraintType.CAPABILITIES_PARAM_NAME);
227         final UIConstraint uiConstraint1 = new UIConstraint(uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator(),
228             uiConstraint.getSourceType(), uiConstraint.getSourceName(), uiConstraint.getValue());
229         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
230         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
231         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
232         doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
233         uiConstraint1.setCapabilityName(capabilityName);
234         final String requestPayload = buildConstraintDataJson(uiConstraint1);
235         when(componentsUtils.parseToConstraint(requestPayload, user, ComponentTypeEnum.RESOURCE)).thenReturn(Optional.of(uiConstraint1));
236
237         assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
238         final FilterConstraintDto filterConstraintDto1 = new FilterConstraintMapper().mapFrom(uiConstraint1);
239         when(componentNodeFilterBusinessLogic
240             .addNodeFilter(componentId, componentInstance, filterConstraintDto1, true, ComponentTypeEnum.RESOURCE,
241                 NodeFilterConstraintType.CAPABILITIES, capabilityName)
242         ).thenReturn(Optional.of(ciNodeFilterDataDefinition));
243         final Response response = target()
244             .path(path)
245             .request(MediaType.APPLICATION_JSON)
246             .header(USER_ID_HEADER, USER_ID)
247             .post(Entity.entity(requestPayload, MediaType.APPLICATION_JSON));
248
249         verify(componentNodeFilterBusinessLogic, times(1))
250             .addNodeFilter(componentId, componentInstance, filterConstraintDto1, true, ComponentTypeEnum.RESOURCE,
251                 NodeFilterConstraintType.CAPABILITIES, capabilityName);
252
253         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
254         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
255     }
256
257     @Test
258     void addNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
259         initComponentData();
260         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
261         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
262             NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
263
264         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
265
266         final Response response = target()
267             .path(path)
268             .request(MediaType.APPLICATION_JSON)
269             .header(USER_ID_HEADER, USER_ID)
270             .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
271
272         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
273         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
274     }
275
276     @Test
277     void addNodeFilterFailConstraintParseTest() throws JsonProcessingException {
278         initComponentData();
279         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
280         final String path = String.format(pathFormat, componentType, componentId, componentInstance, NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
281
282         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
283
284         final Response response = target()
285             .path(path)
286             .request(MediaType.APPLICATION_JSON)
287             .header(USER_ID_HEADER, USER_ID)
288             .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
289
290         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
291         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
292     }
293
294     @Test
295     void addNodeFilterFailConvertTest() throws JsonProcessingException {
296         initComponentData();
297         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
298         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
299             NodeFilterConstraintType.PROPERTIES.getType());
300
301         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
302
303         final Response response = target()
304             .path(path)
305             .request(MediaType.APPLICATION_JSON)
306             .header(USER_ID_HEADER, USER_ID)
307             .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
308
309         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
310         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
311     }
312
313     @Test
314     void updateNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
315         initComponentData();
316         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
317         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
318             NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
319
320         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
321
322         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
323         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
324         doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
325         doReturn(Optional.of(uiConstraint)).when(componentsUtils)
326             .parseToConstraint(anyString(), any(User.class), eq(ComponentTypeEnum.RESOURCE));
327         when(componentNodeFilterBusinessLogic
328             .updateNodeFilter(componentId, componentInstance, uiConstraint, ComponentTypeEnum.RESOURCE,
329                 NodeFilterConstraintType.PROPERTIES, 0)).thenReturn(Optional.of(ciNodeFilterDataDefinition));
330         final Response response = target()
331             .path(path)
332             .request(MediaType.APPLICATION_JSON)
333             .header(USER_ID_HEADER, USER_ID)
334             .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
335
336         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
337         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
338     }
339
340     @Test
341     void updateNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
342         initComponentData();
343         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
344         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
345             NodeFilterConstraintType.CAPABILITIES_PARAM_NAME, 0);
346
347         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
348
349         when(componentsUtils.parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class)))
350             .thenReturn(Optional.of(uiConstraint));
351         doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
352         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
353         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
354
355         when(componentNodeFilterBusinessLogic
356             .updateNodeFilter(componentId, componentInstance, uiConstraint,
357                 ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.CAPABILITIES, 0))
358             .thenReturn(Optional.of(ciNodeFilterDataDefinition));
359
360         final Response response = target()
361             .path(path)
362             .request(MediaType.APPLICATION_JSON)
363             .header(USER_ID_HEADER, USER_ID)
364             .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
365
366         verify(componentNodeFilterBusinessLogic, times(1))
367             .updateNodeFilter(anyString(), anyString(), any(UIConstraint.class),
368                 any(ComponentTypeEnum.class), any(NodeFilterConstraintType.class),
369                 anyInt());
370
371         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
372         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
373     }
374
375     @Test
376     void updateNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
377         initComponentData();
378         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
379         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
380             NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
381
382         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
383
384         final Response response = target()
385             .path(path)
386             .request(MediaType.APPLICATION_JSON)
387             .header(USER_ID_HEADER, USER_ID)
388             .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
389
390         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
391         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
392     }
393
394     @Test
395     void updateNodeFilterFailConstraintParseTest() throws JsonProcessingException {
396         initComponentData();
397         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
398         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
399             NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
400
401         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
402
403         final Response response = target()
404             .path(path)
405             .request(MediaType.APPLICATION_JSON)
406             .header(USER_ID_HEADER, USER_ID)
407             .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
408
409         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
410         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
411     }
412
413     @Test
414     void updateNodeFilterFailConvertTest() throws JsonProcessingException {
415         initComponentData();
416         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
417         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
418             NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
419
420         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
421
422         final Response response = target()
423             .path(path)
424             .request(MediaType.APPLICATION_JSON)
425             .header(USER_ID_HEADER, USER_ID)
426             .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
427
428         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
429         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
430     }
431
432     @Test
433     void deleteNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException {
434         initComponentData();
435         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
436         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
437             NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
438
439         when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
440         doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
441         when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
442         when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
443
444         when(componentNodeFilterBusinessLogic
445             .deleteNodeFilter(componentId, componentInstance, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES))
446             .thenReturn(Optional.of(ciNodeFilterDataDefinition));
447
448         final Response response = target()
449             .path(path)
450             .request(MediaType.APPLICATION_JSON)
451             .accept(MediaType.APPLICATION_JSON)
452             .header(USER_ID_HEADER, USER_ID)
453             .delete(Response.class);
454
455         verify(componentNodeFilterBusinessLogic, times(1))
456             .deleteNodeFilter(anyString(), anyString(), anyInt(), anyBoolean(), any(ComponentTypeEnum.class), any(NodeFilterConstraintType.class));
457
458         assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
459         verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
460     }
461
462     @Test
463     void deleteNodeFilterFailTest() {
464         final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
465         final String path = String.format(pathFormat, componentType, componentId, componentInstance,
466             NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
467         final Response response = target()
468             .path(path)
469             .request(MediaType.APPLICATION_JSON)
470             .accept(MediaType.APPLICATION_JSON)
471             .header(USER_ID_HEADER, USER_ID)
472             .delete(Response.class);
473
474         assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
475     }
476
477     @Override
478     protected ResourceConfig configure() {
479         forceSet(TestProperties.CONTAINER_PORT, "0");
480         final ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
481         return new ResourceConfig(ComponentNodeFilterServlet.class)
482             .register(new AbstractBinder() {
483                 @Override
484                 protected void configure() {
485                     bind(request).to(HttpServletRequest.class);
486                     bind(userBusinessLogic).to(UserBusinessLogic.class);
487                     bind(componentInstanceBusinessLogic).to(ComponentInstanceBusinessLogic.class);
488                     bind(componentsUtils).to(ComponentsUtils.class);
489                     bind(servletUtils).to(ServletUtils.class);
490                     bind(resourceImportManager).to(ResourceImportManager.class);
491                     bind(componentNodeFilterBusinessLogic).to(ComponentNodeFilterBusinessLogic.class);
492                 }
493             })
494             .property("contextConfig", context);
495     }
496
497     private void initComponentData() {
498         final PropertyFilterDataDefinition propertyFilterDataDefinition =
499             new PropertyFilterDataDefinition();
500         propertyFilterDataDefinition.setName(uiConstraint.getServicePropertyName());
501         propertyFilterDataDefinition.setConstraints(new LinkedList<>(List.of(new FilterConstraintMapper().mapTo(filterConstraintDto))));
502
503         final ListDataDefinition<PropertyFilterDataDefinition> propertyDataDefinitionList =
504             new ListDataDefinition<>(new LinkedList<>(List.of(propertyFilterDataDefinition)));
505
506         final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition =
507             new RequirementNodeFilterCapabilityDataDefinition();
508         requirementNodeFilterCapabilityDataDefinition.setName(uiConstraint.getServicePropertyName());
509         requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionList);
510
511         final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilityDataDefinitionList =
512             new ListDataDefinition<>(new LinkedList<>(List.of(requirementNodeFilterCapabilityDataDefinition)));
513
514         ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
515         ciNodeFilterDataDefinition.setProperties(propertyDataDefinitionList);
516         ciNodeFilterDataDefinition.setCapabilities(capabilityDataDefinitionList);
517         ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
518
519     }
520
521     private String buildConstraintDataJson(final UIConstraint uiConstraint) throws JsonProcessingException {
522         final ObjectMapper mapper = new ObjectMapper();
523         return mapper.writeValueAsString(uiConstraint);
524     }
525
526 }