diff options
author | mark.j.leonard <mark.j.leonard@gmail.com> | 2018-04-18 11:17:11 +0100 |
---|---|---|
committer | mark.j.leonard <mark.j.leonard@gmail.com> | 2018-04-18 11:22:16 +0100 |
commit | 3a1f764b762a91e917e9e14a00c4a7ff3c4e0745 (patch) | |
tree | eb00692e47f7a0924734dba87f4586a12488440e /src/main | |
parent | f43b8aa50bab706fdbf532a0603fd8b0df3d8fa0 (diff) |
Remove dependency on org.powermock (PowerMockito)
Replace use of PowerMockito packages with the standard Mockito.
Create a BabelServiceClient Factory class to simplify mocking.
Remove duplicated "no mock" test classes that were not in fact free of
mocking. Add a dummy sample CSAR file for testing of artifact downloads.
Change-Id: Ib86f560e514e1efab0e2f732e494a032d555c7c3
Issue-ID: AAI-1049
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/main')
5 files changed, 54 insertions, 14 deletions
diff --git a/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java b/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java index bdd101e..3fa0b40 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java +++ b/src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java @@ -26,7 +26,6 @@ import java.util.Base64; import java.util.List; import java.util.Map; import java.util.stream.Collectors; - import org.onap.aai.babel.service.data.BabelArtifact; import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType; import org.onap.aai.cl.api.Logger; @@ -40,6 +39,7 @@ import org.onap.aai.modelloader.entity.model.IModelParser; import org.onap.aai.modelloader.entity.model.NamedQueryArtifactParser; import org.onap.aai.modelloader.extraction.InvalidArchiveException; import org.onap.aai.modelloader.restclient.BabelServiceClient; +import org.onap.aai.modelloader.restclient.BabelServiceClientFactory; import org.onap.aai.modelloader.service.ModelLoaderMsgs; import org.openecomp.sdc.api.IDistributionClient; import org.openecomp.sdc.api.notification.IArtifactInfo; @@ -66,10 +66,13 @@ public class ArtifactDownloadManager { private NotificationPublisher notificationPublisher; private BabelArtifactConverter babelArtifactConverter; private ModelLoaderConfig config; + private BabelServiceClientFactory clientFactory; - public ArtifactDownloadManager(IDistributionClient client, ModelLoaderConfig config) { + public ArtifactDownloadManager(IDistributionClient client, ModelLoaderConfig config, + BabelServiceClientFactory clientFactory) { this.client = client; this.config = config; + this.clientFactory = clientFactory; } /** @@ -193,12 +196,12 @@ public class ArtifactDownloadManager { } } - private BabelServiceClient createBabelServiceClient(IArtifactInfo artifact, String serviceVersion) + BabelServiceClient createBabelServiceClient(IArtifactInfo artifact, String serviceVersion) throws ProcessToscaArtifactsException { BabelServiceClient babelClient; try { logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Creating Babel client"); - babelClient = new BabelServiceClient(config); + babelClient = clientFactory.create(config); } catch (Exception e) { logger.error(ModelLoaderMsgs.BABEL_REST_REQUEST_ERROR, e, "POST", config.getBabelBaseUrl(), "Error posting artifact " + artifact.getArtifactName() + " " + serviceVersion + " to Babel: " diff --git a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java index 827ff81..fe6bf7b 100644 --- a/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java +++ b/src/main/java/org/onap/aai/modelloader/notification/EventCallback.java @@ -28,6 +28,7 @@ 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.restclient.BabelServiceClientFactory; import org.onap.aai.modelloader.service.ModelLoaderMsgs; import org.openecomp.sdc.api.IDistributionClient; import org.openecomp.sdc.api.consumer.INotificationCallback; @@ -58,8 +59,8 @@ public class EventCallback implements INotificationCallback { List<Artifact> catalogArtifacts = new ArrayList<>(); List<Artifact> modelArtifacts = new ArrayList<>(); - boolean success = getArtifactDownloadManager() - .downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts); + boolean success = + getArtifactDownloadManager().downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts); if (success) { success = getArtifactDeploymentManager().deploy(data, artifacts, modelArtifacts, catalogArtifacts); @@ -75,13 +76,12 @@ public class EventCallback implements INotificationCallback { if (artifactDeploymentManager == null) { artifactDeploymentManager = new ArtifactDeploymentManager(client, config); } - return artifactDeploymentManager; } private ArtifactDownloadManager getArtifactDownloadManager() { if (artifactDownloadManager == null) { - artifactDownloadManager = new ArtifactDownloadManager(client, config); + artifactDownloadManager = new ArtifactDownloadManager(client, config, new BabelServiceClientFactory()); } return artifactDownloadManager; diff --git a/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java b/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java index 7d2ab09..28cd671 100644 --- a/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java +++ b/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java @@ -21,7 +21,6 @@ package org.onap.aai.modelloader.restclient; import com.sun.jersey.core.util.MultivaluedMapImpl; // NOSONAR -// import edu.emory.mathcs.backport.java.util.Collections; import java.io.IOException; import java.io.StringReader; import java.net.URI; @@ -91,7 +90,7 @@ public class AaiRestClient { * @return operation result */ public OperationResult putResource(String url, String payload, String transId, MediaType mediaType) { - logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload); + logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload); return setupClient().put(url, payload, buildHeaders(transId), mediaType, mediaType); } @@ -106,7 +105,7 @@ public class AaiRestClient { * @return ClientResponse */ public OperationResult postResource(String url, String payload, String transId, MediaType mediaType) { - logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload); + logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload); return setupClient().post(url, payload, buildHeaders(transId), mediaType, mediaType); } @@ -180,7 +179,6 @@ public class AaiRestClient { * @param transId * @return map of headers */ - @SuppressWarnings("unchecked") private Map<String, List<String>> buildHeaders(String transId) { MultivaluedMap<String, String> headers = new MultivaluedMapImpl(); headers.put(HEADER_TRANS_ID, Collections.singletonList(transId)); diff --git a/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java b/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java new file mode 100644 index 0000000..6ce4a60 --- /dev/null +++ b/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java @@ -0,0 +1,38 @@ +/** + * ============LICENSE_START========================================== + * org.onap.aai + * =================================================================== + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * =================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + */ +package org.onap.aai.modelloader.restclient; + +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import org.onap.aai.modelloader.config.ModelLoaderConfig; + +public class BabelServiceClientFactory { + + public BabelServiceClient create(ModelLoaderConfig config) throws UnrecoverableKeyException, KeyManagementException, + NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException { + return new BabelServiceClient(config); + } + +} diff --git a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java index aa3481c..a4cc5d1 100644 --- a/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java +++ b/src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java @@ -39,6 +39,7 @@ import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.notification.ArtifactDeploymentManager; import org.onap.aai.modelloader.notification.ArtifactDownloadManager; import org.onap.aai.modelloader.notification.EventCallback; +import org.onap.aai.modelloader.restclient.BabelServiceClientFactory; import org.openecomp.sdc.api.IDistributionClient; import org.openecomp.sdc.api.notification.IArtifactInfo; import org.openecomp.sdc.api.notification.INotificationData; @@ -196,8 +197,8 @@ public class ModelLoaderService implements ModelLoaderInterface { logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Generating xml models from test artifact"); - new ArtifactDownloadManager(client, config).processToscaArtifacts(modelArtifacts, catalogArtifacts, - csarFile, artifactInfo, "test-transaction-id", modelVersion); + new ArtifactDownloadManager(client, config, new BabelServiceClientFactory()).processToscaArtifacts( + modelArtifacts, catalogArtifacts, csarFile, artifactInfo, "test-transaction-id", modelVersion); List<IArtifactInfo> artifacts = new ArrayList<>(); artifacts.add(artifactInfo); |