X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fnotification%2FTestArtifactDeploymentManager.java;h=618a268d155d48018417716653d35fd3086f8322;hb=refs%2Fheads%2Fmaster;hp=dfced1ad20fdd969d6313fb5b5998c9f8882945b;hpb=19f034b2554895285f12979b0f36c1629f9af984;p=aai%2Fmodel-loader.git diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java index dfced1a..2ff4ed5 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java +++ b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java @@ -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 toscaArtifacts = setupTest(xml, data); - List modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts); + BabelArtifact toscaArtifact = setupTest(xml, data); + List 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 setupTest(byte[] xml, INotificationData data) throws IOException { - List 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()), 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 toscaArtifacts = setupTest(xml, data); - List modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts); + BabelArtifact toscaArtifact = setupTest(xml, data); + List modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact); List 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 toscaArtifacts = setupTest(xml, data); - List modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts); + BabelArtifact toscaArtifact = setupTest(xml, data); + List modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact); List 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());