package org.onap.aai.modelloader.notification;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.mock;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithCatalogFile;
import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneOfEach;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+
+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.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.entity.Artifact;
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}.
private Properties configProperties;
private ArtifactDeploymentManager manager;
- private ModelArtifactHandler mockModelArtifactHandler;
- private VnfCatalogArtifactHandler mockVnfCatalogArtifactHandler;
+ @Mock private ModelArtifactHandler modelArtifactHandlerMock;
+ @Mock private VnfCatalogArtifactHandler vnfCatalogArtifactHandlerMock;
- @Before
+ @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));
-
- Whitebox.setInternalState(manager, "modelArtifactHandler", mockModelArtifactHandler);
- Whitebox.setInternalState(manager, "vnfCatalogArtifactHandler", mockVnfCatalogArtifactHandler);
+ ModelLoaderConfig modelLoaderConfig = new ModelLoaderConfig(configProperties, null);
+ AaiRestClient aaiRestClient = new AaiRestClient(modelLoaderConfig, new RestTemplate());
+ manager = new ArtifactDeploymentManager(modelArtifactHandlerMock, vnfCatalogArtifactHandlerMock, aaiRestClient);
}
- @After
+ @AfterEach
public void tearDown() {
configProperties = null;
- mockModelArtifactHandler = null;
- mockVnfCatalogArtifactHandler = null;
+ modelArtifactHandlerMock = null;
+ vnfCatalogArtifactHandlerMock = null;
manager = null;
}
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<BabelArtifact> toscaArtifacts = setupTest(xml, data);
- List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+ BabelArtifact toscaArtifact = setupTest(xml, data);
+ List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
- 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));
+ assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data.getDistributionID(), 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());
}
- private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException {
- List<BabelArtifact> 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
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));
+ assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data.getDistributionID(), 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());
}
throws IOException, BabelArtifactParsingException, InvalidArchiveException {
INotificationData data = getNotificationDataWithOneOfEach();
byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
- List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
- List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+ BabelArtifact toscaArtifact = setupTest(xml, data);
+ List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
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));
+ assertThat(SHOULD_HAVE_RETURNED_FALSE, manager.deploy(data.getDistributionID(), 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());
}
}
}
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<BabelArtifact> toscaArtifacts = setupTest(xml, data);
- List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
+ BabelArtifact toscaArtifact = setupTest(xml, data);
+ List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
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));
+ assertThat(manager.deploy(data.getDistributionID(), 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());
}
}