X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fnotification%2FTestBabelArtifactConverter.java;h=aee3dc21c51e761ae1b5158089ca31388b94aa8b;hb=HEAD;hp=2a04ec50d9a907e710fef99f78a020a374226d2b;hpb=b984f4c39231a32dd53d02e60741c7d32822aad0;p=aai%2Fmodel-loader.git diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestBabelArtifactConverter.java b/src/test/java/org/onap/aai/modelloader/notification/TestBabelArtifactConverter.java index 2a04ec5..aee3dc2 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/TestBabelArtifactConverter.java +++ b/src/test/java/org/onap/aai/modelloader/notification/TestBabelArtifactConverter.java @@ -20,18 +20,19 @@ */ package org.onap.aai.modelloader.notification; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; -import java.util.ArrayList; import java.util.List; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.onap.aai.babel.service.data.BabelArtifact; import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; +import org.onap.aai.modelloader.entity.model.ModelArtifactParser; import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder; import org.onap.aai.modelloader.util.ArtifactTestUtils; import org.onap.sdc.api.notification.IArtifactInfo; @@ -42,41 +43,37 @@ import org.onap.sdc.api.notification.INotificationData; */ public class TestBabelArtifactConverter { - @Test(expected = NullPointerException.class) + @Test public void convert_nullToscaFiles() throws BabelArtifactParsingException { - new BabelArtifactConverter().convertToModel(null); - fail("An instance of ArtifactGenerationException should have been thrown"); + assertThrows(NullPointerException.class, () -> { + new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(null); + fail("An instance of ArtifactGenerationException should have been thrown"); + }); } @Test - public void testEmptyToscaFiles() throws BabelArtifactParsingException { - assertTrue("Nothing should have been returned", - new BabelArtifactConverter().convertToModel(new ArrayList<>()).isEmpty()); - } - - @Test(expected = BabelArtifactParsingException.class) public void testInvalidXml() throws IOException, BabelArtifactParsingException { - byte[] problemXml = - "This is some xml that should cause the model artifact parser to throw an erorr" - .getBytes(); + assertThrows(BabelArtifactParsingException.class, () -> { + byte[] problemXml = + "This is some xml that should cause the model artifact parser to throw an erorr" + .getBytes(); - INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile(); + INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile(); - List toscaArtifacts = setupTest(problemXml, data); + BabelArtifact toscaArtifact = setupTest(problemXml, data); - new BabelArtifactConverter().convertToModel(toscaArtifacts); - fail("An instance of ModelArtifactParsingException should have been thrown"); + new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact); + fail("An instance of ModelArtifactParsingException should have been thrown"); + }); } - private List setupTest(byte[] xml, INotificationData data) throws IOException { - List toscaArtifacts = new ArrayList<>(); + private BabelArtifact setupTest(byte[] xml, INotificationData data) throws IOException { IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); BabelArtifact xmlArtifact = new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml)); - toscaArtifacts.add(xmlArtifact); - return toscaArtifacts; + return xmlArtifact; } @Test @@ -84,11 +81,11 @@ public class TestBabelArtifactConverter { INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile(); byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml"); - List toscaArtifacts = setupTest(xml, data); + BabelArtifact toscaArtifact = setupTest(xml, data); - List modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts); + List modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact); - assertEquals("There should have been 1 artifact", 1, modelArtifacts.size()); + assertEquals(1, modelArtifacts.size(), "There should have been 1 artifact"); assertEquals(new String(xml), modelArtifacts.get(0).getPayload()); assertEquals(ArtifactType.MODEL, modelArtifacts.get(0).getType()); }