2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.components.property;
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.ComponentInstance;
30 import org.openecomp.sdc.be.model.ComponentInstancePropInput;
31 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
32 import org.openecomp.sdc.be.model.InputDefinition;
33 import org.openecomp.sdc.be.model.Resource;
35 import java.util.List;
37 import java.util.stream.Collectors;
39 import static org.assertj.core.api.Assertions.assertThat;
40 import static org.openecomp.sdc.common.api.Constants.GET_INPUT;
42 public class PropertyDeclaratorTestBase {
44 static final String INNER_PROP1 = "ecomp_generated_naming";
45 static final String INNER_PROP2 = "naming_policy";
46 static final String RESOURCE_ID = "resourceId";
47 static final String INPUT_ID = "inputId";
48 static final String INSTANCE_ID = "inst1";
49 static final String ORIGIN_INSTANCE_ID = "originInst1";
50 PropertyDataDefinition prop1, prop2, complexProperty;
54 public void setUp() throws Exception {
55 prop1 = new PropertyDataDefinitionBuilder()
62 prop2 = new PropertyDataDefinitionBuilder()
65 .setSchemaType("string")
67 .setValue("[\"a\", \"b\"]")
70 complexProperty = new PropertyDataDefinitionBuilder()
72 .setType("org.openecomp.type1")
74 .setValue("{\"ecomp_generated_naming\":true\",\"naming_policy\":\"abc\"}")
77 ComponentInstance inst1 = new ComponentInstanceBuilder()
78 .setComponentUid(ORIGIN_INSTANCE_ID)
80 .setNormalizedName(INSTANCE_ID)
83 resource = new ResourceBuilder()
84 .setUniqueId(RESOURCE_ID)
85 .addComponentInstance(inst1)
90 List<ComponentInstancePropInput> createInstancePropInputList(List<PropertyDataDefinition> properties) {
91 return properties.stream().map(prop -> new ComponentInstancePropInput(new ComponentInstanceProperty(prop)))
92 .collect(Collectors.toList());
95 void verifyInputPropertiesList(List<InputDefinition> createdInputs, List<PropertyDataDefinition> capturedUpdatedProperties) {
96 Map<String, InputDefinition> propertyIdToCreatedInput = MapUtil.toMap(createdInputs, InputDefinition::getPropertyId);
97 capturedUpdatedProperties.forEach(updatedProperty -> verifyInputPropertiesList(updatedProperty, propertyIdToCreatedInput.get(updatedProperty.getUniqueId())));
100 String generateGetInputValue(String value) {
101 return String.format("{\"%s\":\"%s\"}", GET_INPUT, value);
104 String generateGetInputValueAsListInput(String inputName, String inputProperty) {
105 return String.format("{\"%s\":[\"%s\",\"INDEX\",\"%s\"]}", GET_INPUT, inputName, inputProperty);
108 private void verifyInputPropertiesList(PropertyDataDefinition updatedProperty, InputDefinition input) {
109 assertThat(input.getProperties()).hasSize(1);
110 assertThat(new ComponentInstanceProperty(updatedProperty)).isEqualTo(input.getProperties().get(0));