Update aai-parent in babel to 1.13.3
[aai/babel.git] / src / test / java / org / onap / aai / babel / parser / TestArtifactGeneratorToscaParser.java
index 50812c9..9988076 100644 (file)
@@ -24,13 +24,16 @@ package org.onap.aai.babel.parser;
 import static org.hamcrest.CoreMatchers.equalTo;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
 import org.mockito.Mockito;
 import org.onap.aai.babel.util.ArtifactTestUtils;
 import org.onap.aai.babel.util.Resources;
@@ -58,97 +61,123 @@ public class TestArtifactGeneratorToscaParser {
 
     /**
      * Initialize the Generator with an invalid mappings file path.
-     *
+     * 
      * @throws IOException
      *             if the file content could not be read successfully
      */
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testMissingMappingsFile() throws IOException {
-        ArtifactGeneratorToscaParser.initToscaMappingsConfiguration("non-existent.file");
+        assertThrows(IllegalArgumentException.class, () -> {
+            ArtifactGeneratorToscaParser.initToscaMappingsConfiguration("non-existent.file");
+        });
     }
 
     /**
      * Initialize the Generator with no Widget Mappings content.
-     *
+     * 
      * @throws IOException
      *             if the file content could not be read successfully
      */
-    @Test(expected = IOException.class)
+    @Test
     public void testMissingMappingsContent() throws IOException {
-        String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG);
-        ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson);
+        assertThrows(IOException.class, () -> {
+            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
      */
-    @Test(expected = IOException.class)
+    @Test
     public void testInvalidMappingsContent() throws IOException {
-        String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.INVALID_TOSCA_MAPPING_CONFIG);
-        ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson);
+        assertThrows(IOException.class, () -> {
+            String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.INVALID_TOSCA_MAPPING_CONFIG);
+            ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson);
+        });
     }
 
     /**
      * 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() {
-        List<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage"));
-        new ArtifactGeneratorToscaParser(null)
-                .processResourceModels(new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true), nodeTemplateList);
+    @Test
+    public void testMissingProvidingService() throws XmlArtifactGenerationException {
+        assertThrows(XmlArtifactGenerationException.class, () -> {
+            List<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage"));
+            new ArtifactGeneratorToscaParser(null)
+                    .processResourceModels(new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true), nodeTemplateList);
+        });
     }
 
     /**
      * 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() {
-        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);
+    @Test
+    public void testAddResourceNotProvidingService() throws XmlArtifactGenerationException, IOException {
+        assertThrows(XmlArtifactGenerationException.class, () -> {
+            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);
+        });
     }
 
     /**
      * Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
-     *
+     * 
      * @throws IOException
      *             if a WidgetMapping is invalid
      */
-    @Test(expected = IOException.class)
+    @Test
     public void testToscaMappingWithoutType() throws IOException {
-        WidgetMapping invalidMapping = new WidgetMapping();
-        invalidMapping.setType(null);
-        WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+        assertThrows(IOException.class, () -> {
+            WidgetMapping invalidMapping = new WidgetMapping();
+            invalidMapping.setType(null);
+            WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+        });
     }
 
     /**
      * Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
-     *
+     * 
      * @throws IOException
      *             if a WidgetMapping is invalid
      */
-    @Test(expected = IOException.class)
+    @Test
     public void testToscaMappingWithInvalidType() throws IOException {
-        WidgetMapping invalidMapping = new WidgetMapping();
-        invalidMapping.setType("invalid");
-        WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+        assertThrows(IOException.class, () -> {
+            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)
+    @Test
     public void testToscaMappingWithoutWidget() throws IOException {
-        WidgetMapping invalidMapping = new WidgetMapping();
-        invalidMapping.setWidget(null);
-        WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+        assertThrows(IOException.class, () -> {
+            WidgetMapping invalidMapping = new WidgetMapping();
+            invalidMapping.setWidget(null);
+            WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+        });
     }
 
     /**
@@ -162,21 +191,23 @@ public class TestArtifactGeneratorToscaParser {
      */
     @Test
     public void testAddWidgetToService() throws IOException, XmlArtifactGenerationException {
-        ArtifactTestUtils testUtils = new ArtifactTestUtils();
-        testUtils.loadWidgetMappings();
+        assertDoesNotThrow(() -> {
+            ArtifactTestUtils testUtils = new ArtifactTestUtils();
+            testUtils.loadWidgetMappings();
 
-        Model serviceModel = new Service();
-        Resource resourceModel = new Resource(WidgetType.valueOf("VF"), false);
-        resourceModel.setModelType(ModelType.WIDGET);
+            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);
+            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
@@ -189,21 +220,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);