2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.be.nodeFilter;
19 import java.util.List;
20 import org.junit.jupiter.api.BeforeEach;
21 import org.openecomp.sdc.be.config.ConfigurationManager;
22 import org.openecomp.sdc.be.datatypes.elements.CINodeFilterDataDefinition;
23 import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
24 import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
25 import org.openecomp.sdc.be.datatypes.elements.PropertyFilterDataDefinition;
26 import org.openecomp.sdc.be.datatypes.elements.ToscaGetFunctionDataDefinition;
27 import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
28 import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
29 import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
30 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
31 import org.openecomp.sdc.be.model.ComponentInstance;
32 import org.openecomp.sdc.be.model.PropertyDefinition;
33 import org.openecomp.sdc.be.model.Service;
34 import org.openecomp.sdc.common.impl.ExternalConfiguration;
35 import org.openecomp.sdc.common.impl.FSConfigurationSource;
37 public class BaseServiceFilterUtilsTest {
39 protected Service service;
40 protected PropertyFilterDataDefinition propertyFilterDataDefinition;
41 protected PropertyFilterDataDefinition propertyFilterDataDefinition2;
42 protected static final String CI_NAME = "AAAAAA";
43 protected static final String A_PROP_NAME = "A_PROP";
44 protected static final String SIZE_PROP = "size";
48 new ConfigurationManager(new FSConfigurationSource(ExternalConfiguration.getChangeListener(), "src/test/resources/config/catalog-be"));
49 service = new Service();
50 ComponentInstance componentInstance = new ComponentInstance();
51 componentInstance.setUniqueId(CI_NAME);
52 componentInstance.setName(CI_NAME);
53 service.setComponentInstances(List.of(componentInstance));
54 componentInstance.setDirectives(ConfigurationManager.getConfigurationManager().getConfiguration()
56 CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition();
57 componentInstance.setNodeFilter(serviceFilter);
58 propertyFilterDataDefinition = new PropertyFilterDataDefinition();
59 propertyFilterDataDefinition.setName("Name1");
60 final var propertyFilterConstraint1 = new PropertyFilterConstraintDataDefinition();
61 propertyFilterConstraint1.setPropertyName("mem_size");
62 propertyFilterConstraint1.setOperator(ConstraintType.EQUAL);
63 propertyFilterConstraint1.setValue(createToscaGetFunction(CI_NAME, ToscaGetFunctionType.GET_PROPERTY, List.of("size")));
64 propertyFilterConstraint1.setValueType(FilterValueType.GET_PROPERTY);
65 propertyFilterConstraint1.setTargetType(PropertyFilterTargetType.PROPERTY);
66 propertyFilterDataDefinition.setConstraints(List.of(propertyFilterConstraint1));
67 propertyFilterDataDefinition2 = new PropertyFilterDataDefinition();
68 propertyFilterDataDefinition2.setName("Name2");
69 final var propertyFilterConstraint2 = new PropertyFilterConstraintDataDefinition();
70 propertyFilterConstraint2.setPropertyName("mem_size");
71 propertyFilterConstraint2.setOperator(ConstraintType.EQUAL);
72 propertyFilterConstraint2.setValue(createToscaGetFunction("SELF", ToscaGetFunctionType.GET_PROPERTY, List.of(A_PROP_NAME)));
73 propertyFilterConstraint2.setValueType(FilterValueType.GET_PROPERTY);
74 propertyFilterConstraint2.setTargetType(PropertyFilterTargetType.PROPERTY);
75 propertyFilterDataDefinition2.setConstraints(List.of(propertyFilterConstraint2));
77 ListDataDefinition<PropertyFilterDataDefinition> listDataDefinition =
78 new ListDataDefinition<>(List.of(propertyFilterDataDefinition, propertyFilterDataDefinition2));
79 serviceFilter.setProperties(listDataDefinition);
80 PropertyDefinition property = new PropertyDefinition();
81 property.setName(A_PROP_NAME);
82 service.setProperties(List.of(property));
85 protected static ToscaGetFunctionDataDefinition createToscaGetFunction(final String sourceName,
86 final ToscaGetFunctionType toscaGetFunctionType,
87 final List<String> propertyPathFromSource) {
88 final var toscaGetFunction = new ToscaGetFunctionDataDefinition();
89 toscaGetFunction.setFunctionType(toscaGetFunctionType);
90 toscaGetFunction.setPropertyPathFromSource(propertyPathFromSource);
91 toscaGetFunction.setSourceName(sourceName);
92 toscaGetFunction.setPropertyName(propertyPathFromSource.get(0));
93 return toscaGetFunction;