Support TOSCA functions in Node Filters
[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.Arrays;
31 import java.util.Collections;
32 import java.util.HashMap;
33 import java.util.LinkedList;
34 import java.util.List;
35 import java.util.Map;
36 import org.junit.jupiter.api.BeforeEach;
37 import org.junit.jupiter.api.Test;
38 import org.mockito.InjectMocks;
39 import org.mockito.Mock;
40 import org.mockito.Mockito;
41 import org.mockito.MockitoAnnotations;
42 import org.openecomp.sdc.be.config.ConfigurationManager;
43 import org.openecomp.sdc.be.dao.api.ActionStatus;
44 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
45 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
46 import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
47 import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
48 import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
49 import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
50 import org.openecomp.sdc.be.datatypes.enums.PropertySource;
51 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
52 import org.openecomp.sdc.be.impl.ComponentsUtils;
53 import org.openecomp.sdc.be.model.ComponentInstance;
54 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
55 import org.openecomp.sdc.be.model.PropertyDefinition;
56 import org.openecomp.sdc.be.model.Service;
57 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
58 import org.openecomp.sdc.be.model.dto.FilterConstraintDto;
59 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
60 import org.openecomp.sdc.be.model.validation.FilterConstraintValidator;
61 import org.openecomp.sdc.common.impl.ExternalConfiguration;
62 import org.openecomp.sdc.common.impl.FSConfigurationSource;
63 import org.openecomp.sdc.exception.ResponseFormat;
64
65 class NodeFilterValidatorTest {
66
67     private static final String INNER_SERVICE = "innerService";
68     private static final String PROPERTY_NAME = "Prop1";
69     private static final String COMPONENT1_ID = "component1";
70     private static final String PARENTSERVICE_ID = "parentservice";
71     private static final String COMPONENT2_ID = "component2";
72     private ComponentsUtils componentsUtils;
73
74     @Mock
75     ApplicationDataTypeCache applicationDataTypeCache;
76     @Mock
77     private FilterConstraintValidator filterConstraintValidator;
78     @InjectMocks
79     private NodeFilterValidator nodeFilterValidator;
80     private FilterConstraintDto baseFilterConstraintDto;
81
82     @BeforeEach
83     void setup() {
84         componentsUtils = Mockito.mock(ComponentsUtils.class);
85         MockitoAnnotations.openMocks(this);
86         baseFilterConstraintDto = new FilterConstraintDto();
87         baseFilterConstraintDto.setPropertyName(PROPERTY_NAME);
88         baseFilterConstraintDto.setValueType(FilterValueType.STATIC);
89         baseFilterConstraintDto.setOperator(ConstraintType.EQUAL);
90         baseFilterConstraintDto.setTargetType(PropertyFilterTargetType.PROPERTY);
91         baseFilterConstraintDto.setValue("value");
92         when(applicationDataTypeCache.getAll(any())).thenReturn(Either.left(Map.of()));
93         new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
94     }
95
96     @Test
97     void testValidateComponentInstanceExist() {
98         final ResponseFormat expectedResponse = new ResponseFormat();
99         when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, "?", INNER_SERVICE)).thenReturn(expectedResponse);
100         Either<Boolean, ResponseFormat> either =
101                 nodeFilterValidator.validateComponentInstanceExist(null, INNER_SERVICE);
102         assertTrue(either.isRight());
103         assertEquals(expectedResponse, either.right().value());
104
105         Service service = createService("booleanIncorrect");
106         when(componentsUtils.getResponseFormat(ActionStatus.COMPONENT_INSTANCE_NOT_FOUND, service.getName(), INNER_SERVICE))
107             .thenReturn(expectedResponse);
108         either = nodeFilterValidator.validateComponentInstanceExist(service, INNER_SERVICE);
109         assertTrue(either.isRight());
110         assertEquals(expectedResponse, either.right().value());
111
112         List<ComponentInstance> list = new LinkedList<>();
113         ComponentInstance instance = new ComponentInstance();
114         instance.setUniqueId("uniqueId");
115         list.add(instance);
116         service.setComponentInstances(list);
117         either = nodeFilterValidator.validateComponentInstanceExist(service, "uniqueId");
118         assertTrue(either.isLeft());
119     }
120
121     @Test
122     void testValidateNodeFilterStaticIncorrectPropertyTypeProvided() {
123         final Service service = createService("booleanIncorrect");
124         final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(PROPERTY_NAME, FilterValueType.STATIC, ConstraintType.EQUAL,
125             PropertyFilterTargetType.PROPERTY, "true");
126         Either<Boolean, ResponseFormat> either =
127                 nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
128         assertTrue(either.isRight());
129         filterConstraintDto.setTargetType(PropertyFilterTargetType.CAPABILITY);
130         either = nodeFilterValidator.validateFilter(service, INNER_SERVICE, filterConstraintDto);
131         assertTrue(either.isRight());
132     }
133
134     @Test
135     void testValidateComponentFilter() {
136         Service service = createService("integer");
137         final var filterConstraint1 = buildFilterConstraintDto(
138             PROPERTY_NAME,
139             FilterValueType.GET_PROPERTY,
140             ConstraintType.EQUAL,
141             PropertyFilterTargetType.PROPERTY,
142             createToscaGetFunction("test", PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of("test2"))
143         );
144         Either<Boolean, ResponseFormat> actualValidationResult =
145                 nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint1));
146         assertTrue(actualValidationResult.isRight());
147
148         final var filterConstraint2 = buildFilterConstraintDto(
149             PROPERTY_NAME,
150             FilterValueType.GET_PROPERTY,
151             ConstraintType.EQUAL,
152             PropertyFilterTargetType.PROPERTY,
153             createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of("Prop1"))
154         );
155         actualValidationResult =
156                 nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(filterConstraint2));
157         assertTrue(actualValidationResult.isLeft());
158
159         final var staticFilter1 = buildFilterConstraintDto(
160             PROPERTY_NAME,
161             FilterValueType.STATIC,
162             ConstraintType.EQUAL,
163             PropertyFilterTargetType.PROPERTY,
164             1
165         );
166         actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter1));
167         assertTrue(actualValidationResult.isLeft());
168         assertTrue(actualValidationResult.left().value());
169
170         final var staticFilter2 = buildFilterConstraintDto(
171             PROPERTY_NAME,
172             FilterValueType.STATIC,
173             ConstraintType.EQUAL,
174             PropertyFilterTargetType.PROPERTY,
175             "true"
176         );
177         actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter2));
178         assertTrue(actualValidationResult.isRight());
179
180         service = createService(ToscaPropertyType.BOOLEAN.getType());
181         final var staticFilter3 = buildFilterConstraintDto(
182             PROPERTY_NAME,
183             FilterValueType.STATIC,
184             ConstraintType.GREATER_THAN,
185             PropertyFilterTargetType.PROPERTY,
186             "3"
187         );
188         actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, List.of(staticFilter3));
189         assertTrue(actualValidationResult.isRight());
190
191         final var staticFilter4 = buildFilterConstraintDto(
192             "test",
193             FilterValueType.STATIC,
194             ConstraintType.GREATER_THAN,
195             PropertyFilterTargetType.PROPERTY,
196             "3"
197         );
198         actualValidationResult = nodeFilterValidator.validateSubstitutionFilter(service, Collections.singletonList(staticFilter4));
199         assertTrue(actualValidationResult.isRight());
200     }
201
202     @Test
203     void testValidateNodeFilterStaticIncorrectOperatorProvidedBoolean() {
204         Service service = createService(ToscaPropertyType.BOOLEAN.getType());
205         final FilterConstraintDto filterConstraintDto = buildFilterConstraintDto(
206             PROPERTY_NAME,
207             FilterValueType.STATIC,
208             ConstraintType.GREATER_THAN,
209             PropertyFilterTargetType.PROPERTY,
210             "true"
211         );
212         final ResponseFormat expectedResponse = new ResponseFormat();
213         when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_OPERATOR_PROVIDED, filterConstraintDto.getPropertyName(),
214             filterConstraintDto.getOperator().getType())
215         ).thenReturn(expectedResponse);
216         final Either<Boolean, ResponseFormat> validationResult =
217                 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(filterConstraintDto));
218         assertTrue(validationResult.isRight());
219         assertEquals(expectedResponse, validationResult.right().value());
220     }
221
222     @Test
223     void testValidateNodeFilterStaticIncorrectValueProvidedBoolean() {
224         final Service service = createService(ToscaPropertyType.BOOLEAN.getType());
225         baseFilterConstraintDto.setValue("trues");
226
227         final ResponseFormat responseFormat = new ResponseFormat();
228         when(componentsUtils
229             .getResponseFormat(eq(ActionStatus.UNSUPPORTED_VALUE_PROVIDED), eq(ToscaPropertyType.BOOLEAN.getType()), eq(PROPERTY_NAME), any())
230         ).thenReturn(responseFormat);
231         final Either<Boolean, ResponseFormat> validationResult =
232                 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
233
234         assertTrue(validationResult.isRight());
235         assertEquals(responseFormat, validationResult.right().value());
236     }
237
238     @Test
239     void testValidateNodeFilterStaticIncorrectOperatorProvidedString() {
240         Service service = createService(ToscaPropertyType.STRING.getType());
241         baseFilterConstraintDto.setValue("true");
242         baseFilterConstraintDto.setOperator(ConstraintType.GREATER_THAN);
243         Either<Boolean, ResponseFormat> either =
244                 nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
245
246         assertTrue(either.isLeft());
247     }
248
249     @Test
250     void testValidateNodeFilterIntegerValueSuccess() {
251         Service service = createService(ToscaPropertyType.INTEGER.getType());
252         baseFilterConstraintDto.setValue(1);
253         Either<Boolean, ResponseFormat> validationResult =
254             nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
255
256         assertTrue(validationResult.isLeft());
257     }
258
259     @Test
260     void testValidateNodeFilterIntegerValueFail() {
261         Service service = createService(ToscaPropertyType.INTEGER.getType());
262
263         baseFilterConstraintDto.setValue(1.0);
264
265         final ResponseFormat expectedResponse = new ResponseFormat();
266         when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, ToscaPropertyType.INTEGER.getType(),
267             baseFilterConstraintDto.getPropertyName(), "1.0")
268         ).thenReturn(expectedResponse);
269         Either<Boolean, ResponseFormat> validationResult =
270             nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
271
272         assertTrue(validationResult.isRight());
273         assertEquals(expectedResponse, validationResult.right().value());
274     }
275
276     @Test
277     void testValidateNodeFilterFloatValueSuccess() {
278         final Service service = createService(ToscaPropertyType.FLOAT.getType());
279         baseFilterConstraintDto.setValue(1.0);
280         final Either<Boolean, ResponseFormat> validationResult =
281             nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
282
283         assertTrue(validationResult.isLeft());
284         assertTrue(validationResult.left().value());
285     }
286
287     @Test
288     void testValidateNodeFilterFloatValueFail() {
289         Service service = createService(ToscaPropertyType.FLOAT.getType());
290
291         when(componentsUtils.getResponseFormat(ActionStatus.UNSUPPORTED_VALUE_PROVIDED, "param1")).thenReturn(new ResponseFormat());
292
293         Either<Boolean, ResponseFormat> either =
294             nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
295
296         assertTrue(either.isRight());
297     }
298
299     @Test
300     void testValidateNodeFilterStringValueSuccess() {
301         Service service = createService(ToscaPropertyType.STRING.getType());
302         Either<Boolean, ResponseFormat> either =
303             nodeFilterValidator.validateFilter(service, INNER_SERVICE, List.of(baseFilterConstraintDto));
304
305         assertTrue(either.isLeft());
306     }
307
308     @Test
309     void testValidatePropertyConstraintBrotherSuccess() {
310         Service service = createService(ToscaPropertyType.STRING.getType());
311         final ToscaGetFunctionDataDefinition toscaGetFunction =
312             createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
313         final var filterConstraintDto = buildFilterConstraintDto(
314             PROPERTY_NAME,
315             FilterValueType.GET_PROPERTY,
316             ConstraintType.EQUAL,
317             PropertyFilterTargetType.PROPERTY,
318             toscaGetFunction
319         );
320         Either<Boolean, ResponseFormat> either =
321             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
322
323         assertTrue(either.isLeft());
324         assertTrue(either.left().value());
325     }
326
327     @Test
328     void testValidatePropertyConstraintParentSuccess() {
329         final var service = createService(ToscaPropertyType.STRING.getType());
330         final ToscaGetFunctionDataDefinition toscaGetFunction =
331             createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
332         final var filterConstraintDto = buildFilterConstraintDto(
333             PROPERTY_NAME,
334             FilterValueType.GET_PROPERTY,
335             ConstraintType.EQUAL,
336             PropertyFilterTargetType.PROPERTY,
337             toscaGetFunction
338         );
339         final Either<Boolean, ResponseFormat> validationResult =
340             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
341
342         assertTrue(validationResult.isLeft());
343         assertTrue(validationResult.left().value());
344     }
345
346     @Test
347     void testValidatePropertyConstraintBrotherPropertyTypeMismatch() {
348         final Service service = createService(ToscaPropertyType.STRING.getType());
349         service.getComponentInstancesProperties().get(COMPONENT2_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
350         final ToscaGetFunctionDataDefinition toscaGetFunction =
351             createToscaGetFunction(COMPONENT2_ID, PropertySource.INSTANCE, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
352         final var filterConstraintDto = buildFilterConstraintDto(
353             PROPERTY_NAME,
354             FilterValueType.GET_PROPERTY,
355             ConstraintType.EQUAL,
356             PropertyFilterTargetType.PROPERTY,
357             toscaGetFunction
358         );
359
360         final ResponseFormat expectedResponse = new ResponseFormat();
361         when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
362             PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(), PROPERTY_NAME, ToscaPropertyType.STRING.getType())
363         ).thenReturn(expectedResponse);
364
365         final Either<Boolean, ResponseFormat> either =
366             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
367
368         assertTrue(either.isRight());
369         assertEquals(expectedResponse, either.right().value());
370     }
371
372     @Test
373     void testValidatePropertyConstraintParentPropertyTypeMismatch() {
374         final Service service = createService(ToscaPropertyType.STRING.getType());
375         service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.INTEGER.getType());
376         final ToscaGetFunctionDataDefinition toscaGetFunction =
377             createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
378         final var filterConstraintDto = buildFilterConstraintDto(
379             PROPERTY_NAME,
380             FilterValueType.GET_PROPERTY,
381             ConstraintType.EQUAL,
382             PropertyFilterTargetType.PROPERTY,
383             toscaGetFunction
384         );
385
386         final ResponseFormat expectedResponse = new ResponseFormat();
387         when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_PROPERTY_TYPE_MISMATCH,
388             PROPERTY_NAME, ToscaPropertyType.STRING.getType(), PROPERTY_NAME, ToscaPropertyType.INTEGER.getType())
389         ).thenReturn(expectedResponse);
390
391         Either<Boolean, ResponseFormat> either =
392             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
393
394         assertTrue(either.isRight());
395         assertEquals(expectedResponse, either.right().value());
396     }
397
398     @Test
399     void testValidatePropertyConstraintParentPropertyNotFound() {
400         final Service service = createService(ToscaPropertyType.STRING.getType());
401         service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
402
403         final ResponseFormat expectedResponse = new ResponseFormat();
404         when(componentsUtils.getResponseFormat(eq(ActionStatus.FILTER_PROPERTY_NOT_FOUND), any(), any()))
405             .thenReturn(expectedResponse);
406
407         final ToscaGetFunctionDataDefinition toscaGetFunction =
408             createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
409         final var filterConstraintDto = buildFilterConstraintDto(
410             PROPERTY_NAME,
411             FilterValueType.GET_PROPERTY,
412             ConstraintType.EQUAL,
413             PropertyFilterTargetType.PROPERTY,
414             toscaGetFunction
415         );
416         final Either<Boolean, ResponseFormat> validationResult =
417             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
418
419         assertTrue(validationResult.isRight());
420         assertEquals(expectedResponse, validationResult.right().value());
421     }
422
423     @Test
424     void testValidatePropertyConstraintBrotherPropertyNotFound() {
425         Service service = createService(ToscaPropertyType.STRING.getType());
426         service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setName("Prop2");
427         final ToscaGetFunctionDataDefinition toscaGetFunction =
428             createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
429         final var filterConstraintDto = buildFilterConstraintDto(
430             PROPERTY_NAME,
431             FilterValueType.GET_PROPERTY,
432             ConstraintType.EQUAL,
433             PropertyFilterTargetType.PROPERTY,
434             toscaGetFunction
435         );
436         final ResponseFormat expectedResponse = new ResponseFormat();
437         when(componentsUtils.getResponseFormat(ActionStatus.FILTER_PROPERTY_NOT_FOUND, "Target", PROPERTY_NAME))
438             .thenReturn(expectedResponse);
439         Either<Boolean, ResponseFormat> either =
440             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
441
442         assertTrue(either.isRight());
443         assertEquals(expectedResponse, either.right().value());
444     }
445
446     protected static ToscaGetFunctionDataDefinition createToscaGetFunction(final String sourceName,
447                                                                            final PropertySource propertySource,
448                                                                            final ToscaGetFunctionType toscaGetFunctionType,
449                                                                            final List<String> propertyPathFromSource) {
450         final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
451         toscaGetFunction.setFunctionType(toscaGetFunctionType);
452         toscaGetFunction.setPropertyPathFromSource(propertyPathFromSource);
453         toscaGetFunction.setSourceName(sourceName);
454         toscaGetFunction.setPropertySource(propertySource);
455         toscaGetFunction.setPropertyName(propertyPathFromSource.get(0));
456         return toscaGetFunction;
457     }
458
459     @Test
460     void testValidatePropertyConstraintParentPropertySchemaMismatch() {
461         final Service service = createService(ToscaPropertyType.LIST.getType(), ToscaPropertyType.STRING.getType());
462         service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setType(ToscaPropertyType.LIST.getType());
463         final var schemaProperty = new PropertyDataDefinition();
464         schemaProperty.setType(ToscaPropertyType.INTEGER.getType());
465         final var schemaDefinition = new SchemaDefinition();
466         schemaDefinition.setProperty(schemaProperty);
467         service.getComponentInstancesProperties().get(COMPONENT1_ID).get(0).setSchema(schemaDefinition);
468
469         final ToscaGetFunctionDataDefinition toscaGetFunction =
470             createToscaGetFunction(PARENTSERVICE_ID, PropertySource.SELF, ToscaGetFunctionType.GET_PROPERTY, List.of(PROPERTY_NAME));
471         final var filterConstraintDto = buildFilterConstraintDto(
472             PROPERTY_NAME,
473             FilterValueType.GET_PROPERTY,
474             ConstraintType.EQUAL,
475             PropertyFilterTargetType.PROPERTY,
476             toscaGetFunction
477         );
478
479         final ResponseFormat expectedResponse = new ResponseFormat();
480         when(componentsUtils.getResponseFormat(ActionStatus.SOURCE_TARGET_SCHEMA_MISMATCH, PROPERTY_NAME, ToscaPropertyType.INTEGER.getType(),
481             PROPERTY_NAME, ToscaPropertyType.STRING.getType())
482         ).thenReturn(expectedResponse);
483
484         Either<Boolean, ResponseFormat> either =
485             nodeFilterValidator.validateFilter(service, COMPONENT1_ID, List.of(filterConstraintDto));
486
487         assertTrue(either.isRight());
488         assertEquals(expectedResponse, either.right().value());
489     }
490
491     private Service createService(String type) {
492         return createService(type, null);
493     }
494
495     private Service createService(String type, String schemaType) {
496         Service service = new Service();
497         service.setName(PARENTSERVICE_ID);
498
499         PropertyDefinition propertyDefinition = new PropertyDefinition();
500         propertyDefinition.setName(PROPERTY_NAME);
501         propertyDefinition.setType(type);
502         if (schemaType != null){
503             SchemaDefinition schemaDefinition = new SchemaDefinition();
504             PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
505             schemaProperty.setType(schemaType);
506             schemaDefinition.setProperty(schemaProperty);
507             propertyDefinition.setSchema(schemaDefinition);
508         }
509         service.setProperties(Collections.singletonList(propertyDefinition));
510
511         ComponentInstance componentInstance = new ComponentInstance();
512         componentInstance.setUniqueId(COMPONENT1_ID);
513         componentInstance.setName(COMPONENT1_ID);
514
515         ComponentInstance componentInstance2 = new ComponentInstance();
516         componentInstance2.setUniqueId(COMPONENT2_ID);
517         componentInstance2.setName(COMPONENT2_ID);
518
519         service.setComponentInstances(Arrays.asList(componentInstance, componentInstance2));
520
521         ComponentInstanceProperty componentInstanceProperty  = new ComponentInstanceProperty();
522         componentInstanceProperty.setName(PROPERTY_NAME);
523         componentInstanceProperty.setType(type);
524
525         ComponentInstanceProperty componentInstanceProperty2  = new ComponentInstanceProperty();
526         componentInstanceProperty2.setName(PROPERTY_NAME);
527         componentInstanceProperty2.setType(type);
528
529         Map<String, List<ComponentInstanceProperty>> componentInstancePropertyMap = new HashMap<>();
530         componentInstancePropertyMap.put(componentInstance.getUniqueId(),
531                 Collections.singletonList(componentInstanceProperty));
532         componentInstancePropertyMap.put(componentInstance2.getUniqueId(),
533                 Collections.singletonList(componentInstanceProperty2));
534         componentInstancePropertyMap.put(INNER_SERVICE, Collections.singletonList(componentInstanceProperty));
535
536         service.setComponentInstancesProperties(componentInstancePropertyMap);
537
538         return service;
539     }
540
541     private static FilterConstraintDto buildFilterConstraintDto(final String propertyName, final FilterValueType valueType,
542                                                                 final ConstraintType constraintType,
543                                                                 final PropertyFilterTargetType targetType, Object value) {
544         final var filterConstraintDto = new FilterConstraintDto();
545         filterConstraintDto.setPropertyName(propertyName);
546         filterConstraintDto.setValueType(valueType);
547         filterConstraintDto.setOperator(constraintType);
548         filterConstraintDto.setTargetType(targetType);
549         filterConstraintDto.setValue(value);
550         return filterConstraintDto;
551     }
552
553 }