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.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.anyString;
28 import static org.mockito.ArgumentMatchers.eq;
29 import static org.mockito.ArgumentMatchers.nullable;
30 import static org.mockito.Mockito.doReturn;
31 import static org.mockito.Mockito.times;
32 import static org.mockito.Mockito.verify;
33 import static org.mockito.Mockito.when;
34 import static org.openecomp.sdc.common.api.Constants.USER_ID_HEADER;
36 import com.fasterxml.jackson.core.JsonProcessingException;
37 import com.fasterxml.jackson.databind.ObjectMapper;
38 import java.util.Arrays;
39 import java.util.LinkedList;
40 import java.util.Optional;
41 import javax.servlet.ServletContext;
42 import javax.servlet.http.HttpServletRequest;
43 import javax.servlet.http.HttpSession;
44 import javax.ws.rs.client.Entity;
45 import javax.ws.rs.core.MediaType;
46 import javax.ws.rs.core.Response;
47 import org.eclipse.jetty.http.HttpStatus;
48 import org.glassfish.hk2.utilities.binding.AbstractBinder;
49 import org.glassfish.jersey.server.ResourceConfig;
50 import org.glassfish.jersey.test.JerseyTest;
51 import org.glassfish.jersey.test.TestProperties;
52 import org.junit.jupiter.api.AfterAll;
53 import org.junit.jupiter.api.AfterEach;
54 import org.junit.jupiter.api.BeforeAll;
55 import org.junit.jupiter.api.BeforeEach;
56 import org.junit.jupiter.api.Test;
57 import org.junit.jupiter.api.TestInstance;
58 import org.junit.jupiter.api.TestInstance.Lifecycle;
59 import org.junit.jupiter.api.extension.ExtendWith;
60 import org.mockito.ArgumentMatchers;
61 import org.mockito.Mock;
62 import org.mockito.MockitoAnnotations;
63 import org.mockito.junit.jupiter.MockitoExtension;
64 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
65 import org.openecomp.sdc.be.components.impl.ComponentNodeFilterBusinessLogic;
66 import org.openecomp.sdc.be.components.impl.ResourceImportManager;
67 import org.openecomp.sdc.be.components.impl.exceptions.BusinessLogicException;
68 import org.openecomp.sdc.be.components.impl.utils.NodeFilterConstraintAction;
69 import org.openecomp.sdc.be.components.validation.UserValidations;
70 import org.openecomp.sdc.be.config.ConfigurationManager;
71 import org.openecomp.sdc.be.config.SpringConfig;
72 import org.openecomp.sdc.be.dao.api.ActionStatus;
73 import org.openecomp.sdc.be.datamodel.utils.ConstraintConvertor;
74 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
75 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
76 import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterCapabilityDataDefinition;
77 import org.openecomp.sdc.be.datatypes.elements.RequirementNodeFilterPropertyDataDefinition;
78 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
79 import org.openecomp.sdc.be.datatypes.enums.NodeFilterConstraintType;
80 import org.openecomp.sdc.be.impl.ComponentsUtils;
81 import org.openecomp.sdc.be.impl.ServletUtils;
82 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
83 import org.openecomp.sdc.be.model.User;
84 import org.openecomp.sdc.be.ui.model.UIConstraint;
85 import org.openecomp.sdc.be.user.Role;
86 import org.openecomp.sdc.be.user.UserBusinessLogic;
87 import org.openecomp.sdc.common.api.ConfigurationSource;
88 import org.openecomp.sdc.common.api.Constants;
89 import org.openecomp.sdc.common.impl.ExternalConfiguration;
90 import org.openecomp.sdc.common.impl.FSConfigurationSource;
91 import org.openecomp.sdc.exception.ResponseFormat;
92 import org.springframework.context.ApplicationContext;
93 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
94 import org.springframework.web.context.WebApplicationContext;
96 @ExtendWith(MockitoExtension.class)
97 @TestInstance(Lifecycle.PER_CLASS)
98 class ComponentNodeFilterServletTest extends JerseyTest {
100 private static final String USER_ID = "jh0003";
101 private static final String servicePropertyName = "resourceType";
102 private static final String constraintOperator = "equal";
103 private static final String sourceType = "static";
104 private static final String sourceName = sourceType;
105 private static final String propertyValue = "resourceTypeValue";
106 private static final String componentId = "dac65869-dfb4-40d2-aa20-084324659ec1";
107 private static final String componentInstance = "dac65869-dfb4-40d2-aa20-084324659ec1.resource0";
108 private static final String componentType = "resources";
109 private static final String capabilityName = "MyCapabilityName";
110 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";
111 private static final String V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER = "/v1/catalog/%s/%s/componentInstance/%s/%s/nodeFilter";
112 private final UIConstraint uiConstraint = new UIConstraint("resourceType", "equal", "static", "static", "resourceTypeValue");
113 private final String constraint = new ConstraintConvertor().convert(uiConstraint);
114 private final String inputJson = buildConstraintDataJson(uiConstraint);
115 private final User user = new User("", "", USER_ID, "", Role.ADMIN.name(), null);
117 private HttpServletRequest request;
119 private HttpSession session;
121 private ServletContext servletContext;
123 private WebAppContextWrapper webAppContextWrapper;
125 private WebApplicationContext webApplicationContext;
127 private UserBusinessLogic userBusinessLogic;
129 private ComponentInstanceBusinessLogic componentInstanceBusinessLogic;
131 private ComponentsUtils componentsUtils;
133 private ServletUtils servletUtils;
135 private ResourceImportManager resourceImportManager;
137 private ComponentNodeFilterBusinessLogic componentNodeFilterBusinessLogic;
139 private ResponseFormat responseFormat;
141 private UserValidations userValidations;
143 private CINodeFilterDataDefinition ciNodeFilterDataDefinition;
145 public ComponentNodeFilterServletTest() throws JsonProcessingException {
149 public void initClass() {
150 MockitoAnnotations.initMocks(this);
151 when(request.getSession()).thenReturn(session);
152 when(session.getServletContext()).thenReturn(servletContext);
153 when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
154 when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
155 when(webApplicationContext.getBean(ComponentNodeFilterBusinessLogic.class)).thenReturn(componentNodeFilterBusinessLogic);
156 when(request.getHeader("USER_ID")).thenReturn(USER_ID);
157 when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
158 when(servletUtils.getComponentsUtils()).thenReturn(componentsUtils);
159 final String appConfigDir = "src/test/resources/config/catalog-be";
160 final ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
161 final ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
162 final org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
163 configuration.setJanusGraphInMemoryGraph(true);
164 configurationManager.setConfiguration(configuration);
165 ExternalConfiguration.setAppName("catalog-be");
169 public void resetMock() throws Exception {
174 void after() throws Exception {
179 void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
181 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
182 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
183 NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
185 doReturn(user).when(componentNodeFilterBusinessLogic).validateUser(USER_ID);
186 doReturn(HttpStatus.OK_200).when(responseFormat).getStatus();
187 doReturn(responseFormat).when(componentsUtils).getResponseFormat(ActionStatus.OK);
188 doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
189 assertNotNull(uiConstraint);
190 assertThat(servicePropertyName).isEqualToIgnoringCase(uiConstraint.getServicePropertyName());
191 assertThat(constraintOperator).isEqualToIgnoringCase(uiConstraint.getConstraintOperator());
192 assertThat(sourceType).isEqualToIgnoringCase(uiConstraint.getSourceType());
193 assertThat(sourceName).isEqualToIgnoringCase(uiConstraint.getSourceName());
194 assertThat(propertyValue).isEqualToIgnoringCase(uiConstraint.getValue().toString());
196 doReturn(Optional.of(uiConstraint)).when(componentsUtils)
197 .parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class));
199 assertNotNull(constraint);
200 assertNotNull(ciNodeFilterDataDefinition);
201 assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
202 assertThat("resourceType: {equal: resourceTypeValue}\n").isEqualToIgnoringCase(constraint);
204 doReturn(Optional.of(ciNodeFilterDataDefinition)).when(componentNodeFilterBusinessLogic)
205 .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
206 uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
207 NodeFilterConstraintType.PROPERTIES, "");
209 final Response response = target()
211 .request(MediaType.APPLICATION_JSON)
212 .header(USER_ID_HEADER, USER_ID)
213 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
215 verify(componentNodeFilterBusinessLogic, times(1))
216 .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(),
217 anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
218 ArgumentMatchers.any(NodeFilterConstraintType.class), anyString());
220 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
221 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
225 void addNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
227 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
228 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
229 NodeFilterConstraintType.CAPABILITIES_PARAM_NAME);
230 final UIConstraint uiConstraint1 = new UIConstraint(uiConstraint.getServicePropertyName(), uiConstraint.getConstraintOperator(),
231 uiConstraint.getSourceType(), uiConstraint.getSourceName(), uiConstraint.getValue());
232 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
233 when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
234 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
235 doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
236 uiConstraint1.setCapabilityName(capabilityName);
238 when(componentsUtils.parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class)))
239 .thenReturn(Optional.of(uiConstraint1));
241 assertThat(ciNodeFilterDataDefinition.getProperties().getListToscaDataDefinition()).hasSize(1);
242 when(componentNodeFilterBusinessLogic
243 .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
244 uiConstraint1.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
245 NodeFilterConstraintType.CAPABILITIES, capabilityName))
246 .thenReturn(Optional.of(ciNodeFilterDataDefinition));
248 final Response response = target()
250 .request(MediaType.APPLICATION_JSON)
251 .header(USER_ID_HEADER, USER_ID)
252 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
254 verify(componentNodeFilterBusinessLogic, times(1))
255 .addNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class), anyString(),
256 anyString(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
257 ArgumentMatchers.any(NodeFilterConstraintType.class), anyString());
259 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
260 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
264 void addNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
266 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
267 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
268 NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
270 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
272 final Response response = target()
274 .request(MediaType.APPLICATION_JSON)
275 .header(USER_ID_HEADER, USER_ID)
276 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
278 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
279 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
283 void addNodeFilterFailConstraintParseTest() throws JsonProcessingException {
285 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
286 final String path = String.format(pathFormat, componentType, componentId, componentInstance, NodeFilterConstraintType.PROPERTIES_PARAM_NAME);
288 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
290 final Response response = target()
292 .request(MediaType.APPLICATION_JSON)
293 .header(USER_ID_HEADER, USER_ID)
294 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
296 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
297 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
301 void addNodeFilterFailConvertTest() throws JsonProcessingException {
303 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_NODE_FILTER;
304 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
305 NodeFilterConstraintType.PROPERTIES.getType());
307 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
309 final Response response = target()
311 .request(MediaType.APPLICATION_JSON)
312 .header(USER_ID_HEADER, USER_ID)
313 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
315 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
316 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
320 void updateNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
322 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
323 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
324 NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
326 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
328 when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
329 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
330 doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
331 doReturn(Optional.of(uiConstraint)).when(componentsUtils)
332 .parseToConstraint(anyString(), any(User.class), eq(ComponentTypeEnum.RESOURCE));
333 when(componentNodeFilterBusinessLogic
334 .updateNodeFilter(componentId, componentInstance, uiConstraint, ComponentTypeEnum.RESOURCE,
335 NodeFilterConstraintType.PROPERTIES, 0)).thenReturn(Optional.of(ciNodeFilterDataDefinition));
336 final Response response = target()
338 .request(MediaType.APPLICATION_JSON)
339 .header(USER_ID_HEADER, USER_ID)
340 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
342 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
343 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
347 void updateNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
349 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
350 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
351 NodeFilterConstraintType.CAPABILITIES_PARAM_NAME, 0);
353 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
355 when(componentsUtils.parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class)))
356 .thenReturn(Optional.of(uiConstraint));
357 doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
358 when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
359 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
361 when(componentNodeFilterBusinessLogic
362 .updateNodeFilter(componentId, componentInstance, uiConstraint,
363 ComponentTypeEnum.RESOURCE, NodeFilterConstraintType.CAPABILITIES, 0))
364 .thenReturn(Optional.of(ciNodeFilterDataDefinition));
366 final Response response = target()
368 .request(MediaType.APPLICATION_JSON)
369 .header(USER_ID_HEADER, USER_ID)
370 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
372 verify(componentNodeFilterBusinessLogic, times(1))
373 .updateNodeFilter(anyString(), anyString(), ArgumentMatchers.any(UIConstraint.class),
374 ArgumentMatchers.any(ComponentTypeEnum.class), ArgumentMatchers.any(NodeFilterConstraintType.class),
377 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
378 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
382 void updateNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
384 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
385 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
386 NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
388 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
390 final Response response = target()
392 .request(MediaType.APPLICATION_JSON)
393 .header(USER_ID_HEADER, USER_ID)
394 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
396 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
397 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
401 void updateNodeFilterFailConstraintParseTest() throws JsonProcessingException {
403 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
404 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
405 NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
407 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
409 final Response response = target()
411 .request(MediaType.APPLICATION_JSON)
412 .header(USER_ID_HEADER, USER_ID)
413 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
415 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
416 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
420 void updateNodeFilterFailConvertTest() throws JsonProcessingException {
422 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
423 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
424 NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
426 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
428 final Response response = target()
430 .request(MediaType.APPLICATION_JSON)
431 .header(USER_ID_HEADER, USER_ID)
432 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
434 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
435 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
439 void deleteNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException {
441 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
442 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
443 NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
445 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
446 doReturn(componentsUtils).when(servletUtils).getComponentsUtils();
447 when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
448 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
450 when(componentNodeFilterBusinessLogic.deleteNodeFilter(componentId, componentInstance,
451 NodeFilterConstraintAction.DELETE, null, 0, true, ComponentTypeEnum.RESOURCE,
452 NodeFilterConstraintType.PROPERTIES))
453 .thenReturn(Optional.of(ciNodeFilterDataDefinition));
455 final Response response = target()
457 .request(MediaType.APPLICATION_JSON)
458 .accept(MediaType.APPLICATION_JSON)
459 .header(USER_ID_HEADER, USER_ID)
460 .delete(Response.class);
462 verify(componentNodeFilterBusinessLogic, times(1))
463 .deleteNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class),
464 nullable(String.class), anyInt(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class),
465 ArgumentMatchers.any(NodeFilterConstraintType.class));
467 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
468 verify(componentNodeFilterBusinessLogic,times(1)).validateUser(USER_ID);
472 void deleteNodeFilterFailTest() {
473 final String pathFormat = V_1_CATALOG_S_S_COMPONENT_INSTANCE_S_S_S_NODE_FILTER;
474 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
475 NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 0);
476 final Response response = target()
478 .request(MediaType.APPLICATION_JSON)
479 .accept(MediaType.APPLICATION_JSON)
480 .header(USER_ID_HEADER, USER_ID)
481 .delete(Response.class);
483 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
487 protected ResourceConfig configure() {
488 forceSet(TestProperties.CONTAINER_PORT, "0");
489 final ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
490 return new ResourceConfig(ComponentNodeFilterServlet.class)
491 .register(new AbstractBinder() {
493 protected void configure() {
494 bind(request).to(HttpServletRequest.class);
495 bind(userBusinessLogic).to(UserBusinessLogic.class);
496 bind(componentInstanceBusinessLogic).to(ComponentInstanceBusinessLogic.class);
497 bind(componentsUtils).to(ComponentsUtils.class);
498 bind(servletUtils).to(ServletUtils.class);
499 bind(resourceImportManager).to(ResourceImportManager.class);
500 bind(componentNodeFilterBusinessLogic).to(ComponentNodeFilterBusinessLogic.class);
503 .property("contextConfig", context);
506 private void initComponentData() throws JsonProcessingException {
507 final RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition =
508 new RequirementNodeFilterPropertyDataDefinition();
509 requirementNodeFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
510 requirementNodeFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
512 final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> propertyDataDefinitionList =
513 new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterPropertyDataDefinition)));
515 final RequirementNodeFilterCapabilityDataDefinition requirementNodeFilterCapabilityDataDefinition =
516 new RequirementNodeFilterCapabilityDataDefinition();
517 requirementNodeFilterCapabilityDataDefinition.setName(uiConstraint.getServicePropertyName());
518 requirementNodeFilterCapabilityDataDefinition.setProperties(propertyDataDefinitionList);
520 final ListDataDefinition<RequirementNodeFilterCapabilityDataDefinition> capabilityDataDefinitionList =
521 new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterCapabilityDataDefinition)));
523 ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
524 ciNodeFilterDataDefinition.setProperties(propertyDataDefinitionList);
525 ciNodeFilterDataDefinition.setCapabilities(capabilityDataDefinitionList);
526 ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
530 private String buildConstraintDataJson(final UIConstraint uiConstraint) throws JsonProcessingException {
531 final ObjectMapper mapper = new ObjectMapper();
532 return mapper.writeValueAsString(uiConstraint);