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
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.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.openecomp.sdc.be.servlets;
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;
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;
94 @ExtendWith(MockitoExtension.class)
95 @TestInstance(Lifecycle.PER_CLASS)
96 class ComponentNodeFilterServletTest extends JerseyTest {
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);
116 private HttpServletRequest request;
118 private HttpSession session;
120 private ServletContext servletContext;
122 private WebAppContextWrapper webAppContextWrapper;
124 private WebApplicationContext webApplicationContext;
126 private UserBusinessLogic userBusinessLogic;
128 private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
130 private ComponentsUtils componentsUtils;
132 private ServletUtils servletUtils;
134 private ResourceImportManager resourceImportManager;
136 private ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
138 private ResponseFormat responseFormat;
140 private UserValidations userValidations;
142 private CINodeFilterDataDefinition ciNodeFilterDataDefinition;
144 public ComponentNodeFilterServletTest() throws JsonProcessingException {
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");
168 public void resetMock() throws Exception {
173 void after() throws Exception {
178 void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException {
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);
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());
195 doReturn(Optional.of(uiConstraint)).when(componentsUtils)
196 .parseToConstraint(anyString(), any(User.class), any(ComponentTypeEnum.class));
198 assertNotNull(constraint);
199 assertNotNull(ciNodeFilterDataDefinition);
200 assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
201 assertThat("resourceType: {equal: resourceTypeValue}\n").isEqualToIgnoringCase(constraint);
203 doReturn(Optional.of(ciNodeFilterDataDefinition)).when(componentNodeFilterBusinessLogic)
204 .addNodeFilter(componentId, componentInstance, filterConstraintDto, true, ComponentTypeEnum.RESOURCE,
205 NodeFilterConstraintType.PROPERTIES, "");
207 final Response response = target()
209 .request(MediaType.APPLICATION_JSON)
210 .header(USER_ID_HEADER, USER_ID)
211 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
213 verify(componentNodeFilterBusinessLogic, times(1))
214 .addNodeFilter(anyString(), anyString(), any(FilterConstraintDto.class), anyBoolean(), any(ComponentTypeEnum.class),
215 any(NodeFilterConstraintType.class), anyString()
218 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
219 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
223 void addNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
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));
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()
245 .request(MediaType.APPLICATION_JSON)
246 .header(USER_ID_HEADER, USER_ID)
247 .post(Entity.entity(requestPayload, MediaType.APPLICATION_JSON));
249 verify(componentNodeFilterBusinessLogic, times(1))
250 .addNodeFilter(componentId, componentInstance, filterConstraintDto1, true, ComponentTypeEnum.RESOURCE,
251 NodeFilterConstraintType.CAPABILITIES, capabilityName);
253 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
254 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
258 void addNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
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);
264 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
266 final Response response = target()
268 .request(MediaType.APPLICATION_JSON)
269 .header(USER_ID_HEADER, USER_ID)
270 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
272 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
273 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
277 void addNodeFilterFailConstraintParseTest() throws JsonProcessingException {
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);
282 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
284 final Response response = target()
286 .request(MediaType.APPLICATION_JSON)
287 .header(USER_ID_HEADER, USER_ID)
288 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
290 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
291 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
295 void addNodeFilterFailConvertTest() throws JsonProcessingException {
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());
301 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
303 final Response response = target()
305 .request(MediaType.APPLICATION_JSON)
306 .header(USER_ID_HEADER, USER_ID)
307 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
309 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
310 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
314 void updateNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
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);
320 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
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()
332 .request(MediaType.APPLICATION_JSON)
333 .header(USER_ID_HEADER, USER_ID)
334 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
336 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
337 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
341 void updateNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
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);
347 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
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);
355 when(componentNodeFilterBusinessLogic
356 .updateNodeFilter(componentId, componentInstance, uiConstraint,
357 ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.CAPABILITIES, 0))
358 .thenReturn(Optional.of(ciNodeFilterDataDefinition));
360 final Response response = target()
362 .request(MediaType.APPLICATION_JSON)
363 .header(USER_ID_HEADER, USER_ID)
364 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
366 verify(componentNodeFilterBusinessLogic, times(1))
367 .updateNodeFilter(anyString(), anyString(), any(UIConstraint.class),
368 any(ComponentTypeEnum.class), any(NodeFilterConstraintType.class),
371 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
372 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
376 void updateNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
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);
382 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
384 final Response response = target()
386 .request(MediaType.APPLICATION_JSON)
387 .header(USER_ID_HEADER, USER_ID)
388 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
390 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
391 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
395 void updateNodeFilterFailConstraintParseTest() throws JsonProcessingException {
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);
401 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
403 final Response response = target()
405 .request(MediaType.APPLICATION_JSON)
406 .header(USER_ID_HEADER, USER_ID)
407 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
409 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
410 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
414 void updateNodeFilterFailConvertTest() throws JsonProcessingException {
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);
420 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
422 final Response response = target()
424 .request(MediaType.APPLICATION_JSON)
425 .header(USER_ID_HEADER, USER_ID)
426 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
428 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
429 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
433 void deleteNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException {
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);
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);
444 when(componentNodeFilterBusinessLogic
445 .deleteNodeFilter(componentId, componentInstance, 0, true, ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.PROPERTIES))
446 .thenReturn(Optional.of(ciNodeFilterDataDefinition));
448 final Response response = target()
450 .request(MediaType.APPLICATION_JSON)
451 .accept(MediaType.APPLICATION_JSON)
452 .header(USER_ID_HEADER, USER_ID)
453 .delete(Response.class);
455 verify(componentNodeFilterBusinessLogic, times(1))
456 .deleteNodeFilter(anyString(), anyString(), anyInt(), anyBoolean(), any(ComponentTypeEnum.class), any(NodeFilterConstraintType.class));
458 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
459 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
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()
469 .request(MediaType.APPLICATION_JSON)
470 .accept(MediaType.APPLICATION_JSON)
471 .header(USER_ID_HEADER, USER_ID)
472 .delete(Response.class);
474 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
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() {
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);
494 .property("contextConfig", context);
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))));
503 final ListDataDefinition<PropertyFilterDataDefinition> propertyDataDefinitionList =
504 new ListDataDefinition<>(new LinkedList<>(List.of(propertyFilterDataDefinition)));
506 final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition =
507 new RequirementNodeFilterCapabilityDataDefinition();
508 requirementNodeFilterCapabilityDataDefinition.setName(uiConstraint.getServicePropertyName());
509 requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionList);
511 final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilityDataDefinitionList =
512 new ListDataDefinition<>(new LinkedList<>(List.of(requirementNodeFilterCapabilityDataDefinition)));
514 ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
515 ciNodeFilterDataDefinition.setProperties(propertyDataDefinitionList);
516 ciNodeFilterDataDefinition.setCapabilities(capabilityDataDefinitionList);
517 ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
521 private String buildConstraintDataJson(final UIConstraint uiConstraint) throws JsonProcessingException {
522 final ObjectMapper mapper = new ObjectMapper();
523 return mapper.writeValueAsString(uiConstraint);