diff options
Diffstat (limited to 'src/test/java/org/onap/aai/babel/xml/generator')
7 files changed, 81 insertions, 56 deletions
diff --git a/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java b/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java index b29d0d7..fc2522f 100644 --- a/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java @@ -23,13 +23,14 @@ package org.onap.aai.babel.xml.generator; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.aai.babel.csar.extractor.InvalidArchiveException; import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser; import org.onap.aai.babel.testdata.CsarTest; @@ -50,7 +51,7 @@ public class TestAaiArtifactGenerator { private ArtifactTestUtils testUtils; - @Before + @BeforeEach public void setup() { testUtils = new ArtifactTestUtils(); testUtils.setGeneratorSystemProperties(); @@ -84,19 +85,21 @@ public class TestAaiArtifactGenerator { * @throws XmlArtifactGenerationException * if the configured widget mappings do not support processed widget type(s) */ - @Test(expected = IllegalArgumentException.class) + @Test public void testParserWithIncompleteMappings() throws SdcToscaParserException, IOException, XmlArtifactGenerationException { - testUtils.loadWidgetMappings(); + assertThrows(IllegalArgumentException.class, () -> { + testUtils.loadWidgetMappings(); - AaiArtifactGenerator artifactGenerator = new AaiArtifactGenerator(); - WidgetType.clearElements(); // Remove all WidgetTypes so that the generator fails + AaiArtifactGenerator artifactGenerator = new AaiArtifactGenerator(); + WidgetType.clearElements(); // Remove all WidgetTypes so that the generator fails - ISdcCsarHelper csarHelper = SdcToscaParserFactory.getInstance() - .getSdcCsarHelper(TestAaiArtifactGenerator.class.getClassLoader() - .getResource(ArtifactTestUtils.CSAR_INPUTS_FOLDER + CsarTest.VNF_VENDOR_CSAR.getName()) - .getFile().toString()); - artifactGenerator.generateAllArtifacts("1.0", csarHelper); + ISdcCsarHelper csarHelper = SdcToscaParserFactory.getInstance() + .getSdcCsarHelper(TestAaiArtifactGenerator.class.getClassLoader() + .getResource(ArtifactTestUtils.CSAR_INPUTS_FOLDER + CsarTest.VNF_VENDOR_CSAR.getName()) + .getFile().toString()); + artifactGenerator.generateAllArtifacts("1.0", csarHelper); + }); } /** diff --git a/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java b/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java index 43f49a0..680a58a 100644 --- a/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/TestModelGenerator.java @@ -21,13 +21,14 @@ package org.onap.aai.babel.xml.generator; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.aai.babel.service.data.BabelArtifact; import org.onap.aai.babel.testdata.CsarTest; import org.onap.aai.babel.util.ArtifactTestUtils; @@ -43,16 +44,18 @@ public class TestModelGenerator { System.setProperty("APP_HOME", "."); } - @Before + @BeforeEach public void setup() { new ArtifactTestUtils().setGeneratorSystemProperties(); } - @Test(expected = Test.None.class /* no exception expected */) + @Test public void testDefaultServiceVersion() throws XmlArtifactGenerationException, IOException { - Artifact ymlFile = new Artifact(null, null, null, null); - new ModelGenerator().generateArtifacts(CsarTest.SD_WAN_CSAR_FILE.getContent(), - Collections.singletonList(ymlFile)); + assertDoesNotThrow(() -> { + Artifact ymlFile = new Artifact(null, null, null, null); + new ModelGenerator().generateArtifacts(CsarTest.SD_WAN_CSAR_FILE.getContent(), + Collections.singletonList(ymlFile)); + }); } @Test diff --git a/src/test/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorTest.java b/src/test/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorTest.java index 27e158f..6187ab3 100644 --- a/src/test/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorTest.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/api/AaiModelGeneratorTest.java @@ -22,7 +22,7 @@ package org.onap.aai.babel.xml.generator.api; import org.apache.groovy.util.Maps; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.aai.babel.util.ArtifactTestUtils; import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException; import org.onap.aai.babel.xml.generator.model.Model; diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java index 1fc5d13..d4b7fc8 100644 --- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestGeneratorUtil.java @@ -21,12 +21,12 @@ package org.onap.aai.babel.xml.generator.model; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.Base64; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.aai.babel.xml.generator.data.GeneratorUtil; public class TestGeneratorUtil { diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java index 700cf38..93dd443 100644 --- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestModel.java @@ -23,11 +23,13 @@ package org.onap.aai.babel.xml.generator.model; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.aai.babel.util.ArtifactTestUtils; /** @@ -42,7 +44,7 @@ public class TestModel { * @throws IOException * if the mappings configuration cannot be loaded */ - @BeforeClass + @BeforeAll public static void setup() throws IOException { new ArtifactTestUtils().loadWidgetMappings(); } @@ -74,18 +76,22 @@ public class TestModel { /** * Test that there is no exception if processing a Model that has no metadata properties. */ - @Test(expected = Test.None.class /* no exception expected */) + @Test public void testNullIdentProperties() { - createTestModel().populateModelIdentificationInformation(null); + assertDoesNotThrow(() -> { + createTestModel().populateModelIdentificationInformation(null); + }); } /** * Test that an exception occurs if calling code passes an unsupported Widget Type value to the base implementation * of the hasWidgetType() method. */ - @Test(expected = IllegalArgumentException.class) + @Test public void testUnknownWidgetType() { - createTestModel().hasWidgetType(null); + assertThrows(IllegalArgumentException.class, () -> { + createTestModel().hasWidgetType(null); + }); } /** diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java index 88555ee..d752ecd 100644 --- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestVfModule.java @@ -23,15 +23,15 @@ package org.onap.aai.babel.xml.generator.model; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; import java.io.IOException; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.aai.babel.util.ArtifactTestUtils; import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException; @@ -46,7 +46,7 @@ public class TestVfModule { * @throws IOException * if the mappings configuration cannot be loaded */ - @BeforeClass + @BeforeAll public static void setup() throws IOException { new ArtifactTestUtils().loadWidgetMappings(); } diff --git a/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java b/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java index 35319d6..9a06766 100644 --- a/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/model/TestWidget.java @@ -23,12 +23,13 @@ package org.onap.aai.babel.xml.generator.model; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.util.Collections; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.onap.aai.babel.util.ArtifactTestUtils; import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException; import org.onap.aai.babel.xml.generator.types.ModelType; @@ -44,7 +45,7 @@ public class TestWidget { * @throws IOException * if the mappings configuration cannot be loaded */ - @BeforeClass + @BeforeAll public static void setup() throws IOException { new ArtifactTestUtils().loadWidgetMappings(); } @@ -164,9 +165,11 @@ public class TestWidget { assertThat(widgetModel.equals(Widget.createWidget("VSERVER")), is(false)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testGetUnknownWidget() throws XmlArtifactGenerationException { - WidgetType.valueOf("invalid-widget-name"); + assertThrows(IllegalArgumentException.class, () -> { + WidgetType.valueOf("invalid-widget-name"); + }); } /** @@ -175,34 +178,44 @@ public class TestWidget { * @throws XmlArtifactGenerationException * if there is no configuration defined for the specified Widget type */ - @Test(expected = XmlArtifactGenerationException.class) + @Test public void testGetDynamicWidget() throws XmlArtifactGenerationException { - Widget.createWidget(new WidgetType(null)); + assertThrows(XmlArtifactGenerationException.class, () -> { + Widget.createWidget(new WidgetType(null)); + }); } - @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class) + @Test public void testAddResourceIsUnsupported() throws XmlArtifactGenerationException { - Widget.createWidget("OAM_NETWORK").addResource(null); + assertThrows(org.onap.aai.babel.xml.generator.error.IllegalAccessException.class, () -> { + Widget.createWidget("OAM_NETWORK").addResource(null); + }); } // Call Widget methods which are not supported, purely for code coverage. - @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class) + @Test public void testGetModelNameVersionIdIsUnsupported() throws XmlArtifactGenerationException { - Widget widgetModel = Widget.createWidget("OAM_NETWORK"); - widgetModel.getModelNameVersionId(); + assertThrows(org.onap.aai.babel.xml.generator.error.IllegalAccessException.class, () -> { + Widget widgetModel = Widget.createWidget("OAM_NETWORK"); + widgetModel.getModelNameVersionId(); + }); } - @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class) + @Test public void testGetModelTypeNameIsUnsupported() throws XmlArtifactGenerationException { - Widget widgetModel = Widget.createWidget("OAM_NETWORK"); - widgetModel.getModelTypeName(); + assertThrows(org.onap.aai.babel.xml.generator.error.IllegalAccessException.class, () -> { + Widget widgetModel = Widget.createWidget("OAM_NETWORK"); + widgetModel.getModelTypeName(); + }); } - @Test(expected = org.onap.aai.babel.xml.generator.error.IllegalAccessException.class) + @Test public void testGetModelIdIsUnsupported() throws XmlArtifactGenerationException { - Widget widgetModel = Widget.createWidget("OAM_NETWORK"); - widgetModel.getModelId(); + assertThrows(org.onap.aai.babel.xml.generator.error.IllegalAccessException.class, () -> { + Widget widgetModel = Widget.createWidget("OAM_NETWORK"); + widgetModel.getModelId(); + }); } } |