aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-be/src/test/java/org/openecomp/sdc/be/components/validation/NodeFilterValidatorTest.java
blob: ef5f7a0a8468cba703d695444fa90520bf1a4522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.be.components.validation;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;

import fj.data.Either;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
import org.openecomp.sdc.be.datatypes.enums.PropertySource;
import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.ComponentInstanceProperty;
import org.openecomp.sdc.be.model.DataTypeDefinition;
import org.openecomp.sdc.be.model.PropertyDefinition;
import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
import org.openecomp.sdc.be.model.validation.FilterConstraintValidator;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
import org.openecomp.sdc.exception.ResponseFormat;

class NodeFilterValidatorTest {

    private static final String INNER_SERVICE = "innerService";
    private static final String PROPERTY_NAME = "Prop1";
    private static final String COMPONENT1_ID = "component1";
    private static final String PARENT_SERVICE_ID = "parentservice";
    private static final String COMPONENT2_ID = "component2";
    private ComponentsUtils componentsUtils;

    @Mock
    private ApplicationDataTypeCache applicationDataTypeCache;
    @Mock
    private FilterConstraintValidator filterConstraintValidator;
    @InjectMocks
    private NodeFilterValidator nodeFilterValidator;
    private FilterConstraintDto baseFilterConstraintDto;

    @BeforeEach
    void setup() {
        componentsUtils = Mockito.mock(ComponentsUtils.class);
        MockitoAnnotations.openMocks(this);
        baseFilterConstraintDto = new FilterConstraintDto();
        baseFilterConstraintDto.setPropertyName(PROPERTY_NAME);
        baseFilterConstraintDto.setValueType(FilterValueType.STATIC);
        baseFilterConstraintDto.setOperator(ConstraintType.EQUAL);
        baseFilterConstraintDto.setTargetType(PropertyFilterTargetType.PROPERTY);
        baseFilterConstraintDto.setValue("value");
        when(applicationDataTypeCache.getAll(any())).thenReturn(Either.left(Map.of()));
        new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
    }

    @Test
    void testValidateComponentInstanceExist() {
        final ResponseFormat expectedResponse = new ResponseFormat();
        when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, "?", INNER_SERVICE)).thenReturn(expectedResponse);
        Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE);
        assertTrue(either.isRight());
        assertEquals(expectedResponse, either.right().value());

        Service service = createService("booleanIncorrect");
        when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, service.getName(), INNER_SERVICE))
            .thenReturn(expectedResponse);
        either = nodeFilterValidator.validateComponentInstanceExist(service, INNER_SERVICE);
        assertTrue(either.isRight());
        assertEquals(expectedResponse, either.right().value());

        List<ComponentInstance> list = new LinkedList<>();
        ComponentInstance instance = new ComponentInstance();
        instance.setUniqueId("uniqueId");
        list.add(instance);
        service.setComponentInstances(list);
        either = nodeFilterValidator.validateComponentInstanceExist(service, "uniqueId");
        assertTrue(either.isLeft());
    }

    @Test
    void testValidateNodeFilterStaticIncorrectPropertyTypeProvided() {
        final Service service = createService("booleanIncorrect");
        final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(PROPERTY_NAME, FilterValueType.STATIC, ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY, "true");
        Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
        assertTrue(either.isRight());
        filterConstraintDto.setTargetType(PropertyFilterTargetType.CAPABILITY);
        either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
        assertTrue(either.isRight());
    }

    @Test
    void testValidateComponentFilter() {
        Service service = createService("integer");
        final var filterConstraint1 = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            createToscaGetFunction("test", PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of("test2"), null)
        );
        Either<Boolean, ResponseFormat> actualValidationResult =
            nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
        assertTrue(actualValidationResult.isRight());

        final var filterConstraint2 = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of("Prop1"), null)
        );
        actualValidationResult =
            nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint2));
        assertTrue(actualValidationResult.isLeft());

        final var staticFilter1 = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.STATIC,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            1
        );
        actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter1));
        assertTrue(actualValidationResult.isLeft());
        assertTrue(actualValidationResult.left().value());

        final var staticFilter2 = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.STATIC,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            "true"
        );
        actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter2));
        assertTrue(actualValidationResult.isRight());

        service = createService(ToscaPropertyType.BOOLEAN.getType());
        final var staticFilter3 = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.STATIC,
            ConstraintType.GREATER_THAN,
            PropertyFilterTargetType.PROPERTY,
            "3"
        );
        actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter3));
        assertTrue(actualValidationResult.isRight());

        final var staticFilter4 = buildFilterConstraintDto(
            "test",
            FilterValueType.STATIC,
            ConstraintType.GREATER_THAN,
            PropertyFilterTargetType.PROPERTY,
            "3"
        );
        actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(staticFilter4));
        assertTrue(actualValidationResult.isRight());
    }

    @Test
    void testValidateComponentFilterWithIndex() {
        Service service = createService("string", "schema");
        final var filterConstraint1 = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            createToscaGetFunction("test", PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME, "alist"), List.of("1"))
        );
        Map<String, DataTypeDefinition> data = new HashMap<>();
        DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
        List<PropertyDefinition> properties = new ArrayList<>();
        PropertyDefinition propertyDefinition = new PropertyDefinition();
        propertyDefinition.setName("alist");
        propertyDefinition.setType("list");

        SchemaDefinition schemaDefinition = new SchemaDefinition();
        PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
        schemaProperty.setType("string");
        schemaDefinition.setProperty(schemaProperty);
        propertyDefinition.setSchema(schemaDefinition);

        properties.add(propertyDefinition);
        dataTypeDefinition.setProperties(properties);

        data.put("string", dataTypeDefinition);
        Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> allDataTypes = Either.left(data);
        when(applicationDataTypeCache.getAll(null)).thenReturn(allDataTypes);

        Either<Boolean, ResponseFormat> actualValidationResult =
            nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
        assertTrue(actualValidationResult.isLeft());
    }

    @Test
    void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
        Service service = createService(ToscaPropertyType.BOOLEAN.getType());
        final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.STATIC,
            ConstraintType.GREATER_THAN,
            PropertyFilterTargetType.PROPERTY,
            "true"
        );
        final ResponseFormat expectedResponse = new ResponseFormat();
        when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.BOOLEAN.getType(),
            filterConstraintDto.getPropertyName(), "\"true\"")
        ).thenReturn(expectedResponse);
        final Either<Boolean, ResponseFormat> validationResult =
            nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(filterConstraintDto));
        assertTrue(validationResult.isRight());
        assertEquals(expectedResponse, validationResult.right().value());
    }

    @Test
    void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
        final Service service = createService(ToscaPropertyType.BOOLEAN.getType());
        baseFilterConstraintDto.setValue("trues");

        final ResponseFormat responseFormat = new ResponseFormat();
        when(componentsUtils.getResponseFormat
            (ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.BOOLEAN.getType(), PROPERTY_NAME, "\"trues\"")
        ).thenReturn(responseFormat);
        final Either<Boolean, ResponseFormat> validationResult =
            nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));

        assertTrue(validationResult.isRight());
        assertEquals(responseFormat, validationResult.right().value());
    }

    @Test
    void testValidateNodeFilterStaticIncorrectOperatorProvidedString() {
        Service service = createService(ToscaPropertyType.STRING.getType());
        baseFilterConstraintDto.setValue("true");
        baseFilterConstraintDto.setOperator(ConstraintType.GREATER_THAN);
        Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));

        assertTrue(either.isLeft());
    }

    @Test
    void testValidateNodeFilterIntegerValueSuccess() {
        Service service = createService(ToscaPropertyType.INTEGER.getType());
        baseFilterConstraintDto.setValue(1);
        Either<Boolean, ResponseFormat> validationResult =
            nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));

        assertTrue(validationResult.isLeft());
    }

    @Test
    void testValidateNodeFilterIntegerValueFail() {
        Service service = createService(ToscaPropertyType.INTEGER.getType());

        baseFilterConstraintDto.setValue(1.0);

        final ResponseFormat expectedResponse = new ResponseFormat();
        when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.INTEGER.getType(),
            baseFilterConstraintDto.getPropertyName(), "1.0")
        ).thenReturn(expectedResponse);
        Either<Boolean, ResponseFormat> validationResult =
            nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));

        assertTrue(validationResult.isRight());
        assertEquals(expectedResponse, validationResult.right().value());
    }

    @Test
    void testValidateNodeFilterFloatValueSuccess() {
        final Service service = createService(ToscaPropertyType.FLOAT.getType());
        baseFilterConstraintDto.setValue(1.0);
        final Either<Boolean, ResponseFormat> validationResult =
            nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));

        assertTrue(validationResult.isLeft());
        assertTrue(validationResult.left().value());
    }

    @Test
    void testValidateNodeFilterFloatValueFail() {
        Service service = createService(ToscaPropertyType.FLOAT.getType());

        when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1")).thenReturn(new ResponseFormat());

        Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));

        assertTrue(either.isRight());
    }

    @Test
    void testValidateNodeFilterStringValueSuccess() {
        Service service = createService(ToscaPropertyType.STRING.getType());
        Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));

        assertTrue(either.isLeft());
    }

    @Test
    void testValidatePropertyConstraintBrotherSuccess() {
        Service service = createService(ToscaPropertyType.STRING.getType());
        final ToscaGetFunctionDataDefinition toscaGetFunction =
            createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
        final var filterConstraintDto = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            toscaGetFunction
        );
        Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));

        assertTrue(either.isLeft());
        assertTrue(either.left().value());
    }

    @Test
    void testValidatePropertyConstraintParentSuccess() {
        final var service = createService(ToscaPropertyType.STRING.getType());
        final ToscaGetFunctionDataDefinition toscaGetFunction =
            createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
        final var filterConstraintDto = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            toscaGetFunction
        );
        final Either<Boolean, ResponseFormat> validationResult =
            nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));

        assertTrue(validationResult.isLeft());
        assertTrue(validationResult.left().value());
    }

    @Test
    void testValidatePropertyConstraintBrotherPropertyTypeMismatch() {
        final Service service = createService(ToscaPropertyType.STRING.getType());
        service.getComponentInstancesProperties().get(COMPONENT2_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
        final ToscaGetFunctionDataDefinition toscaGetFunction =
            createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
        final var filterConstraintDto = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            toscaGetFunction
        );

        final ResponseFormat expectedResponse = new ResponseFormat();
        when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
            PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(), PROPERTY_NAME, ToscaPropertyType.STRING.getType())
        ).thenReturn(expectedResponse);

        final Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));

        assertTrue(either.isRight());
        assertEquals(expectedResponse, either.right().value());
    }

    @Test
    void testValidatePropertyConstraintParentPropertyTypeMismatch() {
        final Service service = createService(ToscaPropertyType.STRING.getType());
        service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
        final ToscaGetFunctionDataDefinition toscaGetFunction =
            createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
        final var filterConstraintDto = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            toscaGetFunction
        );

        final ResponseFormat expectedResponse = new ResponseFormat();
        when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
            PROPERTY_NAME, ToscaPropertyType.STRING.getType(), PROPERTY_NAME, ToscaPropertyType.INTEGER.getType())
        ).thenReturn(expectedResponse);

        Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));

        assertTrue(either.isRight());
        assertEquals(expectedResponse, either.right().value());
    }

    @Test
    void testValidatePropertyConstraintParentPropertyNotFound() {
        final Service service = createService(ToscaPropertyType.STRING.getType());
        service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");

        final ResponseFormat expectedResponse = new ResponseFormat();
        when(componentsUtils.getResponseFormat(eq(ActionStatus.FILTER_PROPERTY_NOT_FOUND), any(), any()))
            .thenReturn(expectedResponse);

        final ToscaGetFunctionDataDefinition toscaGetFunction =
            createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
        final var filterConstraintDto = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            toscaGetFunction
        );
        final Either<Boolean, ResponseFormat> validationResult =
            nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));

        assertTrue(validationResult.isRight());
        assertEquals(expectedResponse, validationResult.right().value());
    }

    @Test
    void testValidatePropertyConstraintBrotherPropertyNotFound() {
        Service service = createService(ToscaPropertyType.STRING.getType());
        service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
        final ToscaGetFunctionDataDefinition toscaGetFunction =
            createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
        final var filterConstraintDto = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            toscaGetFunction
        );
        final ResponseFormat expectedResponse = new ResponseFormat();
        when(componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, "Target", PROPERTY_NAME))
            .thenReturn(expectedResponse);
        Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));

        assertTrue(either.isRight());
        assertEquals(expectedResponse, either.right().value());
    }

    protected static ToscaGetFunctionDataDefinition createToscaGetFunction(final String sourceName,
                                                                           final PropertySource propertySource,
                                                                           final ToscaGetFunctionType toscaGetFunctionType,
                                                                           final List<String> propertyPathFromSource,
                                                                           final List<Object> toscaIndexList) {
        final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
        toscaGetFunction.setFunctionType(toscaGetFunctionType);
        toscaGetFunction.setPropertyPathFromSource(propertyPathFromSource);
        toscaGetFunction.setSourceName(sourceName);
        toscaGetFunction.setPropertySource(propertySource);
        toscaGetFunction.setPropertyName(propertyPathFromSource.get(0));
        toscaGetFunction.setToscaIndexList(toscaIndexList);
        return toscaGetFunction;
    }

    @Test
    void testValidatePropertyConstraintParentPropertySchemaMismatch() {
        final Service service = createService(ToscaPropertyType.LIST.getType(), ToscaPropertyType.STRING.getType());
        service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.LIST.getType());
        final var schemaProperty = new PropertyDataDefinition();
        schemaProperty.setType(ToscaPropertyType.INTEGER.getType());
        final var schemaDefinition = new SchemaDefinition();
        schemaDefinition.setProperty(schemaProperty);
        service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setSchema(schemaDefinition);

        final ToscaGetFunctionDataDefinition toscaGetFunction =
            createToscaGetFunction(PARENT_SERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME), null);
        final var filterConstraintDto = buildFilterConstraintDto(
            PROPERTY_NAME,
            FilterValueType.GET_PROPERTY,
            ConstraintType.EQUAL,
            PropertyFilterTargetType.PROPERTY,
            toscaGetFunction
        );

        final ResponseFormat expectedResponse = new ResponseFormat();
        when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH, PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(),
            PROPERTY_NAME, ToscaPropertyType.STRING.getType())
        ).thenReturn(expectedResponse);

        Either<Boolean, ResponseFormat> either =
            nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));

        assertTrue(either.isRight());
        assertEquals(expectedResponse, either.right().value());
    }

    private Service createService(String type) {
        return createService(type, null);
    }

    private Service createService(String type, String schemaType) {
        Service service = new Service();
        service.setName(PARENT_SERVICE_ID);

        PropertyDefinition propertyDefinition = new PropertyDefinition();
        propertyDefinition.setName(PROPERTY_NAME);
        propertyDefinition.setType(type);
        if (schemaType != null) {
            SchemaDefinition schemaDefinition = new SchemaDefinition();
            PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
            schemaProperty.setType(schemaType);
            schemaDefinition.setProperty(schemaProperty);
            propertyDefinition.setSchema(schemaDefinition);
        }
        service.setProperties(Collections.singletonList(propertyDefinition));

        ComponentInstance componentInstance = new ComponentInstance();
        componentInstance.setUniqueId(COMPONENT1_ID);
        componentInstance.setName(COMPONENT1_ID);

        ComponentInstance componentInstance2 = new ComponentInstance();
        componentInstance2.setUniqueId(COMPONENT2_ID);
        componentInstance2.setName(COMPONENT2_ID);

        service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));

        ComponentInstanceProperty componentInstanceProperty = new ComponentInstanceProperty();
        componentInstanceProperty.setName(PROPERTY_NAME);
        componentInstanceProperty.setType(type);

        ComponentInstanceProperty componentInstanceProperty2 = new ComponentInstanceProperty();
        componentInstanceProperty2.setName(PROPERTY_NAME);
        componentInstanceProperty2.setType(type);

        Map<String, List<ComponentInstanceProperty>> componentInstancePropertyMap = new HashMap<>();
        componentInstancePropertyMap.put(componentInstance.getUniqueId(),
            Collections.singletonList(componentInstanceProperty));
        componentInstancePropertyMap.put(componentInstance2.getUniqueId(),
            Collections.singletonList(componentInstanceProperty2));
        componentInstancePropertyMap.put(INNER_SERVICE, Collections.singletonList(componentInstanceProperty));

        service.setComponentInstancesProperties(componentInstancePropertyMap);

        return service;
    }

    private static FilterConstraintDto buildFilterConstraintDto(final String propertyName, final FilterValueType valueType,
                                                                final ConstraintType constraintType,
                                                                final PropertyFilterTargetType targetType, Object value) {
        final var filterConstraintDto = new FilterConstraintDto();
        filterConstraintDto.setPropertyName(propertyName);
        filterConstraintDto.setValueType(valueType);
        filterConstraintDto.setOperator(constraintType);
        filterConstraintDto.setTargetType(targetType);
        filterConstraintDto.setValue(value);
        return filterConstraintDto;
    }

}