Use checked Exception instead of RuntimeException
[aai/babel.git] / src / test / java / org / onap / aai / babel / parser / TestArtifactGeneratorToscaParser.java
index 7bc9fa8..65ec4c3 100644 (file)
@@ -27,6 +27,7 @@ import static org.hamcrest.Matchers.is;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
@@ -56,21 +57,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
      */
@@ -81,19 +70,19 @@ public class TestArtifactGeneratorToscaParser {
 
     /**
      * Initialize the Generator with no Widget Mappings content.
-     *
+     * 
      * @throws IOException
      *             if the file content could not be read successfully
      */
     @Test(expected = IOException.class)
     public void testMissingMappingsContent() throws IOException {
-        String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG);
-        ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson);
+        String emptyJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG);
+        ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(emptyJson);
     }
 
     /**
      * Initialize the Generator with invalid Widget Mappings content.
-     *
+     * 
      * @throws IOException
      *             if the file content could not be read successfully
      */
@@ -105,9 +94,12 @@ public class TestArtifactGeneratorToscaParser {
 
     /**
      * Process an Allotted Resource that does not have a Providing Service.
+     *
+     * @throws XmlArtifactGenerationException
+     *             because the ALLOTTED_RESOURCE lacks a Providing Service
      */
-    @Test(expected = IllegalArgumentException.class)
-    public void testMissingProvidingService() {
+    @Test(expected = XmlArtifactGenerationException.class)
+    public void testMissingProvidingService() throws XmlArtifactGenerationException {
         List<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage"));
         new ArtifactGeneratorToscaParser(null)
                 .processResourceModels(new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true), nodeTemplateList);
@@ -115,10 +107,17 @@ public class TestArtifactGeneratorToscaParser {
 
     /**
      * Add a CR (a type of Resource which is not a Providing Service) to a Resource Model.
+     *
+     * @throws XmlArtifactGenerationException
+     *             because the ALLOTTED_RESOURCE lacks a Providing Service
+     * @throws IOException
+     *             if the test mappings cannot be loaded
      */
-    @Test(expected = IllegalArgumentException.class)
-    public void testAddResourceNotProvidingService() {
+    @Test(expected = XmlArtifactGenerationException.class)
+    public void testAddResourceNotProvidingService() throws XmlArtifactGenerationException, IOException {
+        new ArtifactTestUtils().loadWidgetMappings();
         List<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR"));
+
         // Create any Resource to which the CR can be added
         final Resource dummyResource = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true);
         new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList);
@@ -126,7 +125,7 @@ public class TestArtifactGeneratorToscaParser {
 
     /**
      * Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
-     *
+     * 
      * @throws IOException
      *             if a WidgetMapping is invalid
      */
@@ -139,7 +138,7 @@ public class TestArtifactGeneratorToscaParser {
 
     /**
      * Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
-     *
+     * 
      * @throws IOException
      *             if a WidgetMapping is invalid
      */
@@ -152,7 +151,7 @@ public class TestArtifactGeneratorToscaParser {
 
     /**
      * Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
-     *
+     * 
      * @throws IOException
      *             if a WidgetMapping is invalid
      */
@@ -176,7 +175,6 @@ public class TestArtifactGeneratorToscaParser {
     public void testAddWidgetToService() throws IOException, XmlArtifactGenerationException {
         ArtifactTestUtils testUtils = new ArtifactTestUtils();
         testUtils.loadWidgetMappings();
-        testUtils.loadWidgetToUuidMappings();
 
         Model serviceModel = new Service();
         Resource resourceModel = new Resource(WidgetType.valueOf("VF"), false);
@@ -189,7 +187,7 @@ public class TestArtifactGeneratorToscaParser {
 
     /**
      * 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
@@ -202,21 +200,18 @@ public class TestArtifactGeneratorToscaParser {
         final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup";
         WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType));
 
-        ISdcCsarHelper helper = Mockito.mock(ISdcCsarHelper.class);
         SubstitutionMappings sm = Mockito.mock(SubstitutionMappings.class);
 
+        List<Group> groups = Arrays.asList(buildGroup("group", instanceGroupType));
+        Mockito.when(sm.getGroups()).thenReturn(new ArrayList<Group>(groups));
+
         NodeTemplate serviceNodeTemplate =
                 buildNodeTemplate("service", "org.openecomp.resource.cr.a-collection-resource");
         serviceNodeTemplate.setSubMappingToscaTemplate(sm);
-        Mockito.when(helper.getNodeTemplateByName(serviceNodeTemplate.getName())).thenReturn(serviceNodeTemplate);
-
-        ArrayList<Group> groups = new ArrayList<>();
-        groups.add(buildGroup("group", instanceGroupType));
-        Mockito.when(helper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate)).thenReturn(groups);
 
-        ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper);
         Resource groupResource = new Resource(WidgetType.valueOf("INSTANCE_GROUP"), true);
-        List<Resource> resources = parser.processInstanceGroups(groupResource, serviceNodeTemplate);
+        List<Resource> resources = new ArtifactGeneratorToscaParser(Mockito.mock(ISdcCsarHelper.class))
+                .processInstanceGroups(groupResource, serviceNodeTemplate);
 
         assertThat(resources.size(), is(1));
         Resource resource = resources.get(0);