X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fnotification%2FArtifactDownloadManagerVnfcTest.java;h=a64c00ce307df5f7e3eff5bfe18c5bf47e973352;hb=refs%2Fchanges%2F07%2F137707%2F6;hp=c0de0ee0619e37d576ca10a58ae17a59e4e0d23d;hpb=378fac344f2de5a89b5410b9031e76841cd8fba6;p=aai%2Fmodel-loader.git diff --git a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java index c0de0ee..a64c00c 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java @@ -21,11 +21,10 @@ package org.onap.aai.modelloader.notification; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; 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.getNotificationDataWithToscaCsarFile; @@ -33,11 +32,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.junit.Before; -import org.junit.Test; + +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.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.ArtifactType; import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifact; @@ -55,40 +58,30 @@ import org.onap.sdc.api.notification.INotificationData; import org.onap.sdc.api.results.IDistributionClientDownloadResult; import org.onap.sdc.impl.DistributionClientDownloadResultImpl; import org.onap.sdc.utils.DistributionActionResultEnum; -import org.springframework.test.util.ReflectionTestUtils; /** * Tests {@link ArtifactDownloadManager} with VNF Catalog Artifacts. */ public class ArtifactDownloadManagerVnfcTest { - private ArtifactDownloadManager downloadManager; - private BabelServiceClient mockBabelClient; - private IDistributionClient mockDistributionClient; - private NotificationPublisher mockNotificationPublisher; - private BabelArtifactConverter mockBabelArtifactConverter; - private BabelServiceClientFactory mockClientFactory; - private VnfCatalogExtractor mockVnfCatalogExtractor; + @Mock private ArtifactDownloadManager downloadManager; + @Mock private BabelServiceClient mockBabelClient; + @Mock private IDistributionClient mockDistributionClient; + @Mock private NotificationPublisher mockNotificationPublisher; + @Mock private BabelArtifactConverter mockBabelArtifactConverter; + @Mock private BabelServiceClientFactory mockClientFactory; + @Mock private VnfCatalogExtractor mockVnfCatalogExtractor; + @InjectMocks private BabelArtifactService babelArtifactService; - @Before + @BeforeEach public void setup() throws Exception { - mockBabelClient = mock(BabelServiceClient.class); - mockDistributionClient = mock(IDistributionClient.class); - mockNotificationPublisher = mock(NotificationPublisher.class); - mockBabelArtifactConverter = mock(BabelArtifactConverter.class); - mockClientFactory = mock(BabelServiceClientFactory.class); + MockitoAnnotations.openMocks(this); when(mockClientFactory.create(Mockito.any())).thenReturn(mockBabelClient); - mockVnfCatalogExtractor = mock(VnfCatalogExtractor.class); Properties configProperties = new Properties(); configProperties.load(this.getClass().getClassLoader().getResourceAsStream("model-loader.properties")); downloadManager = new ArtifactDownloadManager(mockDistributionClient, - new ModelLoaderConfig(configProperties, "."), mockClientFactory); - - - ReflectionTestUtils.setField(downloadManager, "notificationPublisher", mockNotificationPublisher); - ReflectionTestUtils.setField(downloadManager, "babelArtifactConverter", mockBabelArtifactConverter); - ReflectionTestUtils.setField(downloadManager, "vnfCatalogExtractor", mockVnfCatalogExtractor); + mockNotificationPublisher, mockVnfCatalogExtractor, babelArtifactService); } @Test @@ -98,7 +91,7 @@ public class ArtifactDownloadManagerVnfcTest { IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); setupValidDownloadCsarMocks(data, artifactInfo); - when(mockBabelClient.postArtifact(any(), any(), any(), any())).thenReturn(createBabelArtifacts()); + when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifacts()); when(mockVnfCatalogExtractor.extract(any(), any())).thenReturn(new ArrayList<>()); List modelArtifacts = new ArrayList<>(); @@ -106,7 +99,7 @@ public class ArtifactDownloadManagerVnfcTest { assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles), is(true)); - assertEquals("There should have been some catalog files", 2, catalogFiles.size()); + assertEquals(2, catalogFiles.size(), "There should have been some catalog files"); } @Test @@ -116,7 +109,7 @@ public class ArtifactDownloadManagerVnfcTest { IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); setupValidDownloadCsarMocks(data, artifactInfo); - when(mockBabelClient.postArtifact(any(), any(), any(), any())).thenReturn(createBabelArtifactsNoVnfc()); + when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifactsNoVnfc()); when(mockVnfCatalogExtractor.extract(any(), any())).thenReturn(createXmlVnfcArtifacts()); List modelArtifacts = new ArrayList<>(); @@ -124,7 +117,7 @@ public class ArtifactDownloadManagerVnfcTest { assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles), is(true)); - assertEquals("There should have been some catalog files", 3, catalogFiles.size()); + assertEquals(3, catalogFiles.size(), "There should have been some catalog files"); } @Test @@ -134,7 +127,7 @@ public class ArtifactDownloadManagerVnfcTest { IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); setupValidDownloadCsarMocks(data, artifactInfo); - when(mockBabelClient.postArtifact(any(), any(), any(), any())).thenReturn(createBabelArtifactsNoVnfc()); + when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifactsNoVnfc()); when(mockVnfCatalogExtractor.extract(any(), any())).thenReturn(new ArrayList<>()); List modelArtifacts = new ArrayList<>(); @@ -142,7 +135,7 @@ public class ArtifactDownloadManagerVnfcTest { assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles), is(true)); - assertEquals("There should not have been any catalog files", 0, catalogFiles.size()); + assertEquals(0, catalogFiles.size(), "There should not have been any catalog files"); } @Test @@ -152,7 +145,7 @@ public class ArtifactDownloadManagerVnfcTest { IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); setupValidDownloadCsarMocks(data, artifactInfo); - when(mockBabelClient.postArtifact(any(), any(), any(), any())).thenReturn(createBabelArtifacts()); + when(mockBabelClient.postArtifact(any(), any())).thenReturn(createBabelArtifacts()); when(mockVnfCatalogExtractor.extract(any(), any())).thenReturn(createXmlVnfcArtifacts()); doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);