X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fnotification%2FTestArtifactDownloadManager.java;h=27d0aa9ff08e7a16a4a827d73cac184dbb855128;hb=0e9a90774a86475f40d4e946798cf765910a31f6;hp=030a0ff73e9a86c96dea1a6f674b564c825fe577;hpb=c5aea4a8bc398fc1c6220875e55b9520fd7f7524;p=aai%2Fmodel-loader.git diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java index 030a0ff..27d0aa9 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java +++ b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java @@ -22,10 +22,11 @@ package org.onap.aai.modelloader.notification; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsEmptyCollection.empty; -import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithInvalidType; import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithModelQuerySpec; @@ -37,21 +38,23 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Properties; + import org.hamcrest.collection.IsEmptyCollection; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Matchers; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.internal.util.reflection.Whitebox; +import org.mockito.MockitoAnnotations; import org.onap.aai.babel.service.data.BabelArtifact; -import org.onap.aai.modelloader.config.ModelLoaderConfig; +import org.onap.aai.modelloader.babel.BabelArtifactService; import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; +import org.onap.aai.modelloader.extraction.VnfCatalogExtractor; import org.onap.aai.modelloader.restclient.BabelServiceClient; import org.onap.aai.modelloader.restclient.BabelServiceClientException; import org.onap.aai.modelloader.service.BabelServiceClientFactory; -import org.onap.aai.modelloader.service.HttpsBabelServiceClientFactory; import org.onap.aai.modelloader.util.ArtifactTestUtils; import org.onap.sdc.api.IDistributionClient; import org.onap.sdc.api.notification.IArtifactInfo; @@ -66,31 +69,27 @@ import org.onap.sdc.utils.DistributionActionResultEnum; public class TestArtifactDownloadManager { private ArtifactDownloadManager downloadManager; - private BabelServiceClient mockBabelClient; - private IDistributionClient mockDistributionClient; - private NotificationPublisher mockNotificationPublisher; - private BabelArtifactConverter mockBabelArtifactConverter; - private BabelServiceClientFactory mockClientFactory; - - @Before + @Mock private BabelServiceClient mockBabelClient; + @Mock private IDistributionClient mockDistributionClient; + @Mock private NotificationPublisher mockNotificationPublisher; + @Mock private BabelArtifactConverter mockBabelArtifactConverter; + @Mock private BabelServiceClientFactory mockClientFactory; + @InjectMocks BabelArtifactService babelArtifactService; + private VnfCatalogExtractor vnfCatalogExtractor; + + @BeforeEach public void setup() throws Exception { - mockBabelClient = mock(BabelServiceClient.class); - mockDistributionClient = mock(IDistributionClient.class); - mockNotificationPublisher = mock(NotificationPublisher.class); - mockBabelArtifactConverter = mock(BabelArtifactConverter.class); - mockClientFactory = mock(HttpsBabelServiceClientFactory.class); - when(mockClientFactory.create(Mockito.any())).thenReturn(mockBabelClient); + MockitoAnnotations.openMocks(this); + vnfCatalogExtractor = new VnfCatalogExtractor(); + when(mockClientFactory.create(any())).thenReturn(mockBabelClient); Properties configProperties = new Properties(); configProperties.load(this.getClass().getClassLoader().getResourceAsStream("model-loader.properties")); downloadManager = new ArtifactDownloadManager(mockDistributionClient, - new ModelLoaderConfig(configProperties, "."), mockClientFactory); - - Whitebox.setInternalState(downloadManager, "notificationPublisher", mockNotificationPublisher); - Whitebox.setInternalState(downloadManager, "babelArtifactConverter", mockBabelArtifactConverter); + mockNotificationPublisher, vnfCatalogExtractor, babelArtifactService); } - @After + @AfterEach public void tearDown() { downloadManager = null; mockDistributionClient = null; @@ -108,7 +107,7 @@ public class TestArtifactDownloadManager { catalogFiles), is(true)); assertThat(modelFiles, is(empty())); assertThat(catalogFiles, is(empty())); - Mockito.verifyZeroInteractions(mockBabelClient, mockDistributionClient, mockNotificationPublisher, + Mockito.verifyNoInteractions(mockBabelClient, mockDistributionClient, mockNotificationPublisher, mockBabelArtifactConverter); } @@ -128,12 +127,12 @@ public class TestArtifactDownloadManager { Mockito.verify(mockNotificationPublisher).publishDownloadFailure(mockDistributionClient, data, artifact, errorMessage); - Mockito.verifyZeroInteractions(mockBabelClient, mockBabelArtifactConverter); + Mockito.verifyNoInteractions(mockBabelClient, mockBabelArtifactConverter); } @Test public void testErrorCreatingBabelClient() throws Exception { - when(mockClientFactory.create(Mockito.any())).thenThrow(new BabelServiceClientException(new Exception())); + when(mockClientFactory.create(any())).thenThrow(new BabelServiceClientException(new Exception())); INotificationData data = getNotificationDataWithToscaCsarFile(); IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); @@ -145,8 +144,6 @@ public class TestArtifactDownloadManager { Mockito.verify(mockDistributionClient).download(artifactInfo); Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifactInfo); Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo); - - Mockito.verifyZeroInteractions(mockBabelArtifactConverter); } @Test @@ -156,19 +153,17 @@ public class TestArtifactDownloadManager { when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult( DistributionActionResultEnum.SUCCESS, null, "This is not a valid Tosca CSAR File".getBytes())); doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact); - when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(), - Matchers.anyString())).thenThrow(new BabelServiceClientException("")); + when(mockBabelClient.postArtifact(any(), any())).thenThrow(new BabelServiceClientException("")); doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact); assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, null), is(false)); Mockito.verify(mockDistributionClient).download(artifact); Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact); - Mockito.verify(mockBabelClient).postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(), - Matchers.anyString()); + Mockito.verify(mockBabelClient).postArtifact(any(), any()); Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact); - Mockito.verifyZeroInteractions(mockBabelArtifactConverter); + Mockito.verifyNoInteractions(mockBabelArtifactConverter); } @@ -190,7 +185,7 @@ public class TestArtifactDownloadManager { Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact); Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact); - Mockito.verifyZeroInteractions(mockBabelClient, mockBabelArtifactConverter); + Mockito.verifyNoInteractions(mockBabelClient, mockBabelArtifactConverter); } @Test @@ -209,10 +204,9 @@ public class TestArtifactDownloadManager { Mockito.verify(mockDistributionClient).download(artifactInfo); Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifactInfo); - Mockito.verify(mockBabelClient).postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(), - Matchers.anyString()); - Mockito.verify(mockBabelArtifactConverter).convertToModel(Matchers.any()); - Mockito.verify(mockBabelArtifactConverter).convertToCatalog(Matchers.any()); + Mockito.verify(mockBabelClient).postArtifact(any(), any()); + Mockito.verify(mockBabelArtifactConverter).convertToModel(any()); + Mockito.verify(mockBabelArtifactConverter).convertToCatalog(any()); } private void setupValidDownloadCsarMocks(INotificationData data, IArtifactInfo artifactInfo, @@ -220,8 +214,7 @@ public class TestArtifactDownloadManager { when(mockDistributionClient.download(artifactInfo)) .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null, artifactTestUtils.loadResource("compressedArtifacts/service-VscpaasTest-csar.csar"))); - when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(), - Matchers.anyString())).thenReturn(createBabelArtifacts()); + when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifacts()); } private List createBabelArtifacts() { @@ -249,7 +242,7 @@ public class TestArtifactDownloadManager { Mockito.verify(mockDistributionClient).download(artifact); Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact); - Mockito.verifyZeroInteractions(mockBabelClient, mockBabelArtifactConverter); + Mockito.verifyNoInteractions(mockBabelClient, mockBabelArtifactConverter); } private void setupValidModelQuerySpecMocks(ArtifactTestUtils artifactTestUtils, INotificationData data, @@ -282,10 +275,9 @@ public class TestArtifactDownloadManager { Mockito.verify(mockDistributionClient).download(serviceArtifact); Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, serviceArtifact); - Mockito.verify(mockBabelClient).postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(), - Matchers.anyString()); - Mockito.verify(mockBabelArtifactConverter).convertToModel(Matchers.any()); - Mockito.verify(mockBabelArtifactConverter).convertToCatalog(Matchers.any()); + Mockito.verify(mockBabelClient).postArtifact(any(), any()); + Mockito.verify(mockBabelArtifactConverter).convertToModel(any()); + Mockito.verify(mockBabelArtifactConverter).convertToCatalog(any()); Mockito.verify(mockDistributionClient).download(modelSpecArtifact); Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, @@ -295,7 +287,6 @@ public class TestArtifactDownloadManager { } @Test - @SuppressWarnings("unchecked") public void activateCallback_toscaToModelConverterHasProcessToscaArtifactsException() throws Exception { ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils(); INotificationData data = getNotificationDataWithToscaCsarFile(); @@ -304,11 +295,10 @@ public class TestArtifactDownloadManager { when(mockDistributionClient.download(artifactInfo)) .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null, artifactTestUtils.loadResource("compressedArtifacts/service-VscpaasTest-csar.csar"))); - when(mockBabelArtifactConverter.convertToModel(Mockito.anyList())) + when(mockBabelArtifactConverter.convertToModel(anyList())) .thenThrow(BabelArtifactParsingException.class); doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo); - when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(), - Matchers.anyString())).thenReturn(createBabelArtifacts()); + when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifacts()); List modelArtifacts = new ArrayList<>(); List catalogFiles = new ArrayList<>(); @@ -319,9 +309,8 @@ public class TestArtifactDownloadManager { Mockito.verify(mockDistributionClient).download(artifactInfo); Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo); - Mockito.verify(mockBabelClient).postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(), - Matchers.anyString()); - Mockito.verify(mockBabelArtifactConverter).convertToModel(Matchers.any()); + Mockito.verify(mockBabelClient).postArtifact(any(), any()); + Mockito.verify(mockBabelArtifactConverter).convertToModel(any()); } @Test @@ -339,7 +328,7 @@ public class TestArtifactDownloadManager { Mockito.verify(mockDistributionClient).download(artifact); Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact); Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact); - Mockito.verifyZeroInteractions(mockBabelClient, mockBabelArtifactConverter); + Mockito.verifyNoInteractions(mockBabelClient, mockBabelArtifactConverter); } private IDistributionClientDownloadResult createDistributionClientDownloadResult(