diff options
Diffstat (limited to 'catalog-be/src/test')
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java | 37 | ||||
-rw-r--r-- | catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java | 32 | ||||
-rw-r--r-- | catalog-be/src/test/resources/csars/with_groups.csar | bin | 66187 -> 66267 bytes |
3 files changed, 60 insertions, 9 deletions
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java index a2931a515b..edf17b7e61 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/YamlTemplateParsingHandlerTest.java @@ -31,6 +31,7 @@ import static org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum.ARTIFACTS; import java.io.File; import java.net.URISyntaxException; +import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -260,6 +261,42 @@ public class YamlTemplateParsingHandlerTest { validateParsedYamlWithPolicies(parsedYaml); } + @Test + void parseResourceInstanceWithAttributesTest() { + stubGetGroupType(); + stubGetPolicyType(); + Resource resource = new Resource(); + ParsedToscaYamlInfo parsedYaml = handler.parseResourceInfoFromYAML(FILE_NAME, resourceYml, new HashMap<>(), + new HashMap<>(), "", resource, null); + validateParsedYamlWithAttributes(parsedYaml); + } + + private void validateParsedYamlWithAttributes(ParsedToscaYamlInfo parsedYaml) { + ArrayList<String> expectedSubnetsShowList = new ArrayList<>(); + expectedSubnetsShowList.add("val1"); + expectedSubnetsShowList.add("val2"); + + HashMap<String, String> expectedSubnetsNameMap = new HashMap<>(); + expectedSubnetsNameMap.put("name1", "name_val1"); + expectedSubnetsNameMap.put("name2", "name_val2"); + + + assertThat(parsedYaml.getInstances().get("resource_instance_with_attributes")).isNotNull(); + UploadComponentInstanceInfo resourceInstanceWithAttributes = parsedYaml.getInstances().get("resource_instance_with_attributes"); + assertEquals(5, resourceInstanceWithAttributes.getAttributes().size()); + + assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("fq_name")); + assertEquals(resourceInstanceWithAttributes.getAttributes().get("fq_name").getValue(), "fq_name_value"); + assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("tosca_name")); + assertEquals(resourceInstanceWithAttributes.getAttributes().get("tosca_name").getValue(), "tosca_name_value"); + assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("subnets_show")); + assertEquals(resourceInstanceWithAttributes.getAttributes().get("subnets_show").getValue(), expectedSubnetsShowList); + assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("subnets_name")); + assertEquals(resourceInstanceWithAttributes.getAttributes().get("subnets_name").getValue(), expectedSubnetsNameMap); + assertTrue(resourceInstanceWithAttributes.getAttributes().containsKey("new_attribute")); + assertEquals(resourceInstanceWithAttributes.getAttributes().get("new_attribute").getValue(), "new_attribute_value"); + } + private void validateParsedYaml(ParsedToscaYamlInfo parsedYaml, String group, List<String> expectedProp) { assertThat(parsedYaml).isNotNull(); assertThat(parsedYaml.getGroups()).isNotNull().containsKey(group); diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java index fcc0ebfffd..00779d40e2 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/AttributeConverterTest.java @@ -33,12 +33,15 @@ import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; import org.onap.sdc.tosca.datatypes.model.EntrySchema; +import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition; +import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition; import org.openecomp.sdc.be.model.AttributeDefinition; import org.openecomp.sdc.be.model.DataTypeDefinition; import org.openecomp.sdc.be.model.PropertyDefinition; import org.openecomp.sdc.be.model.tosca.ToscaPropertyType; import org.openecomp.sdc.be.tosca.exception.ToscaConversionException; import org.openecomp.sdc.be.tosca.model.ToscaAttribute; +import org.openecomp.sdc.be.tosca.model.ToscaSchemaDefinition; class AttributeConverterTest { @@ -80,10 +83,10 @@ class AttributeConverterTest { attributeDefinition.setType(ToscaPropertyType.LIST.getType()); attributeDefinition.setDescription("aDescription"); attributeDefinition.setStatus("aStatus"); - final EntrySchema entrySchema = new EntrySchema(); - entrySchema.setDescription("anEntrySchemaDescription"); - entrySchema.setType(ToscaPropertyType.LIST.getType()); - attributeDefinition.setEntry_schema(entrySchema); + attributeDefinition.setSchema(new SchemaDefinition()); + attributeDefinition.getSchema().setProperty(new PropertyDataDefinition()); + attributeDefinition.getSchema().getProperty().setType(ToscaPropertyType.LIST.getType()); + attributeDefinition.getSchema().getProperty().setDescription("anEntrySchemaDescription"); final List<String> defaultValueList = new ArrayList<>(); defaultValueList.add("entry1"); defaultValueList.add("entry2"); @@ -143,15 +146,26 @@ class AttributeConverterTest { } @Test - void testConvertAndAddValue() throws ToscaConversionException { + void testConvertAndAddDefaultValue() throws ToscaConversionException { final AttributeConverter converter = createTestSubject(); final AttributeDefinition attribute = new AttributeDefinition(); attribute.setName("attrib"); attribute.setDefaultValue("default"); final Map<String, Object> attribs = new HashMap<>(); converter.convertAndAddValue(attribs, attribute); + assertEquals(0, attribs.size()); + } + + @Test + void testConvertAndAddValue() throws ToscaConversionException { + final AttributeConverter converter = createTestSubject(); + final AttributeDefinition attribute = new AttributeDefinition(); + attribute.setName("attrib"); + attribute.setValue("value"); + final Map<String, Object> attribs = new HashMap<>(); + converter.convertAndAddValue(attribs, attribute); assertEquals(1, attribs.size()); - assertEquals("default", attribs.get("attrib")); + assertEquals("value", attribs.get("attrib")); } private AttributeConverter createTestSubject() { @@ -167,13 +181,13 @@ class AttributeConverterTest { assertEquals(expectedAttributeDefinition.getType(), actualToscaAttribute.getType()); assertEquals(expectedAttributeDefinition.getDescription(), actualToscaAttribute.getDescription()); assertEquals(expectedAttributeDefinition.getStatus(), actualToscaAttribute.getStatus()); - if (expectedAttributeDefinition.getEntry_schema() == null) { + if (expectedAttributeDefinition.getSchema() == null) { assertNull(actualToscaAttribute.getEntrySchema()); } else { - assertEquals(expectedAttributeDefinition.getEntry_schema().getType(), + assertEquals(expectedAttributeDefinition.getSchema().getProperty().getType(), actualToscaAttribute.getEntrySchema().getType()); assertEquals( - expectedAttributeDefinition.getEntry_schema().getDescription(), + expectedAttributeDefinition.getSchema().getProperty().getDescription(), actualToscaAttribute.getEntrySchema().getDescription()); } assertEquals(expectedDefault, actualToscaAttribute.getDefault()); diff --git a/catalog-be/src/test/resources/csars/with_groups.csar b/catalog-be/src/test/resources/csars/with_groups.csar Binary files differindex 49b5a440ea..dd7f5dfb69 100644 --- a/catalog-be/src/test/resources/csars/with_groups.csar +++ b/catalog-be/src/test/resources/csars/with_groups.csar |