X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fparser%2FTestArtifactGeneratorToscaParser.java;h=50812c9450625484567d5c3c087de73f45fea690;hb=bfde3ef00beb3c6f31cebfd12e90b9b9cdcc492e;hp=2de10b96fb9db26488079fc631d09dcf8fbc70b2;hpb=4e828f7f2037735de2253a0dcc2b557c88c15cd3;p=aai%2Fbabel.git diff --git a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java index 2de10b9..50812c9 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java +++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2019 European Software Marketing Ltd. + * Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,11 @@ import org.onap.aai.babel.util.Resources; import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException; import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil; import org.onap.aai.babel.xml.generator.data.WidgetMapping; +import org.onap.aai.babel.xml.generator.model.Model; import org.onap.aai.babel.xml.generator.model.Resource; -import org.onap.aai.babel.xml.generator.model.Widget.Type; +import org.onap.aai.babel.xml.generator.model.Service; +import org.onap.aai.babel.xml.generator.model.WidgetType; +import org.onap.aai.babel.xml.generator.types.ModelType; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; @@ -53,21 +56,9 @@ public class TestArtifactGeneratorToscaParser { private static final String TEST_UUID = "1234"; - /** - * Initialize the Generator with an invalid artifact generator properties file path. - * - * @throws IOException - * if an error occurs reading the configuration properties - */ - @Test(expected = IllegalArgumentException.class) - public void testMissingPropertiesFile() throws IOException { - System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE, "non-existent.file"); - ArtifactGeneratorToscaParser.initWidgetConfiguration(); - } - /** * Initialize the Generator with an invalid mappings file path. - * + * * @throws IOException * if the file content could not be read successfully */ @@ -78,7 +69,7 @@ public class TestArtifactGeneratorToscaParser { /** * Initialize the Generator with no Widget Mappings content. - * + * * @throws IOException * if the file content could not be read successfully */ @@ -90,7 +81,7 @@ public class TestArtifactGeneratorToscaParser { /** * Initialize the Generator with invalid Widget Mappings content. - * + * * @throws IOException * if the file content could not be read successfully */ @@ -106,8 +97,8 @@ public class TestArtifactGeneratorToscaParser { @Test(expected = IllegalArgumentException.class) public void testMissingProvidingService() { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage")); - new ArtifactGeneratorToscaParser(null).processResourceModels(new Resource(Type.ALLOTTED_RESOURCE, true), - nodeTemplateList); + new ArtifactGeneratorToscaParser(null) + .processResourceModels(new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true), nodeTemplateList); } /** @@ -117,38 +108,84 @@ public class TestArtifactGeneratorToscaParser { public void testAddResourceNotProvidingService() { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR")); // Create any Resource to which the CR can be added - final Resource dummyResource = new Resource(Type.ALLOTTED_RESOURCE, true); + final Resource dummyResource = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true); new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList); } /** - * Initialise the Artifact Generator Widget Mapping config with incomplete data (no type). + * Initialize the Artifact Generator Widget Mapping config with incomplete data (no type). + * + * @throws IOException + * if a WidgetMapping is invalid */ - @Test(expected = IllegalArgumentException.class) - public void testToscaMappingWithoutType() { + @Test(expected = IOException.class) + public void testToscaMappingWithoutType() throws IOException { WidgetMapping invalidMapping = new WidgetMapping(); invalidMapping.setType(null); WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); } /** - * Initialise the Artifact Generator Widget Mapping config with incomplete data (no widget name). + * Initialize the Artifact Generator Widget Mapping config with invalid data (type value). + * + * @throws IOException + * if a WidgetMapping is invalid */ - @Test(expected = IllegalArgumentException.class) - public void testToscaMappingWithoutWidget() { + @Test(expected = IOException.class) + public void testToscaMappingWithInvalidType() throws IOException { + WidgetMapping invalidMapping = new WidgetMapping(); + invalidMapping.setType("invalid"); + WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); + } + + /** + * Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name). + * + * @throws IOException + * if a WidgetMapping is invalid + */ + @Test(expected = IOException.class) + public void testToscaMappingWithoutWidget() throws IOException { WidgetMapping invalidMapping = new WidgetMapping(); invalidMapping.setWidget(null); WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); } + /** + * Create a Resource with a Widget model type and add this to a Service. Note that there are no test CSAR files + * which require this functionality, but the code path exists to support it. + * + * @throws IOException + * if the widget mappings are not loaded + * @throws XmlArtifactGenerationException + * if there is no configuration defined for the test resource's widget type + */ + @Test + public void testAddWidgetToService() throws IOException, XmlArtifactGenerationException { + ArtifactTestUtils testUtils = new ArtifactTestUtils(); + testUtils.loadWidgetMappings(); + + Model serviceModel = new Service(); + Resource resourceModel = new Resource(WidgetType.valueOf("VF"), false); + resourceModel.setModelType(ModelType.WIDGET); + + ISdcCsarHelper helper = Mockito.mock(ISdcCsarHelper.class); + ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper); + parser.addRelatedModel(serviceModel, resourceModel); + } + /** * Process a dummy Group object for a Service Resource. - * + * * @throws XmlArtifactGenerationException * if there is no configuration defined for a member Widget of an instance group + * @throws IOException + * if the widget mappings cannot be loaded */ @Test - public void testInstanceGroups() throws XmlArtifactGenerationException { + public void testInstanceGroups() throws XmlArtifactGenerationException, IOException { + new ArtifactTestUtils().loadWidgetMappings(); + final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup"; WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType)); @@ -165,8 +202,8 @@ public class TestArtifactGeneratorToscaParser { Mockito.when(helper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate)).thenReturn(groups); ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper); - List resources = - parser.processInstanceGroups(new Resource(Type.INSTANCE_GROUP, true), serviceNodeTemplate); + Resource groupResource = new Resource(WidgetType.valueOf("INSTANCE_GROUP"), true); + List resources = parser.processInstanceGroups(groupResource, serviceNodeTemplate); assertThat(resources.size(), is(1)); Resource resource = resources.get(0);