ef5f7a0a8468cba703d695444fa90520bf1a4522
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / validation / NodeFilterValidatorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.components.validation;
22
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;
28
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;
36 import java.util.Map;
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;
67
68 class NodeFilterValidatorTest {
69
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;
76
77     @Mock
78     private ApplicationDataTypeCache applicationDataTypeCache;
79     @Mock
80     private FilterConstraintValidator filterConstraintValidator;
81     @InjectMocks
82     private NodeFilterValidator nodeFilterValidator;
83     private FilterConstraintDto baseFilterConstraintDto;
84
85     @BeforeEach
86     void setup() {
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"));
97     }
98
99     @Test
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());
107
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());
114
115         List<ComponentInstance> list = new LinkedList<>();
116         ComponentInstance instance = new ComponentInstance();
117         instance.setUniqueId("uniqueId");
118         list.add(instance);
119         service.setComponentInstances(list);
120         either = nodeFilterValidator.validateComponentInstanceExist(service, "uniqueId");
121         assertTrue(either.isLeft());
122     }
123
124     @Test
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());
135     }
136
137     @Test
138     void testValidateComponentFilter() {
139         Service service = createService("integer");
140         final var filterConstraint1 = buildFilterConstraintDto(
141             PROPERTY_NAME,
142             FilterValueType.GET_PROPERTY,
143             ConstraintType.EQUAL,
144             PropertyFilterTargetType.PROPERTY,
145             createToscaGetFunction("test", PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of("test2"), null)
146         );
147         Either<Boolean, ResponseFormat> actualValidationResult =
148             nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
149         assertTrue(actualValidationResult.isRight());
150
151         final var filterConstraint2 = buildFilterConstraintDto(
152             PROPERTY_NAME,
153             FilterValueType.GET_PROPERTY,
154             ConstraintType.EQUAL,
155             PropertyFilterTargetType.PROPERTY,
156             createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of("Prop1"), null)
157         );
158         actualValidationResult =
159             nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint2));
160         assertTrue(actualValidationResult.isLeft());
161
162         final var staticFilter1 = buildFilterConstraintDto(
163             PROPERTY_NAME,
164             FilterValueType.STATIC,
165             ConstraintType.EQUAL,
166             PropertyFilterTargetType.PROPERTY,
167             1
168         );
169         actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter1));
170         assertTrue(actualValidationResult.isLeft());
171         assertTrue(actualValidationResult.left().value());
172
173         final var staticFilter2 = buildFilterConstraintDto(
174             PROPERTY_NAME,
175             FilterValueType.STATIC,
176             ConstraintType.EQUAL,
177             PropertyFilterTargetType.PROPERTY,
178             "true"
179         );
180         actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter2));
181         assertTrue(actualValidationResult.isRight());
182
183         service = createService(ToscaPropertyType.BOOLEAN.getType());
184         final var staticFilter3 = buildFilterConstraintDto(
185             PROPERTY_NAME,
186             FilterValueType.STATIC,
187             ConstraintType.GREATER_THAN,
188             PropertyFilterTargetType.PROPERTY,
189             "3"
190         );
191         actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter3));
192         assertTrue(actualValidationResult.isRight());
193
194         final var staticFilter4 = buildFilterConstraintDto(
195             "test",
196             FilterValueType.STATIC,
197             ConstraintType.GREATER_THAN,
198             PropertyFilterTargetType.PROPERTY,
199             "3"
200         );
201         actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(staticFilter4));
202         assertTrue(actualValidationResult.isRight());
203     }
204
205     @Test
206     void testValidateComponentFilterWithIndex() {
207         Service service = createService("string", "schema");
208         final var filterConstraint1 = buildFilterConstraintDto(
209             PROPERTY_NAME,
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"))
214         );
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");
221
222         SchemaDefinition schemaDefinition = new SchemaDefinition();
223         PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
224         schemaProperty.setType("string");
225         schemaDefinition.setProperty(schemaProperty);
226         propertyDefinition.setSchema(schemaDefinition);
227
228         properties.add(propertyDefinition);
229         dataTypeDefinition.setProperties(properties);
230
231         data.put("string", dataTypeDefinition);
232         Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = Either.left(data);
233         when(applicationDataTypeCache.getAll(null)).thenReturn(allDataTypes);
234
235         Either<Boolean, ResponseFormat> actualValidationResult =
236             nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
237         assertTrue(actualValidationResult.isLeft());
238     }
239
240     @Test
241     void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
242         Service service = createService(ToscaPropertyType.BOOLEAN.getType());
243         final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(
244             PROPERTY_NAME,
245             FilterValueType.STATIC,
246             ConstraintType.GREATER_THAN,
247             PropertyFilterTargetType.PROPERTY,
248             "true"
249         );
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());
258     }
259
260     @Test
261     void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
262         final Service service = createService(ToscaPropertyType.BOOLEAN.getType());
263         baseFilterConstraintDto.setValue("trues");
264
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));
271
272         assertTrue(validationResult.isRight());
273         assertEquals(responseFormat, validationResult.right().value());
274     }
275
276     @Test
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));
283
284         assertTrue(either.isLeft());
285     }
286
287     @Test
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));
293
294         assertTrue(validationResult.isLeft());
295     }
296
297     @Test
298     void testValidateNodeFilterIntegerValueFail() {
299         Service service = createService(ToscaPropertyType.INTEGER.getType());
300
301         baseFilterConstraintDto.setValue(1.0);
302
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));
309
310         assertTrue(validationResult.isRight());
311         assertEquals(expectedResponse, validationResult.right().value());
312     }
313
314     @Test
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));
320
321         assertTrue(validationResult.isLeft());
322         assertTrue(validationResult.left().value());
323     }
324
325     @Test
326     void testValidateNodeFilterFloatValueFail() {
327         Service service = createService(ToscaPropertyType.FLOAT.getType());
328
329         when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1")).thenReturn(new ResponseFormat());
330
331         Either<Boolean, ResponseFormat> either =
332             nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
333
334         assertTrue(either.isRight());
335     }
336
337     @Test
338     void testValidateNodeFilterStringValueSuccess() {
339         Service service = createService(ToscaPropertyType.STRING.getType());
340         Either<Boolean, ResponseFormat> either =
341             nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
342
343         assertTrue(either.isLeft());
344     }
345
346     @Test
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(
352             PROPERTY_NAME,
353             FilterValueType.GET_PROPERTY,
354             ConstraintType.EQUAL,
355             PropertyFilterTargetType.PROPERTY,
356             toscaGetFunction
357         );
358         Either<Boolean, ResponseFormat> either =
359             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
360
361         assertTrue(either.isLeft());
362         assertTrue(either.left().value());
363     }
364
365     @Test
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(
371             PROPERTY_NAME,
372             FilterValueType.GET_PROPERTY,
373             ConstraintType.EQUAL,
374             PropertyFilterTargetType.PROPERTY,
375             toscaGetFunction
376         );
377         final Either<Boolean, ResponseFormat> validationResult =
378             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
379
380         assertTrue(validationResult.isLeft());
381         assertTrue(validationResult.left().value());
382     }
383
384     @Test
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(
391             PROPERTY_NAME,
392             FilterValueType.GET_PROPERTY,
393             ConstraintType.EQUAL,
394             PropertyFilterTargetType.PROPERTY,
395             toscaGetFunction
396         );
397
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);
402
403         final Either<Boolean, ResponseFormat> either =
404             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
405
406         assertTrue(either.isRight());
407         assertEquals(expectedResponse, either.right().value());
408     }
409
410     @Test
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(
417             PROPERTY_NAME,
418             FilterValueType.GET_PROPERTY,
419             ConstraintType.EQUAL,
420             PropertyFilterTargetType.PROPERTY,
421             toscaGetFunction
422         );
423
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);
428
429         Either<Boolean, ResponseFormat> either =
430             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
431
432         assertTrue(either.isRight());
433         assertEquals(expectedResponse, either.right().value());
434     }
435
436     @Test
437     void testValidatePropertyConstraintParentPropertyNotFound() {
438         final Service service = createService(ToscaPropertyType.STRING.getType());
439         service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
440
441         final ResponseFormat expectedResponse = new ResponseFormat();
442         when(componentsUtils.getResponseFormat(eq(ActionStatus.FILTER_PROPERTY_NOT_FOUND), any(), any()))
443             .thenReturn(expectedResponse);
444
445         final ToscaGetFunctionDataDefinition toscaGetFunction =
446             createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
447         final var filterConstraintDto = buildFilterConstraintDto(
448             PROPERTY_NAME,
449             FilterValueType.GET_PROPERTY,
450             ConstraintType.EQUAL,
451             PropertyFilterTargetType.PROPERTY,
452             toscaGetFunction
453         );
454         final Either<Boolean, ResponseFormat> validationResult =
455             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
456
457         assertTrue(validationResult.isRight());
458         assertEquals(expectedResponse, validationResult.right().value());
459     }
460
461     @Test
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(
468             PROPERTY_NAME,
469             FilterValueType.GET_PROPERTY,
470             ConstraintType.EQUAL,
471             PropertyFilterTargetType.PROPERTY,
472             toscaGetFunction
473         );
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));
479
480         assertTrue(either.isRight());
481         assertEquals(expectedResponse, either.right().value());
482     }
483
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;
497     }
498
499     @Test
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);
508
509         final ToscaGetFunctionDataDefinition toscaGetFunction =
510             createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
511         final var filterConstraintDto = buildFilterConstraintDto(
512             PROPERTY_NAME,
513             FilterValueType.GET_PROPERTY,
514             ConstraintType.EQUAL,
515             PropertyFilterTargetType.PROPERTY,
516             toscaGetFunction
517         );
518
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);
523
524         Either<Boolean, ResponseFormat> either =
525             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
526
527         assertTrue(either.isRight());
528         assertEquals(expectedResponse, either.right().value());
529     }
530
531     private Service createService(String type) {
532         return createService(type, null);
533     }
534
535     private Service createService(String type, String schemaType) {
536         Service service = new Service();
537         service.setName(PARENT_SERVICE_ID);
538
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);
548         }
549         service.setProperties(Collections.singletonList(propertyDefinition));
550
551         ComponentInstance componentInstance = new ComponentInstance();
552         componentInstance.setUniqueId(COMPONENT1_ID);
553         componentInstance.setName(COMPONENT1_ID);
554
555         ComponentInstance componentInstance2 = new ComponentInstance();
556         componentInstance2.setUniqueId(COMPONENT2_ID);
557         componentInstance2.setName(COMPONENT2_ID);
558
559         service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));
560
561         ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
562         componentInstanceProperty.setName(PROPERTY_NAME);
563         componentInstanceProperty.setType(type);
564
565         ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
566         componentInstanceProperty2.setName(PROPERTY_NAME);
567         componentInstanceProperty2.setType(type);
568
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));
575
576         service.setComponentInstancesProperties(componentInstancePropertyMap);
577
578         return service;
579     }
580
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;
591     }
592
593 }