X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fparser%2FTestArtifactGeneratorToscaParser.java;h=4451a28b47e3ab153eb3944542571ff01dd7313d;hb=f5dae47e293ae63a7a2f18230b772a699a52566f;hp=52dd462e7743f591a47e002114c3328b0b747bec;hpb=7fcc74469c941c1834cd02b54ff5ca88a53bf83b;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 52dd462..4451a28 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-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 European Software Marketing Ltd. + * Copyright © 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright © 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. @@ -25,16 +25,20 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import org.junit.Test; import org.mockito.Mockito; +import org.onap.aai.babel.util.ArtifactTestUtils; +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.model.AllotedResource; -import org.onap.aai.babel.xml.generator.model.InstanceGroup; +import org.onap.aai.babel.xml.generator.data.WidgetMapping; import org.onap.aai.babel.xml.generator.model.Resource; +import org.onap.aai.babel.xml.generator.model.Widget.Type; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; @@ -49,31 +53,97 @@ public class TestArtifactGeneratorToscaParser { private static final String TEST_UUID = "1234"; + /** + * Initialize the Generator with an invalid artifact generator properties file path. + * + * @throws IOException + */ + @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 + */ + @Test(expected = IllegalArgumentException.class) + public void testMissingMappingsFile() throws IOException { + ArtifactGeneratorToscaParser.initToscaMappingsConfiguration("non-existent.file"); + } + + /** + * Initialize the Generator with no Widget Mappings content. + * + * @throws IOException + */ + @Test(expected = IOException.class) + public void testMissingMappingsContent() throws IOException { + String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG); + ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson); + } + + /** + * Initialize the Generator with invalid Widget Mappings content. + * + * @throws IOException + */ + @Test(expected = IOException.class) + public void testInvalidMappingsContent() throws IOException { + String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.INVALID_TOSCA_MAPPING_CONFIG); + ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson); + } + /** * Process an Allotted Resource that does not have a Providing Service. */ @Test(expected = IllegalArgumentException.class) public void testMissingProvidingService() { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage")); - new ArtifactGeneratorToscaParser(null).processResourceModels(new AllotedResource(), nodeTemplateList); + new ArtifactGeneratorToscaParser(null).processResourceModels(new Resource(Type.ALLOTTED_RESOURCE, true), + nodeTemplateList); } /** - * * Add a CR (a type of Resource which is not a Providing Service) to a Resource Model. */ @Test(expected = IllegalArgumentException.class) public void testAddResourceNotProvidingService() { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR")); - final Resource dummyResource = new AllotedResource(); // Any Resource to which the CR can be added + // Create any Resource to which the CR can be added + final Resource dummyResource = new Resource(Type.ALLOTTED_RESOURCE, true); new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList); } + /** + * Initialise the Artifact Generator Widget Mapping config with incomplete data. + */ + @Test(expected = IllegalArgumentException.class) + public void testToscaMappingWithoutType() { + WidgetMapping invalidMapping = new WidgetMapping(); + invalidMapping.setType(null); + WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); + } + + /** + * Initialise the Artifact Generator Widget Mapping config with incomplete data. + */ + @Test(expected = IllegalArgumentException.class) + public void testToscaMappingWithoutWidget() { + WidgetMapping invalidMapping = new WidgetMapping(); + invalidMapping.setWidget(null); + WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); + } + /** * Process a dummy Group object for a Service Resource. + * + * @throws XmlArtifactGenerationException */ @Test - public void testInstanceGroups() { + public void testInstanceGroups() throws XmlArtifactGenerationException { final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup"; WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType)); @@ -90,7 +160,8 @@ public class TestArtifactGeneratorToscaParser { Mockito.when(helper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate)).thenReturn(groups); ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper); - List resources = parser.processInstanceGroups(new InstanceGroup(), serviceNodeTemplate); + List resources = + parser.processInstanceGroups(new Resource(Type.INSTANCE_GROUP, true), serviceNodeTemplate); assertThat(resources.size(), is(1)); Resource resource = resources.get(0);