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.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;
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;
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;
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";
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;
115 private CINodeFilterDataDefinition ciNodeFilterDataDefinition;
116 private RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition;
117 private UIConstraint uiConstraint;
118 private String constraint;
119 private String inputJson;
123 public static void initClass() {
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);
136 public void resetMock() throws Exception {
138 reset(componentNodeFilterBusinessLogic);
142 void after() throws Exception {
147 public void addNodeFilterPropertiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
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);
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);
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());
165 when(componentsUtils.parseToConstraint(anyString(), any(User.class), ArgumentMatchers.any(ComponentTypeEnum.class)))
166 .thenReturn(Optional.of(uiConstraint));
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));
178 final Response response = target()
180 .request(MediaType.APPLICATION_JSON)
181 .header(USER_ID_HEADER, USER_ID)
182 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
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));
189 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
193 public void addNodeFilterCapabilitiesSuccessTest() throws BusinessLogicException, JsonProcessingException {
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);
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));
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));
213 final Response response = target()
215 .request(MediaType.APPLICATION_JSON)
216 .header(USER_ID_HEADER, USER_ID)
217 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
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));
224 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
228 public void addNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
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);
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);
239 when(componentsUtils.convertJsonToObjectUsingObjectMapper(anyString(), any(User.class),
240 ArgumentMatchers.<Class<UIConstraint>>any(),
241 nullable(AuditingActionEnum.class), nullable(ComponentTypeEnum.class))).thenReturn(Either.left(uiConstraint));
243 when(componentNodeFilterBusinessLogic
244 .addNodeFilter(componentId, componentInstance, NodeFilterConstraintAction.ADD,
245 uiConstraint.getServicePropertyName(), constraint, true, ComponentTypeEnum.RESOURCE,
246 NodeFilterConstraintType.PROPERTIES))
247 .thenReturn(Optional.empty());
249 final Response response = target()
251 .request(MediaType.APPLICATION_JSON)
252 .header(USER_ID_HEADER, USER_ID)
253 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
255 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
259 public void addNodeFilterFailConstraintParseTest() throws JsonProcessingException {
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);
264 when(userValidations.validateUserExists(user)).thenReturn(user);
265 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
267 when(responseFormat.getStatus()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR_500);
268 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
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)));
275 final Response response = target()
277 .request(MediaType.APPLICATION_JSON)
278 .header(USER_ID_HEADER, USER_ID)
279 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
281 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
285 public void addNodeFilterFailConvertTest() throws JsonProcessingException, BusinessLogicException {
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());
291 when(userValidations.validateUserExists(user)).thenReturn(user);
292 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
294 when(responseFormat.getStatus()).thenReturn(HttpStatus.INTERNAL_SERVER_ERROR_500);
295 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
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));
302 final Response response = target()
304 .request(MediaType.APPLICATION_JSON)
305 .header(USER_ID_HEADER, USER_ID)
306 .post(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
308 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
312 public void updateNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException {
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);
318 when(userValidations.validateUserExists(user)).thenReturn(user);
319 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
321 when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
322 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
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))));
329 when(componentNodeFilterBusinessLogic
330 .updateNodeFilter(componentId, componentInstance, Collections.singletonList(constraint),
331 true, ComponentTypeEnum.RESOURCE)).thenReturn(Optional.of(ciNodeFilterDataDefinition));
332 final Response response = target()
334 .request(MediaType.APPLICATION_JSON)
335 .header(USER_ID_HEADER, USER_ID)
336 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
338 verify(componentNodeFilterBusinessLogic, times(1))
339 .updateNodeFilter(anyString(), anyString(), anyList(), anyBoolean(),
340 ArgumentMatchers.any(ComponentTypeEnum.class));
342 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
346 public void updateNodeFilterFailTest() throws BusinessLogicException, JsonProcessingException {
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);
352 when(userValidations.validateUserExists(user)).thenReturn(user);
353 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
355 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
357 when(componentsUtils.validateAndParseConstraint(ArgumentMatchers.any(ComponentTypeEnum.class), anyString(), any(User.class)))
358 .thenReturn(Collections.singletonList(uiConstraint));
360 when(componentNodeFilterBusinessLogic
361 .updateNodeFilter(componentId, componentInstance, Collections.singletonList(constraint),
362 true, ComponentTypeEnum.RESOURCE))
363 .thenReturn(Optional.empty());
364 final Response response = target()
366 .request(MediaType.APPLICATION_JSON)
367 .header(USER_ID_HEADER, USER_ID)
368 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
370 verify(componentNodeFilterBusinessLogic, times(1))
371 .updateNodeFilter(anyString(), anyString(), anyList(), anyBoolean(),
372 ArgumentMatchers.any(ComponentTypeEnum.class));
375 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
379 public void updateNodeFilterFailConstraintParseTest() throws JsonProcessingException {
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);
385 when(userValidations.validateUserExists(user)).thenReturn(user);
386 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
387 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
389 when(componentsUtils.validateAndParseConstraint(ArgumentMatchers.any(ComponentTypeEnum.class), anyString(), any(User.class)))
390 .thenReturn(Collections.emptyList());
392 final Response response = target()
394 .request(MediaType.APPLICATION_JSON)
395 .header(USER_ID_HEADER, USER_ID)
396 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
398 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
402 public void updateNodeFilterFailConvertTest() throws JsonProcessingException {
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);
408 when(userValidations.validateUserExists(user)).thenReturn(user);
409 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
410 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
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));
417 final Response response = target()
419 .request(MediaType.APPLICATION_JSON)
420 .header(USER_ID_HEADER, USER_ID)
421 .put(Entity.entity(inputJson, MediaType.APPLICATION_JSON));
423 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
427 public void deleteNodeFilterSuccessTest() throws BusinessLogicException, JsonProcessingException {
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);
433 when(userValidations.validateUserExists(user)).thenReturn(user);
434 when(componentNodeFilterBusinessLogic.validateUser(USER_ID)).thenReturn(user);
436 when(responseFormat.getStatus()).thenReturn(HttpStatus.OK_200);
437 when(componentsUtils.getResponseFormat(ActionStatus.OK)).thenReturn(responseFormat);
439 when(componentNodeFilterBusinessLogic.deleteNodeFilter(componentId, componentInstance,
440 NodeFilterConstraintAction.DELETE, null, 0, true, ComponentTypeEnum.RESOURCE))
441 .thenReturn(Optional.of(ciNodeFilterDataDefinition));
443 final Response response = target()
445 .request(MediaType.APPLICATION_JSON)
446 .accept(MediaType.APPLICATION_JSON)
447 .header(USER_ID_HEADER, USER_ID)
448 .delete(Response.class);
450 verify(componentNodeFilterBusinessLogic, times(1))
451 .deleteNodeFilter(anyString(), anyString(), ArgumentMatchers.any(NodeFilterConstraintAction.class),
452 nullable(String.class), anyInt(), anyBoolean(), ArgumentMatchers.any(ComponentTypeEnum.class));
454 assertThat(response.getStatus()).isEqualTo(HttpStatus.OK_200);
458 public void deleteNodeFilterFailTest() {
459 final String pathFormat = "/v1/catalog/%s/%s/resourceInstances/%s/nodeFilter/%s/%s";
460 final String path = String.format(pathFormat, componentType, componentId, componentInstance,
461 NodeFilterConstraintType.PROPERTIES_PARAM_NAME, 1);
462 final Response response = target()
464 .request(MediaType.APPLICATION_JSON)
465 .accept(MediaType.APPLICATION_JSON)
466 .header(USER_ID_HEADER, USER_ID)
467 .delete(Response.class);
469 assertThat(response.getStatus()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR_500);
472 private static void createMocks() {
473 request = mock(HttpServletRequest.class);
474 userBusinessLogic = mock(UserBusinessLogic.class);
475 componentInstanceBusinessLogic = mock(ComponentInstanceBusinessLogic.class);
476 componentsUtils = mock(ComponentsUtils.class);
477 servletUtils = mock(ServletUtils.class);
478 resourceImportManager = mock(ResourceImportManager.class);
479 componentNodeFilterBusinessLogic = mock(ComponentNodeFilterBusinessLogic.class);
481 session = mock(HttpSession.class);
482 servletContext = mock(ServletContext.class);
483 webAppContextWrapper = mock(WebAppContextWrapper.class);
484 webApplicationContext = mock(WebApplicationContext.class);
485 responseFormat = mock(ResponseFormat.class);
486 userValidations = mock(UserValidations.class);
490 protected ResourceConfig configure() {
491 forceSet(TestProperties.CONTAINER_PORT, "0");
492 final ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
493 return new ResourceConfig(ComponentNodeFilterServlet.class)
494 .register(new AbstractBinder() {
496 protected void configure() {
497 bind(request).to(HttpServletRequest.class);
498 bind(userBusinessLogic).to(UserBusinessLogic.class);
499 bind(componentInstanceBusinessLogic).to(ComponentInstanceBusinessLogic.class);
500 bind(componentsUtils).to(ComponentsUtils.class);
501 bind(servletUtils).to(ServletUtils.class);
502 bind(resourceImportManager).to(ResourceImportManager.class);
503 bind(componentNodeFilterBusinessLogic).to(ComponentNodeFilterBusinessLogic.class);
506 .property("contextConfig", context);
509 private void initComponentData() throws JsonProcessingException {
510 uiConstraint = new UIConstraint("resourceType", "equal", "static", "static", "resourceTypeValue");
511 constraint = new ConstraintConvertor().convert(uiConstraint);
512 inputJson = buildConstraintDataJson(uiConstraint);
514 requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
515 requirementNodeFilterPropertyDataDefinition.setName(uiConstraint.getServicePropertyName());
516 requirementNodeFilterPropertyDataDefinition.setConstraints(new LinkedList<>(Arrays.asList(constraint)));
518 final ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
519 new ListDataDefinition<>(new LinkedList<>(Arrays.asList(requirementNodeFilterPropertyDataDefinition)));
521 ciNodeFilterDataDefinition = new CINodeFilterDataDefinition();
522 ciNodeFilterDataDefinition.setProperties(listDataDefinition);
523 ciNodeFilterDataDefinition.setID("NODE_FILTER_UID");
526 user.setUserId(USER_ID);
527 user.setRole(Role.ADMIN.name());
530 private String buildConstraintDataJson(final UIConstraint uiConstraint) throws JsonProcessingException {
531 final ObjectMapper mapper = new ObjectMapper();
532 return mapper.writeValueAsString(uiConstraint);