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.*;
31 import java.util.List;
33 import java.util.stream.Collectors;
35 import static org.assertj.core.api.Assertions.assertThat;
36 import static org.openecomp.sdc.common.api.Constants.GET_INPUT;
38 public class PropertyDeclaratorTestBase {
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;
50 public void setUp() throws Exception {
51 prop1 = new PropertyDataDefinitionBuilder()
58 prop2 = new PropertyDataDefinitionBuilder()
61 .setSchemaType("string")
63 .setValue("[\"a\", \"b\"]")
66 complexProperty = new PropertyDataDefinitionBuilder()
68 .setType("org.openecomp.type1")
70 .setValue("{\"ecomp_generated_naming\":true\",\"naming_policy\":\"abc\"}")
73 ComponentInstance inst1 = new ComponentInstanceBuilder()
74 .setComponentUid(ORIGIN_INSTANCE_ID)
76 .setNormalizedName(INSTANCE_ID)
79 resource = new ResourceBuilder()
80 .setUniqueId(RESOURCE_ID)
81 .addComponentInstance(inst1)
86 List<ComponentInstancePropInput> createInstancePropInputList(List<PropertyDataDefinition> properties) {
87 return properties.stream().map(prop -> new ComponentInstancePropInput(new ComponentInstanceProperty(prop)))
88 .collect(Collectors.toList());
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())));
96 String generateGetInputValue(String value) {
97 return String.format("{\"%s\":\"%s\"}", GET_INPUT, value);
100 String generateGetInputValueAsListInput(String inputName, String inputProperty) {
101 return String.format("{\"%s\":[\"%s\",\"INDEX\",\"%s\"]}", GET_INPUT, inputName, inputProperty);
104 private void verifyInputPropertiesList(PropertyDataDefinition updatedProperty, InputDefinition input) {
105 assertThat(input.getProperties()).hasSize(1);
106 assertThat(new ComponentInstanceProperty(updatedProperty)).isEqualTo(input.getProperties().get(0));