summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-03-26 11:28:49 +0100
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-03-26 11:28:49 +0100
commit19f034b2554895285f12979b0f36c1629f9af984 (patch)
tree21384448dfb9fd91a2cbb4d499897230e73c1bb7 /src/test
parent277fb3d9331b8a5c7fbdd8cf72cb623963a1ff4b (diff)
Use more dependency injection in model-loader
- use more dependency injection - make class variables final if possible - simplify mock creation in some tests using @Mock Issue-ID: AAI-3811 Change-Id: I7a7ccba02df78e6fd3bf082c23aac0968137661b Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java32
-rw-r--r--src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java76
-rw-r--r--src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java28
-rw-r--r--src/test/java/org/onap/aai/modelloader/notification/TestEventCallback.java28
-rw-r--r--src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java2
-rw-r--r--src/test/java/org/onap/aai/modelloader/service/TestModelController.java (renamed from src/test/java/org/onap/aai/modelloader/service/TestModelLoaderService.java)52
-rw-r--r--src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java3
7 files changed, 111 insertions, 110 deletions
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 1b8f33b..aa2d299 100644
--- a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java
+++ b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java
@@ -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,7 +35,9 @@ import java.util.Properties;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+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.entity.Artifact;
@@ -56,40 +57,29 @@ 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;
@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);
+ new ModelLoaderConfig(configProperties, "."), mockClientFactory, mockBabelArtifactConverter, mockNotificationPublisher, mockVnfCatalogExtractor);
}
@Test
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 2cac3c9..dfced1a 100644
--- a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java
+++ b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java
@@ -24,7 +24,6 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithCatalogFile;
import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneOfEach;
@@ -37,7 +36,9 @@ import java.util.Properties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+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.entity.Artifact;
@@ -50,7 +51,6 @@ import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
import org.onap.aai.modelloader.service.ArtifactDeploymentManager;
import org.onap.aai.modelloader.util.ArtifactTestUtils;
import org.onap.sdc.api.notification.INotificationData;
-import org.springframework.test.util.ReflectionTestUtils;
/**
* Tests {@link ArtifactDeploymentManager}.
@@ -63,28 +63,24 @@ public class TestArtifactDeploymentManager {
private Properties configProperties;
private ArtifactDeploymentManager manager;
- private ModelArtifactHandler mockModelArtifactHandler;
- private VnfCatalogArtifactHandler mockVnfCatalogArtifactHandler;
+ @Mock private ModelArtifactHandler modelArtifactHandlerMock;
+ @Mock private VnfCatalogArtifactHandler vnfCatalogArtifactHandlerMock;
@BeforeEach
public void setup() throws IOException {
+ MockitoAnnotations.openMocks(this);
configProperties = new Properties();
configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
- mockModelArtifactHandler = mock(ModelArtifactHandler.class);
- mockVnfCatalogArtifactHandler = mock(VnfCatalogArtifactHandler.class);
-
- manager = new ArtifactDeploymentManager(new ModelLoaderConfig(configProperties, null));
-
- ReflectionTestUtils.setField(manager, "modelArtifactHandler", mockModelArtifactHandler);
- ReflectionTestUtils.setField(manager, "vnfCatalogArtifactHandler", mockVnfCatalogArtifactHandler);
+ ModelLoaderConfig modelLoaderConfig = new ModelLoaderConfig(configProperties, null);
+ manager = new ArtifactDeploymentManager(modelLoaderConfig, modelArtifactHandlerMock, vnfCatalogArtifactHandlerMock);
}
@AfterEach
public void tearDown() {
configProperties = null;
- mockModelArtifactHandler = null;
- mockVnfCatalogArtifactHandler = null;
+ modelArtifactHandlerMock = null;
+ vnfCatalogArtifactHandlerMock = null;
manager = null;
}
@@ -95,18 +91,18 @@ public class TestArtifactDeploymentManager {
List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
- when(mockModelArtifactHandler.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
+ 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));
- Mockito.verify(mockModelArtifactHandler).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
+ Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
any());
- Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).pushArtifacts(eq(modelArtifacts),
+ Mockito.verify(vnfCatalogArtifactHandlerMock, Mockito.never()).pushArtifacts(eq(modelArtifacts),
eq(data.getDistributionID()), any(), any());
- Mockito.verify(mockModelArtifactHandler).rollback(eq(new ArrayList<Artifact>()), eq(data.getDistributionID()),
+ Mockito.verify(modelArtifactHandlerMock).rollback(eq(new ArrayList<Artifact>()), eq(data.getDistributionID()),
any());
- Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).rollback(eq(new ArrayList<Artifact>()),
+ Mockito.verify(vnfCatalogArtifactHandlerMock, Mockito.never()).rollback(eq(new ArrayList<Artifact>()),
eq(data.getDistributionID()), any());
}
@@ -129,19 +125,19 @@ public class TestArtifactDeploymentManager {
List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
- when(mockModelArtifactHandler.pushArtifacts(any(), any(), any(), any())).thenReturn(true);
- when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()), any(), any()))
+ when(modelArtifactHandlerMock.pushArtifacts(any(), any(), any(), any())).thenReturn(true);
+ 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));
- Mockito.verify(mockModelArtifactHandler).pushArtifacts(eq(new ArrayList<Artifact>()),
+ Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(new ArrayList<Artifact>()),
eq(data.getDistributionID()), any(), any());
- Mockito.verify(mockVnfCatalogArtifactHandler).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
+ Mockito.verify(vnfCatalogArtifactHandlerMock).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
any(), any());
- Mockito.verify(mockModelArtifactHandler).rollback(eq(new ArrayList<Artifact>()), eq(data.getDistributionID()),
+ Mockito.verify(modelArtifactHandlerMock).rollback(eq(new ArrayList<Artifact>()), eq(data.getDistributionID()),
any());
- Mockito.verify(mockVnfCatalogArtifactHandler).rollback(eq(new ArrayList<Artifact>()),
+ Mockito.verify(vnfCatalogArtifactHandlerMock).rollback(eq(new ArrayList<Artifact>()),
eq(data.getDistributionID()), any());
}
@@ -170,34 +166,34 @@ public class TestArtifactDeploymentManager {
List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
- when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()), any(), any()))
+ when(vnfCatalogArtifactHandlerMock.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()), any(), any()))
.thenReturn(catalogsDeployed);
- when(mockModelArtifactHandler.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
+ when(modelArtifactHandlerMock.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
.thenReturn(modelsDeployed);
assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data, modelArtifacts, catalogFiles), is(false));
// Catalog artifacts are only pushed if models are successful.
- Mockito.verify(mockModelArtifactHandler).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
+ Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
any());
if (modelsDeployed) {
- Mockito.verify(mockVnfCatalogArtifactHandler).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
+ Mockito.verify(vnfCatalogArtifactHandlerMock).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
any(), any());
}
if (modelsDeployed && catalogsDeployed) {
- Mockito.verify(mockModelArtifactHandler, Mockito.never()).rollback(any(), any(), any());
- Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).rollback(any(), any(), any());
+ Mockito.verify(modelArtifactHandlerMock, Mockito.never()).rollback(any(), any(), any());
+ Mockito.verify(vnfCatalogArtifactHandlerMock, Mockito.never()).rollback(any(), any(), any());
} else {
if (modelsDeployed) {
- Mockito.verify(mockModelArtifactHandler).rollback(eq(new ArrayList<Artifact>()),
+ Mockito.verify(modelArtifactHandlerMock).rollback(eq(new ArrayList<Artifact>()),
eq(data.getDistributionID()), any());
- Mockito.verify(mockVnfCatalogArtifactHandler).rollback(eq(new ArrayList<Artifact>()),
+ Mockito.verify(vnfCatalogArtifactHandlerMock).rollback(eq(new ArrayList<Artifact>()),
eq(data.getDistributionID()), any());
} else {
- Mockito.verify(mockModelArtifactHandler).rollback(eq(new ArrayList<Artifact>()),
+ Mockito.verify(modelArtifactHandlerMock).rollback(eq(new ArrayList<Artifact>()),
eq(data.getDistributionID()), any());
- Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).rollback(any(), any(), any());
+ Mockito.verify(vnfCatalogArtifactHandlerMock, Mockito.never()).rollback(any(), any(), any());
}
}
}
@@ -219,18 +215,18 @@ public class TestArtifactDeploymentManager {
List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
- when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()), any(), any()))
+ when(vnfCatalogArtifactHandlerMock.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()), any(), any()))
.thenReturn(true);
- when(mockModelArtifactHandler.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
+ when(modelArtifactHandlerMock.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
.thenReturn(true);
assertThat(manager.deploy(data, modelArtifacts, catalogFiles), is(true));
- Mockito.verify(mockVnfCatalogArtifactHandler).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
+ Mockito.verify(vnfCatalogArtifactHandlerMock).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
any(), any());
- Mockito.verify(mockModelArtifactHandler).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
+ Mockito.verify(modelArtifactHandlerMock).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
any());
- Mockito.verify(mockModelArtifactHandler, Mockito.never()).rollback(any(), any(), any());
- Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).rollback(any(), any(), any());
+ Mockito.verify(modelArtifactHandlerMock, Mockito.never()).rollback(any(), any(), any());
+ Mockito.verify(vnfCatalogArtifactHandlerMock, Mockito.never()).rollback(any(), any(), any());
}
}
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 561791b..c09eff5 100644
--- a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java
+++ b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDownloadManager.java
@@ -44,15 +44,17 @@ import org.hamcrest.collection.IsEmptyCollection;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+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.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;
@@ -60,7 +62,6 @@ 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}.
@@ -68,28 +69,23 @@ import org.springframework.test.util.ReflectionTestUtils;
public class TestArtifactDownloadManager {
private ArtifactDownloadManager downloadManager;
- private BabelServiceClient mockBabelClient;
- private IDistributionClient mockDistributionClient;
- private NotificationPublisher mockNotificationPublisher;
- private BabelArtifactConverter mockBabelArtifactConverter;
- private BabelServiceClientFactory mockClientFactory;
+ @Mock private BabelServiceClient mockBabelClient;
+ @Mock private IDistributionClient mockDistributionClient;
+ @Mock private NotificationPublisher mockNotificationPublisher;
+ @Mock private BabelArtifactConverter mockBabelArtifactConverter;
+ @Mock private BabelServiceClientFactory mockClientFactory;
+ 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);
+ 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);
-
- ReflectionTestUtils.setField(downloadManager, "notificationPublisher", mockNotificationPublisher);
- ReflectionTestUtils.setField(downloadManager, "babelArtifactConverter", mockBabelArtifactConverter);
+ new ModelLoaderConfig(configProperties, "."), mockClientFactory, mockBabelArtifactConverter, mockNotificationPublisher, vnfCatalogExtractor);
}
@AfterEach
diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestEventCallback.java b/src/test/java/org/onap/aai/modelloader/notification/TestEventCallback.java
index d9245d9..1073a61 100644
--- a/src/test/java/org/onap/aai/modelloader/notification/TestEventCallback.java
+++ b/src/test/java/org/onap/aai/modelloader/notification/TestEventCallback.java
@@ -21,7 +21,6 @@
package org.onap.aai.modelloader.notification;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -32,14 +31,14 @@ import java.util.Properties;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.mockito.Mock;
import org.mockito.Mockito;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
+import org.mockito.MockitoAnnotations;
import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
import org.onap.aai.modelloader.service.ArtifactDeploymentManager;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.notification.INotificationData;
-import org.springframework.test.util.ReflectionTestUtils;
/**
* Tests {@link EventCallback}.
@@ -48,36 +47,25 @@ public class TestEventCallback {
private static final String CONFIG_FILE = "model-loader.properties";
- private ModelLoaderConfig config;
private Properties configProperties;
private EventCallback eventCallback;
- private ArtifactDeploymentManager mockArtifactDeploymentManager;
- private ArtifactDownloadManager mockArtifactDownloadManager;
- private IDistributionClient mockDistributionClient;
- private NotificationPublisher mockNotificationPublisher;
+ @Mock private ArtifactDeploymentManager mockArtifactDeploymentManager;
+ @Mock private ArtifactDownloadManager mockArtifactDownloadManager;
+ @Mock private IDistributionClient mockDistributionClient;
+ @Mock private NotificationPublisher mockNotificationPublisher;
@BeforeEach
public void setup() throws IOException {
+ MockitoAnnotations.openMocks(this);
configProperties = new Properties();
configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
- config = new ModelLoaderConfig(configProperties, null);
- mockArtifactDeploymentManager = mock(ArtifactDeploymentManager.class);
- mockArtifactDownloadManager = mock(ArtifactDownloadManager.class);
- mockDistributionClient = mock(IDistributionClient.class);
- mockNotificationPublisher = mock(NotificationPublisher.class);
-
- eventCallback = new EventCallback(mockDistributionClient, config, null);
-
- ReflectionTestUtils.setField(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager);
- ReflectionTestUtils.setField(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager);
- ReflectionTestUtils.setField(eventCallback, "notificationPublisher", mockNotificationPublisher);
+ eventCallback = new EventCallback(mockDistributionClient, mockArtifactDeploymentManager, mockArtifactDownloadManager, mockNotificationPublisher);
}
@AfterEach
public void tearDown() {
- config = null;
configProperties = null;
eventCallback = null;
mockArtifactDeploymentManager = null;
diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java b/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java
index edf50a8..c4aa932 100644
--- a/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java
+++ b/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java
@@ -63,7 +63,7 @@ public class TestNotificationPublisher {
@BeforeEach
public void setupMocks() {
- MockitoAnnotations.initMocks(this);
+ MockitoAnnotations.openMocks(this);
when(client.getConfiguration()).thenReturn(config);
when(client.sendDownloadStatus(any())).thenReturn(clientResult);
when(client.sendComponentDoneStatus(any())).thenReturn(clientResult);
diff --git a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderService.java b/src/test/java/org/onap/aai/modelloader/service/TestModelController.java
index e58716c..9106342 100644
--- a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderService.java
+++ b/src/test/java/org/onap/aai/modelloader/service/TestModelController.java
@@ -22,16 +22,30 @@ package org.onap.aai.modelloader.service;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Base64;
+import java.util.Collections;
import javax.ws.rs.core.Response;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import org.onap.aai.modelloader.config.BeanConfig;
+import org.mockito.Mock;
+import org.onap.aai.modelloader.config.ModelLoaderConfig;
+import org.onap.aai.modelloader.extraction.VnfCatalogExtractor;
+import org.onap.aai.modelloader.notification.ArtifactDownloadManager;
+import org.onap.aai.modelloader.notification.BabelArtifactConverter;
+import org.onap.aai.modelloader.notification.EventCallback;
+import org.onap.aai.modelloader.notification.NotificationPublisher;
+import org.onap.aai.modelloader.restclient.BabelServiceClient;
+import org.onap.aai.modelloader.restclient.BabelServiceClientException;
import org.onap.aai.modelloader.util.ArtifactTestUtils;
+import org.onap.sdc.api.IDistributionClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
@@ -40,41 +54,59 @@ import org.springframework.test.context.TestPropertySource;
* Tests for the ModelLoaderService class.
*
*/
-@SpringBootTest(classes = {BeanConfig.class, ModelController.class, MockBabelServiceClientFactory.class})
+@SpringBootTest
@TestPropertySource(properties = {"CONFIG_HOME=src/test/resources",})
-public class TestModelLoaderService {
+public class TestModelController {
- @Autowired
- private ModelController service;
+ @Autowired IDistributionClient iDistributionClient;
+ @Autowired ModelLoaderConfig modelLoaderConfig;
+ @Autowired EventCallback eventCallback;
+ @Autowired ArtifactDeploymentManager artifactDeploymentManager;
+ @Autowired BabelArtifactConverter babelArtifactConverter;
+ @Autowired NotificationPublisher notificationPublisher;
+ @Autowired VnfCatalogExtractor vnfCatalogExtractor;
+
+ @Mock BabelServiceClientFactory clientFactory;
+ @Mock BabelServiceClient babelServiceClient;
+
+ private ModelController modelController;
+
+ @BeforeEach
+ public void init() throws BabelServiceClientException {
+ when(clientFactory.create(any())).thenReturn(babelServiceClient);
+ when(babelServiceClient.postArtifact(any(), any(), any(), any())).thenReturn(Collections.emptyList());
+ ArtifactDownloadManager artifactDownloadManager = new ArtifactDownloadManager(iDistributionClient, modelLoaderConfig, clientFactory, babelArtifactConverter, notificationPublisher, vnfCatalogExtractor);
+ this.modelController = new ModelController(iDistributionClient, modelLoaderConfig, eventCallback, artifactDeploymentManager, artifactDownloadManager);
+ }
@AfterEach
public void shutdown() {
- service.preShutdownOperations();
+ modelController.preShutdownOperations();
}
@Test
public void testLoadModel() {
- Response response = service.loadModel("");
+ Response response = modelController.loadModel("");
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
}
@Test
public void testSaveModel() {
- Response response = service.saveModel("", "");
+ Response response = modelController.saveModel("", "");
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
}
@Test
public void testIngestModel() throws IOException {
byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
- Response response = service.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
+ Response response = modelController.ingestModel("model-name", "", Base64.getEncoder().encodeToString(csarPayload));
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
}
@Test
public void testIngestModelMissingName() throws IOException {
byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
- Response response = service.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
+ Response response = modelController.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
}
diff --git a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java
index 0b68cc0..a8501be 100644
--- a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java
+++ b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderServiceWithSdc.java
@@ -30,7 +30,6 @@ import javax.ws.rs.core.Response;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
-import org.onap.aai.modelloader.config.BeanConfig;
import org.onap.aai.modelloader.util.ArtifactTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -40,7 +39,7 @@ import org.springframework.test.context.TestPropertySource;
* Tests for the ModelLoaderService class.
*
*/
-@SpringBootTest(classes = {BeanConfig.class, ModelController.class, HttpsBabelServiceClientFactory.class})
+@SpringBootTest
@TestPropertySource(properties = {"CONFIG_HOME=src/test/resources",})
public class TestModelLoaderServiceWithSdc {