Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / nodeFilter / BaseServiceFilterUtilsTest.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 org.junit.Assert;
20 import org.junit.Before;
21 import org.openecomp.sdc.be.components.impl.utils.DirectivesUtils;
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.RequirementNodeFilterPropertyDataDefinition;
25 import org.openecomp.sdc.be.model.ComponentInstance;
26 import org.openecomp.sdc.be.model.PropertyDefinition;
27 import org.openecomp.sdc.be.model.Service;
28
29 import java.util.Arrays;
30
31 public class BaseServiceFilterUtilsTest {
32
33     protected Service service;
34     protected RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition;
35     protected RequirementNodeFilterPropertyDataDefinition requirementNodeFilterPropertyDataDefinition2;
36     protected static final String CI_NAME = "AAAAAA";
37     protected static final String A_PROP_NAME = "A_PROP";
38     protected static final String SIZE_PROP = "size";
39     protected static final String ORIG_COMP_INSTANCE_ID = "54355645457457";
40
41     @Before
42     public void initService() {
43         try {
44             service = new Service();
45             ComponentInstance componentInstance = new ComponentInstance();
46             componentInstance.setUniqueId(CI_NAME);
47             componentInstance.setName(CI_NAME);
48             service.setComponentInstances(Arrays.asList(componentInstance));
49             componentInstance.setDirectives(Arrays.asList(DirectivesUtils.SELECTABLE));
50             CINodeFilterDataDefinition serviceFilter = new CINodeFilterDataDefinition();
51             componentInstance.setNodeFilter(serviceFilter);
52             requirementNodeFilterPropertyDataDefinition = new RequirementNodeFilterPropertyDataDefinition();
53             requirementNodeFilterPropertyDataDefinition.setName("Name1");
54             requirementNodeFilterPropertyDataDefinition
55                     .setConstraints(Arrays.asList("mem_size:\n" + "  equal: { get_property : [" + CI_NAME + ", size]}\n"));
56             requirementNodeFilterPropertyDataDefinition2 = new RequirementNodeFilterPropertyDataDefinition();
57             requirementNodeFilterPropertyDataDefinition2.setName("Name2");
58             requirementNodeFilterPropertyDataDefinition2
59                     .setConstraints(Arrays.asList("mem_size:\n {equal:  { get_property : [SELF, "+A_PROP_NAME+"]}}\n"));
60
61             ListDataDefinition<RequirementNodeFilterPropertyDataDefinition> listDataDefinition =
62                     new ListDataDefinition<>(Arrays.asList(
63                             requirementNodeFilterPropertyDataDefinition,
64                             requirementNodeFilterPropertyDataDefinition2));
65             serviceFilter.setProperties(listDataDefinition);
66             PropertyDefinition property = new PropertyDefinition();
67             property.setName(A_PROP_NAME);
68             service.setProperties(Arrays.asList(property));
69         } catch (Exception e) {
70             Assert.fail(e.getMessage());
71         }
72     }
73
74 }