Refactor Babel related code in model-loader
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / notification / ArtifactDownloadManagerVnfcTest.java
index 1b8f33b..a64c00c 100644 (file)
@@ -25,7 +25,6 @@ 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;
 
@@ -36,9 +35,12 @@ import java.util.Properties;
 
 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;
@@ -56,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;
 
     @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
@@ -99,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<Artifact> modelArtifacts = new ArrayList<>();
@@ -117,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<Artifact> modelArtifacts = new ArrayList<>();
@@ -135,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<Artifact> modelArtifacts = new ArrayList<>();
@@ -153,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);