import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
-import org.onap.aai.modelloader.notification.EventCallback;
-import org.onap.aai.modelloader.service.BabelServiceClientFactory;
import org.onap.aai.modelloader.service.ModelLoaderMsgs;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.impl.DistributionClientFactory;
public IDistributionClient iDistributionClient() {
return DistributionClientFactory.createDistributionClient();
}
-
- @Bean
- public EventCallback eventCallback(IDistributionClient client, ModelLoaderConfig config, BabelServiceClientFactory babelClientFactory) {
- return new EventCallback(client, config, babelClientFactory);
- }
}
import org.onap.aai.modelloader.restclient.AaiRestClient;\r
import org.onap.aai.modelloader.service.ModelLoaderMsgs;\r
import org.onap.aai.restclient.client.OperationResult;\r
+import org.springframework.stereotype.Component;\r
import org.w3c.dom.Document;\r
import org.w3c.dom.Element;\r
import org.w3c.dom.Node;\r
/**\r
* VNF Catalog specific handling\r
*/\r
+@Component\r
public class VnfCatalogArtifactHandler extends ArtifactHandler {\r
\r
private static Logger logger = LoggerFactory.getInstance().getLogger(VnfCatalogArtifactHandler.class.getName());\r
import org.onap.aai.modelloader.entity.ArtifactHandler;
import org.onap.aai.modelloader.restclient.AaiRestClient;
import org.onap.aai.modelloader.service.ModelLoaderMsgs;
+import org.springframework.stereotype.Service;
+@Service
public class ModelArtifactHandler extends ArtifactHandler {
private static Logger logger = LoggerFactory.getInstance().getLogger(ModelArtifactHandler.class.getName());
import org.onap.aai.modelloader.entity.ArtifactType;
import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifact;
import org.onap.aai.modelloader.service.ModelLoaderMsgs;
+import org.springframework.stereotype.Component;
/**
* A .csar file is a compressed archive like a zip file and this class will treat the byte array as it if were a zip
* file.
*/
+@Component
public class VnfCatalogExtractor {
private static final Logger logger = LoggerFactory.getInstance().getLogger(VnfCatalogExtractor.class.getName());
import org.onap.sdc.api.results.IDistributionClientDownloadResult;
import org.onap.sdc.utils.ArtifactTypeEnum;
import org.onap.sdc.utils.DistributionActionResultEnum;
+import org.springframework.stereotype.Component;
/**
* This class is responsible for downloading the artifacts from the ASDC.
*
* TOSCA_CSAR file artifacts will be converted into XML and returned as model artifacts.
*/
+@Component
public class ArtifactDownloadManager {
private static Logger logger = LoggerFactory.getInstance().getLogger(ArtifactDownloadManager.class);
- private IDistributionClient client;
- private NotificationPublisher notificationPublisher;
- private BabelArtifactConverter babelArtifactConverter;
- private ModelLoaderConfig config;
- private BabelServiceClientFactory clientFactory;
- private VnfCatalogExtractor vnfCatalogExtractor;
+ private final IDistributionClient client;
+ private final NotificationPublisher notificationPublisher;
+ private final BabelArtifactConverter babelArtifactConverter;
+ private final ModelLoaderConfig config;
+ private final BabelServiceClientFactory clientFactory;
+ private final VnfCatalogExtractor vnfCatalogExtractor;
public ArtifactDownloadManager(IDistributionClient client, ModelLoaderConfig config,
- BabelServiceClientFactory clientFactory) {
+ BabelServiceClientFactory clientFactory, BabelArtifactConverter babelArtifactConverter, NotificationPublisher notificationPublisher, VnfCatalogExtractor vnfCatalogExtractor) {
this.client = client;
+ this.notificationPublisher = notificationPublisher;
+ this.babelArtifactConverter = babelArtifactConverter;
this.config = config;
this.clientFactory = clientFactory;
+ this.vnfCatalogExtractor = vnfCatalogExtractor;
}
/**
IDistributionClientDownloadResult downloadResult = downloadIndividualArtifacts(data, artifact);
processDownloadedArtifacts(modelArtifacts, catalogArtifacts, artifact, downloadResult, data);
} catch (DownloadFailureException e) {
- getNotificationPublisher().publishDownloadFailure(client, data, artifact, e.getMessage());
+ notificationPublisher.publishDownloadFailure(client, data, artifact, e.getMessage());
success = false;
} catch (Exception e) {
- getNotificationPublisher().publishDeployFailure(client, data, artifact);
+ notificationPublisher.publishDeployFailure(client, data, artifact);
success = false;
}
if (DistributionActionResultEnum.SUCCESS.equals(downloadResult.getDistributionActionResult())) {
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Downloaded artifact: " + artifact.getArtifactName());
- getNotificationPublisher().publishDownloadSuccess(client, data, artifact);
+ notificationPublisher.publishDownloadSuccess(client, data, artifact);
} else {
throw new DownloadFailureException(downloadResult.getDistributionMessageResult());
}
invokeBabelService(modelArtifacts, catalogArtifacts, payload, artifactInfo, distributionId, serviceVersion);
// Get VNF Catalog artifacts directly from CSAR
- List<Artifact> csarCatalogArtifacts = getVnfCatalogExtractor().extract(payload, artifactInfo.getArtifactName());
+ List<Artifact> csarCatalogArtifacts = vnfCatalogExtractor.extract(payload, artifactInfo.getArtifactName());
// Throw an error if VNF Catalog data is present in the Babel payload and directly in the CSAR
if (!catalogArtifacts.isEmpty() && !csarCatalogArtifacts.isEmpty()) {
if (artifactMap.containsKey(BabelArtifact.ArtifactType.MODEL)) {
modelArtifacts.addAll(
- getBabelArtifactConverter().convertToModel(artifactMap.get(BabelArtifact.ArtifactType.MODEL)));
+ babelArtifactConverter.convertToModel(artifactMap.get(BabelArtifact.ArtifactType.MODEL)));
artifactMap.remove(BabelArtifact.ArtifactType.MODEL);
}
if (artifactMap.containsKey(BabelArtifact.ArtifactType.VNFCATALOG)) {
- catalogArtifacts.addAll(getBabelArtifactConverter()
+ catalogArtifacts.addAll(babelArtifactConverter
.convertToCatalog(artifactMap.get(BabelArtifact.ArtifactType.VNFCATALOG)));
artifactMap.remove(BabelArtifact.ArtifactType.VNFCATALOG);
}
private boolean parsedArtifactsExist(List<Artifact> parsedArtifacts) {
return parsedArtifacts != null && !parsedArtifacts.isEmpty();
}
-
- private NotificationPublisher getNotificationPublisher() {
- if (notificationPublisher == null) {
- notificationPublisher = new NotificationPublisher();
- }
-
- return notificationPublisher;
- }
-
- private BabelArtifactConverter getBabelArtifactConverter() {
- if (babelArtifactConverter == null) {
- babelArtifactConverter = new BabelArtifactConverter();
- }
-
- return babelArtifactConverter;
- }
-
- private VnfCatalogExtractor getVnfCatalogExtractor() {
- if (vnfCatalogExtractor == null) {
- vnfCatalogExtractor = new VnfCatalogExtractor();
- }
-
- return vnfCatalogExtractor;
- }
}
import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
import org.onap.aai.modelloader.entity.model.ModelArtifact;
import org.onap.aai.modelloader.entity.model.ModelArtifactParser;
+import org.springframework.stereotype.Component;
/**
* This class is responsible for converting TOSCA artifacts into instances of {@link ModelArtifact} ready for pushing
* the converted artifacts .
*/
-class BabelArtifactConverter {
+@Component
+public class BabelArtifactConverter {
/**
* This method converts BabelArtifacts into instances of {@link ModelArtifact}.
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.cl.mdc.MdcContext;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
import org.onap.aai.modelloader.entity.Artifact;
import org.onap.aai.modelloader.extraction.ArtifactInfoExtractor;
import org.onap.aai.modelloader.service.ArtifactDeploymentManager;
-import org.onap.aai.modelloader.service.BabelServiceClientFactory;
import org.onap.aai.modelloader.service.ModelLoaderMsgs;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.api.consumer.INotificationCallback;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
import org.slf4j.MDC;
+import org.springframework.stereotype.Component;
+@Component
public class EventCallback implements INotificationCallback {
private static Logger logger = LoggerFactory.getInstance().getLogger(EventCallback.class.getName());
private static Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(EventCallback.class.getName());
- private ArtifactDeploymentManager artifactDeploymentManager;
- private ArtifactDownloadManager artifactDownloadManager;
- private NotificationPublisher notificationPublisher;
- private IDistributionClient client;
- private ModelLoaderConfig config;
- private BabelServiceClientFactory babelServiceClientFactory;
+ private final ArtifactDeploymentManager artifactDeploymentManager;
+ private final ArtifactDownloadManager artifactDownloadManager;
+ private final NotificationPublisher notificationPublisher;
+ private final IDistributionClient client;
- public EventCallback(IDistributionClient client, ModelLoaderConfig config, BabelServiceClientFactory babelServiceClientFactory) {
+ public EventCallback(IDistributionClient client, ArtifactDeploymentManager artifactDeploymentManager, ArtifactDownloadManager artifactDownloadManager, NotificationPublisher notificationPublisher) {
+ this.artifactDeploymentManager = artifactDeploymentManager;
+ this.artifactDownloadManager = artifactDownloadManager;
+ this.notificationPublisher = notificationPublisher;
this.client = client;
- this.config = config;
- this.babelServiceClientFactory = babelServiceClientFactory;
}
@Override
List<Artifact> modelArtifacts = new ArrayList<>();
boolean success =
- getArtifactDownloadManager().downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts);
+ artifactDownloadManager.downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts);
if (success) {
- success = getArtifactDeploymentManager().deploy(data, modelArtifacts, catalogArtifacts);
+ success = artifactDeploymentManager.deploy(data, modelArtifacts, catalogArtifacts);
}
String statusString = success ? "SUCCESS" : "FAILURE";
boolean deploymentSuccess) {
if (deploymentSuccess) {
artifacts.stream().filter(a -> filterType.equalsIgnoreCase(a.getArtifactType()))
- .forEach(a -> getNotificationPublisher().publishDeploySuccess(client, data, a));
- getNotificationPublisher().publishComponentSuccess(client, data);
+ .forEach(a -> notificationPublisher.publishDeploySuccess(client, data, a));
+ notificationPublisher.publishComponentSuccess(client, data);
} else {
artifacts.stream().filter(a -> filterType.equalsIgnoreCase(a.getArtifactType()))
- .forEach(a -> getNotificationPublisher().publishDeployFailure(client, data, a));
- getNotificationPublisher().publishComponentFailure(client, data, "deploy failure");
+ .forEach(a -> notificationPublisher.publishDeployFailure(client, data, a));
+ notificationPublisher.publishComponentFailure(client, data, "deploy failure");
}
}
-
- private ArtifactDeploymentManager getArtifactDeploymentManager() {
- if (artifactDeploymentManager == null) {
- artifactDeploymentManager = new ArtifactDeploymentManager(config);
- }
-
- return artifactDeploymentManager;
- }
-
- private ArtifactDownloadManager getArtifactDownloadManager() {
- if (artifactDownloadManager == null) {
- artifactDownloadManager = new ArtifactDownloadManager(client, config, babelServiceClientFactory);
- }
-
- return artifactDownloadManager;
- }
-
-
- private NotificationPublisher getNotificationPublisher() {
- if (notificationPublisher == null) {
- notificationPublisher = new NotificationPublisher();
- }
-
- return notificationPublisher;
- }
}
import org.onap.sdc.api.results.IDistributionClientResult;
import org.onap.sdc.utils.DistributionActionResultEnum;
import org.onap.sdc.utils.DistributionStatusEnum;
+import org.springframework.stereotype.Component;
/**
* This class is responsible for publishing the status of actions performed working with artifacts.
*/
+@Component
public class NotificationPublisher {
private static Logger logger = LoggerFactory.getInstance().getLogger(NotificationPublisher.class);
MdcOverride override = new MdcOverride();
override.addAttribute(MdcContext.MDC_START_TIME, ZonedDateTime.now().format(formatter));
- WebResource webResource = client.resource(config.getBabelBaseUrl() + config.getBabelGenerateArtifactsUrl());
+ String resourceUrl = config.getBabelBaseUrl() + config.getBabelGenerateArtifactsUrl();
+ WebResource webResource = client.resource(resourceUrl);
ClientResponse response = webResource.type("application/json")
.header(AaiRestClient.HEADER_TRANS_ID, Collections.singletonList(transactionId))
.header(AaiRestClient.HEADER_FROM_APP_ID, Collections.singletonList(AaiRestClient.ML_APP_NAME))
import org.onap.aai.modelloader.entity.model.ModelArtifactHandler;
import org.onap.aai.modelloader.restclient.AaiRestClient;
import org.onap.sdc.api.notification.INotificationData;
+import org.springframework.stereotype.Component;
/**
* This class is responsible for deploying model and catalog artifacts.
*/
+@Component
public class ArtifactDeploymentManager {
- private ModelLoaderConfig config;
- private ModelArtifactHandler modelArtifactHandler;
- private VnfCatalogArtifactHandler vnfCatalogArtifactHandler;
+ private final ModelLoaderConfig config;
+ private final ModelArtifactHandler modelArtifactHandler;
+ private final VnfCatalogArtifactHandler vnfCatalogArtifactHandler;
- public ArtifactDeploymentManager(ModelLoaderConfig config) {
+ public ArtifactDeploymentManager(ModelLoaderConfig config, ModelArtifactHandler modelArtifactHandler, VnfCatalogArtifactHandler vnfCatalogArtifactHandler) {
this.config = config;
+ this.modelArtifactHandler = modelArtifactHandler;
+ this.vnfCatalogArtifactHandler = vnfCatalogArtifactHandler;
}
/**
List<Artifact> completedArtifacts = new ArrayList<>();
boolean deploySuccess =
- getModelArtifactHandler().pushArtifacts(modelArtifacts, distributionId, completedArtifacts, aaiClient);
+ modelArtifactHandler.pushArtifacts(modelArtifacts, distributionId, completedArtifacts, aaiClient);
if (!deploySuccess) {
- getModelArtifactHandler().rollback(completedArtifacts, distributionId, aaiClient);
+ modelArtifactHandler.rollback(completedArtifacts, distributionId, aaiClient);
} else {
List<Artifact> completedImageData = new ArrayList<>();
- deploySuccess = getVnfCatalogArtifactHandler().pushArtifacts(catalogArtifacts, distributionId,
+ deploySuccess = vnfCatalogArtifactHandler.pushArtifacts(catalogArtifacts, distributionId,
completedImageData, aaiClient);
if (!deploySuccess) {
- getModelArtifactHandler().rollback(completedArtifacts, distributionId, aaiClient);
- getVnfCatalogArtifactHandler().rollback(completedImageData, distributionId, aaiClient);
+ modelArtifactHandler.rollback(completedArtifacts, distributionId, aaiClient);
+ vnfCatalogArtifactHandler.rollback(completedImageData, distributionId, aaiClient);
}
}
return deploySuccess;
}
-
- private ModelArtifactHandler getModelArtifactHandler() {
- if (modelArtifactHandler == null) {
- modelArtifactHandler = new ModelArtifactHandler(config);
- }
-
- return modelArtifactHandler;
- }
-
- private VnfCatalogArtifactHandler getVnfCatalogArtifactHandler() {
- if (vnfCatalogArtifactHandler == null) {
- this.vnfCatalogArtifactHandler = new VnfCatalogArtifactHandler(config);
- }
-
- return vnfCatalogArtifactHandler;
- }
}
@RequestMapping("/services/model-loader/v1/model-service")
public class ModelController implements ModelLoaderInterface {
- private static final Logger logger = LoggerFactory.getInstance().getLogger(ModelController.class.getName());
+ private static final Logger logger = LoggerFactory.getInstance().getLogger(ModelController.class);
private final IDistributionClient client;
private final ModelLoaderConfig config;
private final EventCallback eventCallback;
- private final BabelServiceClientFactory babelClientFactory;
+ private final ArtifactDeploymentManager artifactDeploymentManager;
+ private final ArtifactDownloadManager artifactDownloadManager;
- public ModelController(IDistributionClient client, ModelLoaderConfig config, EventCallback eventCallback,
- BabelServiceClientFactory babelClientFactory) {
+ public ModelController(IDistributionClient client, ModelLoaderConfig config, EventCallback eventCallback, ArtifactDeploymentManager artifactDeploymentManager, ArtifactDownloadManager artifactDownloadManager) {
this.client = client;
this.config = config;
this.eventCallback = eventCallback;
- this.babelClientFactory = babelClientFactory;
+ this.artifactDeploymentManager = artifactDeploymentManager;
+ this.artifactDownloadManager = artifactDownloadManager;
}
/**
List<Artifact> modelArtifacts = new ArrayList<>();
List<Artifact> catalogArtifacts = new ArrayList<>();
- new ArtifactDownloadManager(client, config, babelClientFactory).processToscaArtifacts(modelArtifacts,
+ artifactDownloadManager.processToscaArtifacts(modelArtifacts,
catalogArtifacts, csarFile, artifactInfo, "test-transaction-id", modelVersion);
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Loading xml models from test artifacts: "
NotificationDataImpl notificationData = new NotificationDataImpl();
notificationData.setDistributionID("TestDistributionID");
boolean success =
- new ArtifactDeploymentManager(config).deploy(notificationData, modelArtifacts, catalogArtifacts);
+ artifactDeploymentManager.deploy(notificationData, modelArtifacts, catalogArtifacts);
logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Deployment success was " + success);
response = success ? Response.ok().build() : Response.serverError().build();
} catch (Exception e) {
private static final Logger logger = LoggerFactory.getInstance().getLogger(SdcConnectionJob.class.getName());
private final IDistributionClient client;
- private ModelLoaderConfig config;
- private EventCallback callback;
- private Timer timer;
+ private final ModelLoaderConfig config;
+ private final EventCallback callback;
+ private final Timer timer;
public SdcConnectionJob(IDistributionClient client, ModelLoaderConfig config, EventCallback callback, Timer timer) {
- super();
this.client = client;
this.timer = timer;
this.callback = callback;
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;
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.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
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;
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.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}.
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;
}
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());
}
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());
}
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());
}
}
}
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());
}
}
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;
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}.
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
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;
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}.
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;
@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);
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;
* 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()));
}
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;
* Tests for the ModelLoaderService class.
*
*/
-@SpringBootTest(classes = {BeanConfig.class, ModelController.class, HttpsBabelServiceClientFactory.class})
+@SpringBootTest
@TestPropertySource(properties = {"CONFIG_HOME=src/test/resources",})
public class TestModelLoaderServiceWithSdc {