Added oparent to sdc main
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / property / PropertyDeclaratorTestBase.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.ComponentInstanceBuilder;
25 import org.openecomp.sdc.be.components.utils.PropertyDataDefinitionBuilder;
26 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
27 import org.openecomp.sdc.be.dao.utils.MapUtil;
28 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
29 import org.openecomp.sdc.be.model.*;
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 PropertyDeclaratorTestBase {
39
40     static final String INNER_PROP1 = "ecomp_generated_naming";
41     static final String INNER_PROP2 = "naming_policy";
42     static final String RESOURCE_ID = "resourceId";
43     static final String INPUT_ID = "inputId";
44     static final String INSTANCE_ID = "inst1";
45     static final String ORIGIN_INSTANCE_ID = "originInst1";
46     PropertyDataDefinition prop1, prop2, complexProperty;
47     Resource resource;
48
49     @Before
50     public void setUp() throws Exception {
51         prop1 = new PropertyDataDefinitionBuilder()
52                 .setUniqueId("prop1")
53                 .setType("string")
54                 .setName("prop1")
55                 .setValue("value1")
56                 .build();
57
58         prop2 = new PropertyDataDefinitionBuilder()
59                 .setUniqueId("prop2")
60                 .setType("string")
61                 .setSchemaType("string")
62                 .setName("prop2")
63                 .setValue("[\"a\", \"b\"]")
64                 .build();
65
66         complexProperty = new PropertyDataDefinitionBuilder()
67                 .setUniqueId("prop3")
68                 .setType("org.openecomp.type1")
69                 .setName("prop3")
70                 .setValue("{\"ecomp_generated_naming\":true\",\"naming_policy\":\"abc\"}")
71                 .build();
72
73         ComponentInstance inst1 = new ComponentInstanceBuilder()
74                 .setComponentUid(ORIGIN_INSTANCE_ID)
75                 .setId(INSTANCE_ID)
76                 .setNormalizedName(INSTANCE_ID)
77                 .build();
78
79         resource = new ResourceBuilder()
80                 .setUniqueId(RESOURCE_ID)
81                 .addComponentInstance(inst1)
82                 .build();
83
84     }
85
86     List<ComponentInstancePropInput> createInstancePropInputList(List<PropertyDataDefinition> properties) {
87         return properties.stream().map(prop -> new ComponentInstancePropInput(new ComponentInstanceProperty(prop)))
88                 .collect(Collectors.toList());
89     }
90
91     void verifyInputPropertiesList(List<InputDefinition> createdInputs, List<PropertyDataDefinition> capturedUpdatedProperties) {
92         Map<String, InputDefinition> propertyIdToCreatedInput = MapUtil.toMap(createdInputs, InputDefinition::getPropertyId);
93         capturedUpdatedProperties.forEach(updatedProperty -> verifyInputPropertiesList(updatedProperty, propertyIdToCreatedInput.get(updatedProperty.getUniqueId())));
94     }
95
96     String generateGetInputValue(String value) {
97         return String.format("{\"%s\":\"%s\"}", GET_INPUT, value);
98     }
99
100     String generateGetInputValueAsListInput(String inputName, String inputProperty) {
101         return String.format("{\"%s\":[\"%s\",\"INDEX\",\"%s\"]}", GET_INPUT, inputName, inputProperty);
102     }
103
104     private void verifyInputPropertiesList(PropertyDataDefinition updatedProperty, InputDefinition input) {
105         assertThat(input.getProperties()).hasSize(1);
106         assertThat(new ComponentInstanceProperty(updatedProperty)).isEqualTo(input.getProperties().get(0));
107     }
108
109 }