*/
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;
*/
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 =
- "<model xmlns=\"http://org.openecomp.aai.inventory/v10\"><rubbish>This is some xml that should cause the model artifact parser to throw an erorr</rubbish></model>"
- .getBytes();
+ assertThrows(BabelArtifactParsingException.class, () -> {
+ byte[] problemXml =
+ "<model xmlns=\"http://org.openecomp.aai.inventory/v10\"><rubbish>This is some xml that should cause the model artifact parser to throw an erorr</rubbish></model>"
+ .getBytes();
- INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
+ INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
- List<BabelArtifact> 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<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException {
- List<BabelArtifact> 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
INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
- List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
+ BabelArtifact toscaArtifact = setupTest(xml, data);
- List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+ List<Artifact> 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());
}