Return List<Artifact> in ArtifactDownloadManager
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / notification / TestArtifactDeploymentManager.java
index dfced1a..2ff4ed5 100644 (file)
@@ -46,11 +46,14 @@ import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifact;
 import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifactHandler;
 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
 import org.onap.aai.modelloader.entity.model.ModelArtifactHandler;
+import org.onap.aai.modelloader.entity.model.ModelArtifactParser;
 import org.onap.aai.modelloader.extraction.InvalidArchiveException;
 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
+import org.onap.aai.modelloader.restclient.AaiRestClient;
 import org.onap.aai.modelloader.service.ArtifactDeploymentManager;
 import org.onap.aai.modelloader.util.ArtifactTestUtils;
 import org.onap.sdc.api.notification.INotificationData;
+import org.springframework.web.client.RestTemplate;
 
 /**
  * Tests {@link ArtifactDeploymentManager}.
@@ -73,7 +76,8 @@ public class TestArtifactDeploymentManager {
         configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
 
         ModelLoaderConfig modelLoaderConfig = new ModelLoaderConfig(configProperties, null);
-        manager = new ArtifactDeploymentManager(modelLoaderConfig, modelArtifactHandlerMock, vnfCatalogArtifactHandlerMock);
+        AaiRestClient aaiRestClient = new AaiRestClient(modelLoaderConfig, new RestTemplate());
+        manager = new ArtifactDeploymentManager(modelArtifactHandlerMock, vnfCatalogArtifactHandlerMock, aaiRestClient);
     }
 
     @AfterEach
@@ -88,13 +92,13 @@ public class TestArtifactDeploymentManager {
     public void deploy_csarDeploymentsFailed() throws IOException, BabelArtifactParsingException {
         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
         byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
-        List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
-        List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+        BabelArtifact toscaArtifact = setupTest(xml, data);
+        List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
 
         when(modelArtifactHandlerMock.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
                 .thenReturn(false);
 
-        assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data, modelArtifacts, new ArrayList<>()), is(false));
+        assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data.getDistributionID(), modelArtifacts, new ArrayList<>()), is(false));
 
         Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
                 any());
@@ -106,15 +110,13 @@ public class TestArtifactDeploymentManager {
                 eq(data.getDistributionID()), any());
     }
 
-    private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException {
-        List<BabelArtifact> toscaArtifacts = new ArrayList<>();
+    private BabelArtifact setupTest(byte[] xml, INotificationData data) throws IOException {
         org.onap.sdc.api.notification.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
@@ -129,7 +131,7 @@ public class TestArtifactDeploymentManager {
         when(vnfCatalogArtifactHandlerMock.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()), any(), any()))
                 .thenReturn(false);
 
-        assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data, new ArrayList<>(), catalogFiles), is(false));
+        assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data.getDistributionID(), new ArrayList<>(), catalogFiles), is(false));
 
         Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(new ArrayList<Artifact>()),
                 eq(data.getDistributionID()), any(), any());
@@ -160,8 +162,8 @@ public class TestArtifactDeploymentManager {
             throws IOException, BabelArtifactParsingException, InvalidArchiveException {
         INotificationData data = getNotificationDataWithOneOfEach();
         byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
-        List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
-        List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+        BabelArtifact toscaArtifact = setupTest(xml, data);
+        List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
 
         List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
         catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
@@ -171,7 +173,7 @@ public class TestArtifactDeploymentManager {
         when(modelArtifactHandlerMock.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
                 .thenReturn(modelsDeployed);
 
-        assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data, modelArtifacts, catalogFiles), is(false));
+        assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data.getDistributionID(), modelArtifacts, catalogFiles), is(false));
 
         // Catalog artifacts are only pushed if models are successful.
         Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
@@ -209,8 +211,8 @@ public class TestArtifactDeploymentManager {
     public void testDeploySuccess() throws IOException, BabelArtifactParsingException, InvalidArchiveException {
         INotificationData data = getNotificationDataWithOneOfEach();
         byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
-        List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
-        List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+        BabelArtifact toscaArtifact = setupTest(xml, data);
+        List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
 
         List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
         catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
@@ -220,7 +222,7 @@ public class TestArtifactDeploymentManager {
         when(modelArtifactHandlerMock.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
                 .thenReturn(true);
 
-        assertThat(manager.deploy(data, modelArtifacts, catalogFiles), is(true));
+        assertThat(manager.deploy(data.getDistributionID(), modelArtifacts, catalogFiles), is(true));
 
         Mockito.verify(vnfCatalogArtifactHandlerMock).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
                 any(), any());