Catalog alignment
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / property / PropertyDeceleratorTestBase.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.property;
22
23 import org.junit.Before;
24 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
25 import org.openecomp.sdc.be.dao.utils.MapUtil;
26 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
27 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
28 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
29 import org.openecomp.sdc.be.model.InputDefinition;
30
31 import java.util.List;
32 import java.util.Map;
33 import java.util.stream.Collectors;
34
35 import static org.assertj.core.api.Assertions.assertThat;
36 import static org.openecomp.sdc.common.api.Constants.GET_INPUT;
37
38 public class PropertyDeceleratorTestBase {
39
40     static final String INNER_PROP1 = "ecomp_generated_naming";
41     static final String INNER_PROP2 = "naming_policy";
42     PropertyDataDefinition prop1, prop2, complexProperty;
43
44     @Before
45     public void setUp() throws Exception {
46         prop1 = new PropertyDataDefinitionBuilder()
47                 .setUniqueId("prop1")
48                 .setType("string")
49                 .setName("prop1")
50                 .setValue("value1")
51                 .build();
52
53         prop2 = new PropertyDataDefinitionBuilder()
54                 .setUniqueId("prop2")
55                 .setType("string")
56                 .setSchemaType("string")
57                 .setName("prop2")
58                 .setValue("[\"a\", \"b\"]")
59                 .build();
60
61         complexProperty = new PropertyDataDefinitionBuilder()
62                 .setUniqueId("prop3")
63                 .setType("org.openecomp.type1")
64                 .setName("prop3")
65                 .setValue("{\"ecomp_generated_naming\":true\",\"naming_policy\":\"abc\"}")
66                 .build();
67
68     }
69
70     List<ComponentInstancePropInput> createInstancePropInputList(List<PropertyDataDefinition> properties) {
71         return properties.stream().map(prop -> new ComponentInstancePropInput(new ComponentInstanceProperty(prop)))
72                 .collect(Collectors.toList());
73     }
74
75     void verifyInputPropertiesList(List<InputDefinition> createdInputs, List<PropertyDataDefinition> capturedUpdatedProperties) {
76         Map<String, InputDefinition> propertyIdToCreatedInput = MapUtil.toMap(createdInputs, InputDefinition::getPropertyId);
77         capturedUpdatedProperties.forEach(updatedProperty -> verifyInputPropertiesList(updatedProperty, propertyIdToCreatedInput.get(updatedProperty.getUniqueId())));
78     }
79
80     String generateGetInputValue(String value) {
81         return String.format("{\"%s\":\"%s\"}", GET_INPUT, value);
82     }
83
84     private void verifyInputPropertiesList(PropertyDataDefinition updatedProperty, InputDefinition input) {
85         assertThat(input.getProperties()).hasSize(1);
86         assertThat(new ComponentInstanceProperty(updatedProperty)).isEqualTo(input.getProperties().get(0));
87     }
88
89 }