Support TOSCA functions in Node Filters
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / nodeFilter / ServiceFilterUtilsServiceInputTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.be.nodeFilter;
18
19 import static org.junit.jupiter.api.Assertions.assertNotNull;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import java.util.List;
23 import java.util.Set;
24 import org.junit.jupiter.api.Test;
25 import org.openecomp.sdc.be.datatypes.elements.PropertyFilterConstraintDataDefinition;
26 import org.openecomp.sdc.be.datatypes.enums.ConstraintType;
27 import org.openecomp.sdc.be.datatypes.enums.FilterValueType;
28 import org.openecomp.sdc.be.datatypes.enums.PropertyFilterTargetType;
29 import org.openecomp.sdc.be.datatypes.enums.PropertySource;
30 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
31 import org.openecomp.sdc.be.impl.ServiceFilterUtils;
32 import org.openecomp.sdc.be.model.InputDefinition;
33
34 class ServiceFilterUtilsServiceInputTest extends BaseServiceFilterUtilsTest {
35
36     private static final String CONSTRAINT_NAME = "InputName";
37
38     @Test
39     void checkInputStreamIsFound() {
40         Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CONSTRAINT_NAME);
41         assertNotNull(nodesFiltersToBeDeleted);
42         assertTrue(nodesFiltersToBeDeleted.contains(CI_NAME));
43     }
44
45     private Set<String> getNodeFiltersToBeDeleted(String constraintName) {
46         final var propertyFilterConstraint = new PropertyFilterConstraintDataDefinition();
47         propertyFilterConstraint.setPropertyName("mem_size");
48         propertyFilterConstraint.setOperator(ConstraintType.EQUAL);
49
50         propertyFilterConstraint.setValue(
51             createToscaGetFunction(PropertySource.SELF.getName(), ToscaGetFunctionType.GET_INPUT, List.of(CONSTRAINT_NAME))
52         );
53         propertyFilterConstraint.setValueType(FilterValueType.GET_INPUT);
54         propertyFilterConstraint.setTargetType(PropertyFilterTargetType.PROPERTY);
55         propertyFilterDataDefinition.setConstraints(List.of(propertyFilterConstraint));
56         InputDefinition inputDefinition = new InputDefinition();
57         inputDefinition.setName(constraintName);
58         return ServiceFilterUtils.getNodesFiltersToBeDeleted(service, inputDefinition);
59     }
60
61     @Test
62     public void checkInputStreamIsNotFound() {
63         Set<String> nodesFiltersToBeDeleted = getNodeFiltersToBeDeleted(CONSTRAINT_NAME + " aaa bbb");
64         assertNotNull(nodesFiltersToBeDeleted);
65         assertTrue(nodesFiltersToBeDeleted.isEmpty());
66     }
67 }