2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.components.validation;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.ArgumentMatchers.eq;
27 import static org.mockito.Mockito.when;
29 import fj.data.Either;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.Collections;
33 import java.util.HashMap;
34 import java.util.LinkedList;
35 import java.util.List;
37 import org.junit.jupiter.api.BeforeEach;
38 import org.junit.jupiter.api.Test;
39 import org.mockito.InjectMocks;
40 import org.mockito.Mock;
41 import org.mockito.Mockito;
42 import org.mockito.MockitoAnnotations;
43 import org.openecomp.sdc.be.config.ConfigurationManager;
44 import org.openecomp.sdc.be.dao.api.ActionStatus;
45 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
46 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
47 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
48 import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
49 import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
50 import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
51 import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
52 import org.openecomp.sdc.be.datatypes.enums.PropertySource;
53 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
54 import org.openecomp.sdc.be.impl.ComponentsUtils;
55 import org.openecomp.sdc.be.model.ComponentInstance;
56 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
57 import org.openecomp.sdc.be.model.DataTypeDefinition;
58 import org.openecomp.sdc.be.model.PropertyDefinition;
59 import org.openecomp.sdc.be.model.Service;
60 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
61 import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
62 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
63 import org.openecomp.sdc.be.model.validation.FilterConstraintValidator;
64 import org.openecomp.sdc.common.impl.ExternalConfiguration;
65 import org.openecomp.sdc.common.impl.FSConfigurationSource;
66 import org.openecomp.sdc.exception.ResponseFormat;
68 class NodeFilterValidatorTest {
70 private static final String INNER_SERVICE = "innerService";
71 private static final String PROPERTY_NAME = "Prop1";
72 private static final String COMPONENT1_ID = "component1";
73 private static final String PARENT_SERVICE_ID = "parentservice";
74 private static final String COMPONENT2_ID = "component2";
75 private ComponentsUtils componentsUtils;
78 private ApplicationDataTypeCache applicationDataTypeCache;
80 private FilterConstraintValidator filterConstraintValidator;
82 private NodeFilterValidator nodeFilterValidator;
83 private FilterConstraintDto baseFilterConstraintDto;
87 componentsUtils = Mockito.mock(ComponentsUtils.class);
88 MockitoAnnotations.openMocks(this);
89 baseFilterConstraintDto = new FilterConstraintDto();
90 baseFilterConstraintDto.setPropertyName(PROPERTY_NAME);
91 baseFilterConstraintDto.setValueType(FilterValueType.STATIC);
92 baseFilterConstraintDto.setOperator(ConstraintType.EQUAL);
93 baseFilterConstraintDto.setTargetType(PropertyFilterTargetType.PROPERTY);
94 baseFilterConstraintDto.setValue("value");
95 when(applicationDataTypeCache.getAll(any())).thenReturn(Either.left(Map.of()));
96 new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
100 void testValidateComponentInstanceExist() {
101 final ResponseFormat expectedResponse = new ResponseFormat();
102 when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, "?", INNER_SERVICE)).thenReturn(expectedResponse);
103 Either<Boolean, ResponseFormat> either =
104 nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE);
105 assertTrue(either.isRight());
106 assertEquals(expectedResponse, either.right().value());
108 Service service = createService("booleanIncorrect");
109 when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, service.getName(), INNER_SERVICE))
110 .thenReturn(expectedResponse);
111 either = nodeFilterValidator.validateComponentInstanceExist(service, INNER_SERVICE);
112 assertTrue(either.isRight());
113 assertEquals(expectedResponse, either.right().value());
115 List<ComponentInstance> list = new LinkedList<>();
116 ComponentInstance instance = new ComponentInstance();
117 instance.setUniqueId("uniqueId");
119 service.setComponentInstances(list);
120 either = nodeFilterValidator.validateComponentInstanceExist(service, "uniqueId");
121 assertTrue(either.isLeft());
125 void testValidateNodeFilterStaticIncorrectPropertyTypeProvided() {
126 final Service service = createService("booleanIncorrect");
127 final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(PROPERTY_NAME, FilterValueType.STATIC, ConstraintType.EQUAL,
128 PropertyFilterTargetType.PROPERTY, "true");
129 Either<Boolean, ResponseFormat> either =
130 nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
131 assertTrue(either.isRight());
132 filterConstraintDto.setTargetType(PropertyFilterTargetType.CAPABILITY);
133 either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
134 assertTrue(either.isRight());
138 void testValidateComponentFilter() {
139 Service service = createService("integer");
140 final var filterConstraint1 = buildFilterConstraintDto(
142 FilterValueType.GET_PROPERTY,
143 ConstraintType.EQUAL,
144 PropertyFilterTargetType.PROPERTY,
145 createToscaGetFunction("test", PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of("test2"), null)
147 Either<Boolean, ResponseFormat> actualValidationResult =
148 nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
149 assertTrue(actualValidationResult.isRight());
151 final var filterConstraint2 = buildFilterConstraintDto(
153 FilterValueType.GET_PROPERTY,
154 ConstraintType.EQUAL,
155 PropertyFilterTargetType.PROPERTY,
156 createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of("Prop1"), null)
158 actualValidationResult =
159 nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint2));
160 assertTrue(actualValidationResult.isLeft());
162 final var staticFilter1 = buildFilterConstraintDto(
164 FilterValueType.STATIC,
165 ConstraintType.EQUAL,
166 PropertyFilterTargetType.PROPERTY,
169 actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter1));
170 assertTrue(actualValidationResult.isLeft());
171 assertTrue(actualValidationResult.left().value());
173 final var staticFilter2 = buildFilterConstraintDto(
175 FilterValueType.STATIC,
176 ConstraintType.EQUAL,
177 PropertyFilterTargetType.PROPERTY,
180 actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter2));
181 assertTrue(actualValidationResult.isRight());
183 service = createService(ToscaPropertyType.BOOLEAN.getType());
184 final var staticFilter3 = buildFilterConstraintDto(
186 FilterValueType.STATIC,
187 ConstraintType.GREATER_THAN,
188 PropertyFilterTargetType.PROPERTY,
191 actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter3));
192 assertTrue(actualValidationResult.isRight());
194 final var staticFilter4 = buildFilterConstraintDto(
196 FilterValueType.STATIC,
197 ConstraintType.GREATER_THAN,
198 PropertyFilterTargetType.PROPERTY,
201 actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(staticFilter4));
202 assertTrue(actualValidationResult.isRight());
206 void testValidateComponentFilterWithIndex() {
207 Service service = createService("string", "schema");
208 final var filterConstraint1 = buildFilterConstraintDto(
210 FilterValueType.GET_PROPERTY,
211 ConstraintType.EQUAL,
212 PropertyFilterTargetType.PROPERTY,
213 createToscaGetFunction("test", PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME, "alist"), List.of("1"))
215 Map<String, DataTypeDefinition> data = new HashMap<>();
216 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
217 List<PropertyDefinition> properties = new ArrayList<>();
218 PropertyDefinition propertyDefinition = new PropertyDefinition();
219 propertyDefinition.setName("alist");
220 propertyDefinition.setType("list");
222 SchemaDefinition schemaDefinition = new SchemaDefinition();
223 PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
224 schemaProperty.setType("string");
225 schemaDefinition.setProperty(schemaProperty);
226 propertyDefinition.setSchema(schemaDefinition);
228 properties.add(propertyDefinition);
229 dataTypeDefinition.setProperties(properties);
231 data.put("string", dataTypeDefinition);
232 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = Either.left(data);
233 when(applicationDataTypeCache.getAll(null)).thenReturn(allDataTypes);
235 Either<Boolean, ResponseFormat> actualValidationResult =
236 nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
237 assertTrue(actualValidationResult.isLeft());
241 void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
242 Service service = createService(ToscaPropertyType.BOOLEAN.getType());
243 final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(
245 FilterValueType.STATIC,
246 ConstraintType.GREATER_THAN,
247 PropertyFilterTargetType.PROPERTY,
250 final ResponseFormat expectedResponse = new ResponseFormat();
251 when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.BOOLEAN.getType(),
252 filterConstraintDto.getPropertyName(), "\"true\"")
253 ).thenReturn(expectedResponse);
254 final Either<Boolean, ResponseFormat> validationResult =
255 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(filterConstraintDto));
256 assertTrue(validationResult.isRight());
257 assertEquals(expectedResponse, validationResult.right().value());
261 void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
262 final Service service = createService(ToscaPropertyType.BOOLEAN.getType());
263 baseFilterConstraintDto.setValue("trues");
265 final ResponseFormat responseFormat = new ResponseFormat();
266 when(componentsUtils.getResponseFormat
267 (ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.BOOLEAN.getType(), PROPERTY_NAME, "\"trues\"")
268 ).thenReturn(responseFormat);
269 final Either<Boolean, ResponseFormat> validationResult =
270 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
272 assertTrue(validationResult.isRight());
273 assertEquals(responseFormat, validationResult.right().value());
277 void testValidateNodeFilterStaticIncorrectOperatorProvidedString() {
278 Service service = createService(ToscaPropertyType.STRING.getType());
279 baseFilterConstraintDto.setValue("true");
280 baseFilterConstraintDto.setOperator(ConstraintType.GREATER_THAN);
281 Either<Boolean, ResponseFormat> either =
282 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
284 assertTrue(either.isLeft());
288 void testValidateNodeFilterIntegerValueSuccess() {
289 Service service = createService(ToscaPropertyType.INTEGER.getType());
290 baseFilterConstraintDto.setValue(1);
291 Either<Boolean, ResponseFormat> validationResult =
292 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
294 assertTrue(validationResult.isLeft());
298 void testValidateNodeFilterIntegerValueFail() {
299 Service service = createService(ToscaPropertyType.INTEGER.getType());
301 baseFilterConstraintDto.setValue(1.0);
303 final ResponseFormat expectedResponse = new ResponseFormat();
304 when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.INTEGER.getType(),
305 baseFilterConstraintDto.getPropertyName(), "1.0")
306 ).thenReturn(expectedResponse);
307 Either<Boolean, ResponseFormat> validationResult =
308 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
310 assertTrue(validationResult.isRight());
311 assertEquals(expectedResponse, validationResult.right().value());
315 void testValidateNodeFilterFloatValueSuccess() {
316 final Service service = createService(ToscaPropertyType.FLOAT.getType());
317 baseFilterConstraintDto.setValue(1.0);
318 final Either<Boolean, ResponseFormat> validationResult =
319 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
321 assertTrue(validationResult.isLeft());
322 assertTrue(validationResult.left().value());
326 void testValidateNodeFilterFloatValueFail() {
327 Service service = createService(ToscaPropertyType.FLOAT.getType());
329 when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1")).thenReturn(new ResponseFormat());
331 Either<Boolean, ResponseFormat> either =
332 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
334 assertTrue(either.isRight());
338 void testValidateNodeFilterStringValueSuccess() {
339 Service service = createService(ToscaPropertyType.STRING.getType());
340 Either<Boolean, ResponseFormat> either =
341 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
343 assertTrue(either.isLeft());
347 void testValidatePropertyConstraintBrotherSuccess() {
348 Service service = createService(ToscaPropertyType.STRING.getType());
349 final ToscaGetFunctionDataDefinition toscaGetFunction =
350 createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
351 final var filterConstraintDto = buildFilterConstraintDto(
353 FilterValueType.GET_PROPERTY,
354 ConstraintType.EQUAL,
355 PropertyFilterTargetType.PROPERTY,
358 Either<Boolean, ResponseFormat> either =
359 nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
361 assertTrue(either.isLeft());
362 assertTrue(either.left().value());
366 void testValidatePropertyConstraintParentSuccess() {
367 final var service = createService(ToscaPropertyType.STRING.getType());
368 final ToscaGetFunctionDataDefinition toscaGetFunction =
369 createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
370 final var filterConstraintDto = buildFilterConstraintDto(
372 FilterValueType.GET_PROPERTY,
373 ConstraintType.EQUAL,
374 PropertyFilterTargetType.PROPERTY,
377 final Either<Boolean, ResponseFormat> validationResult =
378 nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
380 assertTrue(validationResult.isLeft());
381 assertTrue(validationResult.left().value());
385 void testValidatePropertyConstraintBrotherPropertyTypeMismatch() {
386 final Service service = createService(ToscaPropertyType.STRING.getType());
387 service.getComponentInstancesProperties().get(COMPONENT2_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
388 final ToscaGetFunctionDataDefinition toscaGetFunction =
389 createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
390 final var filterConstraintDto = buildFilterConstraintDto(
392 FilterValueType.GET_PROPERTY,
393 ConstraintType.EQUAL,
394 PropertyFilterTargetType.PROPERTY,
398 final ResponseFormat expectedResponse = new ResponseFormat();
399 when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
400 PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(), PROPERTY_NAME, ToscaPropertyType.STRING.getType())
401 ).thenReturn(expectedResponse);
403 final Either<Boolean, ResponseFormat> either =
404 nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
406 assertTrue(either.isRight());
407 assertEquals(expectedResponse, either.right().value());
411 void testValidatePropertyConstraintParentPropertyTypeMismatch() {
412 final Service service = createService(ToscaPropertyType.STRING.getType());
413 service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
414 final ToscaGetFunctionDataDefinition toscaGetFunction =
415 createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
416 final var filterConstraintDto = buildFilterConstraintDto(
418 FilterValueType.GET_PROPERTY,
419 ConstraintType.EQUAL,
420 PropertyFilterTargetType.PROPERTY,
424 final ResponseFormat expectedResponse = new ResponseFormat();
425 when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
426 PROPERTY_NAME, ToscaPropertyType.STRING.getType(), PROPERTY_NAME, ToscaPropertyType.INTEGER.getType())
427 ).thenReturn(expectedResponse);
429 Either<Boolean, ResponseFormat> either =
430 nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
432 assertTrue(either.isRight());
433 assertEquals(expectedResponse, either.right().value());
437 void testValidatePropertyConstraintParentPropertyNotFound() {
438 final Service service = createService(ToscaPropertyType.STRING.getType());
439 service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
441 final ResponseFormat expectedResponse = new ResponseFormat();
442 when(componentsUtils.getResponseFormat(eq(ActionStatus.FILTER_PROPERTY_NOT_FOUND), any(), any()))
443 .thenReturn(expectedResponse);
445 final ToscaGetFunctionDataDefinition toscaGetFunction =
446 createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
447 final var filterConstraintDto = buildFilterConstraintDto(
449 FilterValueType.GET_PROPERTY,
450 ConstraintType.EQUAL,
451 PropertyFilterTargetType.PROPERTY,
454 final Either<Boolean, ResponseFormat> validationResult =
455 nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
457 assertTrue(validationResult.isRight());
458 assertEquals(expectedResponse, validationResult.right().value());
462 void testValidatePropertyConstraintBrotherPropertyNotFound() {
463 Service service = createService(ToscaPropertyType.STRING.getType());
464 service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
465 final ToscaGetFunctionDataDefinition toscaGetFunction =
466 createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
467 final var filterConstraintDto = buildFilterConstraintDto(
469 FilterValueType.GET_PROPERTY,
470 ConstraintType.EQUAL,
471 PropertyFilterTargetType.PROPERTY,
474 final ResponseFormat expectedResponse = new ResponseFormat();
475 when(componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, "Target", PROPERTY_NAME))
476 .thenReturn(expectedResponse);
477 Either<Boolean, ResponseFormat> either =
478 nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
480 assertTrue(either.isRight());
481 assertEquals(expectedResponse, either.right().value());
484 protected static ToscaGetFunctionDataDefinition createToscaGetFunction(final String sourceName,
485 final PropertySource propertySource,
486 final ToscaGetFunctionType toscaGetFunctionType,
487 final List<String> propertyPathFromSource,
488 final List<Object> toscaIndexList) {
489 final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
490 toscaGetFunction.setFunctionType(toscaGetFunctionType);
491 toscaGetFunction.setPropertyPathFromSource(propertyPathFromSource);
492 toscaGetFunction.setSourceName(sourceName);
493 toscaGetFunction.setPropertySource(propertySource);
494 toscaGetFunction.setPropertyName(propertyPathFromSource.get(0));
495 toscaGetFunction.setToscaIndexList(toscaIndexList);
496 return toscaGetFunction;
500 void testValidatePropertyConstraintParentPropertySchemaMismatch() {
501 final Service service = createService(ToscaPropertyType.LIST.getType(), ToscaPropertyType.STRING.getType());
502 service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.LIST.getType());
503 final var schemaProperty = new PropertyDataDefinition();
504 schemaProperty.setType(ToscaPropertyType.INTEGER.getType());
505 final var schemaDefinition = new SchemaDefinition();
506 schemaDefinition.setProperty(schemaProperty);
507 service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setSchema(schemaDefinition);
509 final ToscaGetFunctionDataDefinition toscaGetFunction =
510 createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
511 final var filterConstraintDto = buildFilterConstraintDto(
513 FilterValueType.GET_PROPERTY,
514 ConstraintType.EQUAL,
515 PropertyFilterTargetType.PROPERTY,
519 final ResponseFormat expectedResponse = new ResponseFormat();
520 when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH, PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(),
521 PROPERTY_NAME, ToscaPropertyType.STRING.getType())
522 ).thenReturn(expectedResponse);
524 Either<Boolean, ResponseFormat> either =
525 nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
527 assertTrue(either.isRight());
528 assertEquals(expectedResponse, either.right().value());
531 private Service createService(String type) {
532 return createService(type, null);
535 private Service createService(String type, String schemaType) {
536 Service service = new Service();
537 service.setName(PARENT_SERVICE_ID);
539 PropertyDefinition propertyDefinition = new PropertyDefinition();
540 propertyDefinition.setName(PROPERTY_NAME);
541 propertyDefinition.setType(type);
542 if (schemaType != null) {
543 SchemaDefinition schemaDefinition = new SchemaDefinition();
544 PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
545 schemaProperty.setType(schemaType);
546 schemaDefinition.setProperty(schemaProperty);
547 propertyDefinition.setSchema(schemaDefinition);
549 service.setProperties(Collections.singletonList(propertyDefinition));
551 ComponentInstance componentInstance = new ComponentInstance();
552 componentInstance.setUniqueId(COMPONENT1_ID);
553 componentInstance.setName(COMPONENT1_ID);
555 ComponentInstance componentInstance2 = new ComponentInstance();
556 componentInstance2.setUniqueId(COMPONENT2_ID);
557 componentInstance2.setName(COMPONENT2_ID);
559 service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));
561 ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
562 componentInstanceProperty.setName(PROPERTY_NAME);
563 componentInstanceProperty.setType(type);
565 ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
566 componentInstanceProperty2.setName(PROPERTY_NAME);
567 componentInstanceProperty2.setType(type);
569 Map<String, List<ComponentInstanceProperty>> componentInstancePropertyMap = new HashMap<>();
570 componentInstancePropertyMap.put(componentInstance.getUniqueId(),
571 Collections.singletonList(componentInstanceProperty));
572 componentInstancePropertyMap.put(componentInstance2.getUniqueId(),
573 Collections.singletonList(componentInstanceProperty2));
574 componentInstancePropertyMap.put(INNER_SERVICE, Collections.singletonList(componentInstanceProperty));
576 service.setComponentInstancesProperties(componentInstancePropertyMap);
581 private static FilterConstraintDto buildFilterConstraintDto(final String propertyName, final FilterValueType valueType,
582 final ConstraintType constraintType,
583 final PropertyFilterTargetType targetType, Object value) {
584 final var filterConstraintDto = new FilterConstraintDto();
585 filterConstraintDto.setPropertyName(propertyName);
586 filterConstraintDto.setValueType(valueType);
587 filterConstraintDto.setOperator(constraintType);
588 filterConstraintDto.setTargetType(targetType);
589 filterConstraintDto.setValue(value);
590 return filterConstraintDto;