summaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java10
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java14
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java180
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java17
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java91
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java25
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java40
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgBadRequestException.java43
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java253
9 files changed, 633 insertions, 40 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java
index 32c22356b3..84282e0c7f 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java
@@ -23,10 +23,13 @@ import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.util.ArrayList;
import java.util.Collection;
+import org.onap.so.adapters.vnfmadapter.converters.Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter;
import org.onap.so.adapters.vnfmadapter.oauth.OAuth2AccessTokenAdapter;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
@@ -38,6 +41,13 @@ import org.springframework.security.oauth2.common.OAuth2AccessToken;
public class MessageConverterConfiguration {
@Bean
+ public ConversionService conversionService() {
+ final DefaultConversionService service = new DefaultConversionService();
+ service.addConverter(new Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter());
+ return service;
+ }
+
+ @Bean
public HttpMessageConverters customConverters() {
final Collection<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
final Gson gson = new GsonBuilder()
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java
index 713bf01249..2a97bb47e4 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java
@@ -23,6 +23,7 @@ package org.onap.so.adapters.vnfmadapter;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
import org.onap.so.adapters.vnfmadapter.rest.Sol003PackageManagementController;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgBadRequestException;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgConflictException;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
import org.springframework.http.HttpStatus;
@@ -41,7 +42,7 @@ public class Sol003PackageManagementControllerExceptionHandler {
@ExceptionHandler(EtsiCatalogManagerRequestFailureException.class)
public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerRequestFailureException(
- EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) {
+ final EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) {
final ProblemDetails problemDetails = new ProblemDetails();
problemDetails.setDetail(etsiCatalogManagerRequestFailureException.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails);
@@ -49,7 +50,7 @@ public class Sol003PackageManagementControllerExceptionHandler {
@ExceptionHandler(VnfPkgConflictException.class)
public ResponseEntity<ProblemDetails> handleVnfPkgConflictException(
- VnfPkgConflictException vnfPkgConflictException) {
+ final VnfPkgConflictException vnfPkgConflictException) {
final ProblemDetails problemDetails = new ProblemDetails();
problemDetails.setDetail(vnfPkgConflictException.getMessage());
return ResponseEntity.status(HttpStatus.CONFLICT).body(problemDetails);
@@ -57,10 +58,17 @@ public class Sol003PackageManagementControllerExceptionHandler {
@ExceptionHandler(VnfPkgNotFoundException.class)
public ResponseEntity<ProblemDetails> handleVnfPkgNotFoundException(
- VnfPkgNotFoundException vnfPkgNotFoundException) {
+ final VnfPkgNotFoundException vnfPkgNotFoundException) {
final ProblemDetails problemDetails = new ProblemDetails();
problemDetails.setDetail(vnfPkgNotFoundException.getMessage());
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
}
+ @ExceptionHandler(VnfPkgBadRequestException.class)
+ public ResponseEntity<ProblemDetails> handleVnfPkgBadRequestException(
+ final VnfPkgBadRequestException vnfPkgBadRequestException) {
+ final ProblemDetails problemDetails = new ProblemDetails();
+ problemDetails.setDetail(vnfPkgBadRequestException.getMessage());
+ return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(problemDetails);
+ }
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java
new file mode 100644
index 0000000000..de18ecc43e
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.java
@@ -0,0 +1,180 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.converters;
+
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.*;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.convert.converter.Converter;
+import org.springframework.stereotype.Service;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Converter to convert from an Etsi Catalog Model {@link VnfPkgInfo} Object to a PackageManagement Model
+ * {@link InlineResponse2001} Object
+ *
+ * @author andrew.a.lamb@est.tech
+ */
+@Service
+public class Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter
+ implements Converter<VnfPkgInfo, InlineResponse2001> {
+ private static final Logger logger =
+ LoggerFactory.getLogger(Sol003EtsiVnfPkgInfoToPkgmInlineResponse2001Converter.class);
+
+ /**
+ * Convert a {@link VnfPkgInfo} Object to an {@link InlineResponse2001} Object
+ *
+ * @param vnfPkgInfo The VnfPkgInfo Object to Convert
+ * @return The Converted InlineResponse2001 Object
+ */
+ @Override
+ public InlineResponse2001 convert(final VnfPkgInfo vnfPkgInfo) {
+ if (vnfPkgInfo == null) {
+ logger.info("No VnfPkgInfo Object Provided for Conversion. (Null object received, returning Null)");
+ return null;
+ }
+ final InlineResponse2001 response = new InlineResponse2001();
+ response.setId(vnfPkgInfo.getId());
+ response.setVnfdId(vnfPkgInfo.getVnfdId());
+ response.setVnfProvider(vnfPkgInfo.getVnfProvider());
+ response.setVnfProductName(vnfPkgInfo.getVnfProductName());
+ response.setVnfSoftwareVersion(vnfPkgInfo.getVnfSoftwareVersion());
+ response.setVnfdVersion(vnfPkgInfo.getVnfdVersion());
+ response.setChecksum(convertChecksumToVnfPackagesChecksum(vnfPkgInfo.getChecksum()));
+ response.setSoftwareImages(
+ convertVnfPackageSoftwareImageInfoListToVnfPackagesSoftwareImagesList(vnfPkgInfo.getSoftwareImages()));
+ response.setAdditionalArtifacts(convertVnfPackageArtifactInfoListToVnfPackagesAdditionalArtifactsList(
+ vnfPkgInfo.getAdditionalArtifacts()));
+
+ if (vnfPkgInfo.getOnboardingState() != null) {
+ response.setOnboardingState(
+ InlineResponse2001.OnboardingStateEnum.fromValue(vnfPkgInfo.getOnboardingState().getValue()));
+ }
+
+ if (vnfPkgInfo.getOperationalState() != null) {
+ response.setOperationalState(
+ InlineResponse2001.OperationalStateEnum.fromValue(vnfPkgInfo.getOperationalState().getValue()));
+ }
+
+ response.setUserDefinedData((vnfPkgInfo.getUserDefinedData()));
+
+ if (vnfPkgInfo.getLinks() != null) {
+ response.setLinks(convertVNFPKGMLinkSerializerToVnfPackagesLinks(vnfPkgInfo.getLinks()));
+ }
+
+ return response;
+ }
+
+ private VnfPackagesChecksum convertChecksumToVnfPackagesChecksum(final Checksum checksum) {
+ final VnfPackagesChecksum vnfPackagesChecksum = new VnfPackagesChecksum();
+ if (checksum != null) {
+ vnfPackagesChecksum.setAlgorithm(checksum.getAlgorithm());
+ vnfPackagesChecksum.setHash(checksum.getHash());
+ }
+ return vnfPackagesChecksum;
+ }
+
+ private List<VnfPackagesSoftwareImages> convertVnfPackageSoftwareImageInfoListToVnfPackagesSoftwareImagesList(
+ final List<VnfPackageSoftwareImageInfo> vnfPackageSoftwareImageInfoList) {
+ final List<VnfPackagesSoftwareImages> vnfPackagesSoftwareImages = new ArrayList<>();
+ if (vnfPackageSoftwareImageInfoList != null) {
+ for (final VnfPackageSoftwareImageInfo vnfPackageSoftwareImageInfo : vnfPackageSoftwareImageInfoList) {
+ final VnfPackagesSoftwareImages softwareImage =
+ convertVnfPackageSoftwareImageInfoToVnfPackagesSoftwareImages(vnfPackageSoftwareImageInfo);
+ vnfPackagesSoftwareImages.add(softwareImage);
+ }
+ }
+ return vnfPackagesSoftwareImages;
+ }
+
+ private VnfPackagesSoftwareImages convertVnfPackageSoftwareImageInfoToVnfPackagesSoftwareImages(
+ final VnfPackageSoftwareImageInfo vnfPackageSoftwareImageInfo) {
+ final VnfPackagesSoftwareImages vnfPackagesSoftwareImages = new VnfPackagesSoftwareImages();
+ vnfPackagesSoftwareImages.setId(vnfPackageSoftwareImageInfo.getId());
+ vnfPackagesSoftwareImages.setName(vnfPackageSoftwareImageInfo.getName());
+ vnfPackagesSoftwareImages.setProvider(vnfPackageSoftwareImageInfo.getProvider());
+ vnfPackagesSoftwareImages.setVersion(vnfPackageSoftwareImageInfo.getVersion());
+ vnfPackagesSoftwareImages
+ .setChecksum(convertChecksumToVnfPackagesChecksum(vnfPackageSoftwareImageInfo.getChecksum()));
+ if (vnfPackageSoftwareImageInfo.getContainerFormat() != null) {
+ vnfPackagesSoftwareImages.setContainerFormat(VnfPackagesSoftwareImages.ContainerFormatEnum
+ .fromValue(vnfPackageSoftwareImageInfo.getContainerFormat().getValue()));
+ }
+
+ if (vnfPackageSoftwareImageInfo.getDiskFormat() != null) {
+ vnfPackagesSoftwareImages.setDiskFormat(VnfPackagesSoftwareImages.DiskFormatEnum
+ .fromValue(vnfPackageSoftwareImageInfo.getDiskFormat().getValue()));
+ }
+
+ vnfPackagesSoftwareImages.setCreatedAt(vnfPackageSoftwareImageInfo.getCreatedAt());
+ vnfPackagesSoftwareImages.setMinDisk(vnfPackageSoftwareImageInfo.getMinDisk());
+ vnfPackagesSoftwareImages.setMinRam(vnfPackageSoftwareImageInfo.getMinRam());
+ vnfPackagesSoftwareImages.setSize(vnfPackageSoftwareImageInfo.getSize());
+ vnfPackagesSoftwareImages.setUserMetadata(vnfPackageSoftwareImageInfo.getUserMetadata());
+ vnfPackagesSoftwareImages.setImagePath(vnfPackageSoftwareImageInfo.getImagePath());
+ return vnfPackagesSoftwareImages;
+ }
+
+ private List<VnfPackagesAdditionalArtifacts> convertVnfPackageArtifactInfoListToVnfPackagesAdditionalArtifactsList(
+ final List<VnfPackageArtifactInfo> vnfPackageArtifactInfoList) {
+ if (vnfPackageArtifactInfoList != null) {
+ final List<VnfPackagesAdditionalArtifacts> additionalArtifacts = new ArrayList<>();
+ for (final VnfPackageArtifactInfo artifactInfo : vnfPackageArtifactInfoList) {
+ final VnfPackagesAdditionalArtifacts artifact =
+ convertVnfPackageArtifactInfoToVnfPackagesAdditionalArtifacts(artifactInfo);
+ additionalArtifacts.add(artifact);
+ }
+ return additionalArtifacts;
+ }
+ return null;
+ }
+
+ private VnfPackagesAdditionalArtifacts convertVnfPackageArtifactInfoToVnfPackagesAdditionalArtifacts(
+ final VnfPackageArtifactInfo vnfPackageArtifactInfo) {
+ final VnfPackagesAdditionalArtifacts vnfPackagesAdditionalArtifacts = new VnfPackagesAdditionalArtifacts();
+ vnfPackagesAdditionalArtifacts.setArtifactPath(vnfPackageArtifactInfo.getArtifactPath());
+ vnfPackagesAdditionalArtifacts
+ .setChecksum(convertChecksumToVnfPackagesChecksum(vnfPackageArtifactInfo.getChecksum()));
+ vnfPackagesAdditionalArtifacts.setMetadata(vnfPackageArtifactInfo.getMetadata());
+ return vnfPackagesAdditionalArtifacts;
+ }
+
+ private VnfPackagesLinks convertVNFPKGMLinkSerializerToVnfPackagesLinks(
+ final VNFPKGMLinkSerializer vnfpkgmLinkSerializer) {
+ final VnfPackagesLinks vnfPackagesLinks = new VnfPackagesLinks();
+ vnfPackagesLinks.setSelf(convertUriLinkToVnfPackagesLinksSelf(vnfpkgmLinkSerializer.getSelf()));
+ vnfPackagesLinks.setVnfd(convertUriLinkToVnfPackagesLinksSelf(vnfpkgmLinkSerializer.getVnfd()));
+ vnfPackagesLinks
+ .setPackageContent(convertUriLinkToVnfPackagesLinksSelf(vnfpkgmLinkSerializer.getPackageContent()));
+ return vnfPackagesLinks;
+ }
+
+ private VnfPackagesLinksSelf convertUriLinkToVnfPackagesLinksSelf(final UriLink uriLink) {
+ final VnfPackagesLinksSelf vnfPackagesLinksSelf = new VnfPackagesLinksSelf();
+ if (uriLink != null) {
+ vnfPackagesLinksSelf.setHref(uriLink.getHref());
+ }
+ return vnfPackagesLinksSelf;
+ }
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
index 39efc8dc23..a73958e544 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
@@ -20,6 +20,7 @@
package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
import java.util.Optional;
/**
@@ -35,7 +36,21 @@ public interface EtsiCatalogServiceProvider {
* @param vnfPkgId The ID of the VNF Package from which the "package_content" will be retrieved.
* @return The Package Content of a VNF Package ("vnfPkgId").
*/
-
Optional<byte[]> getVnfPackageContent(final String vnfPkgId);
+ /**
+ * GET VNF packages information from ETSI Catalog. Will return zero or more VNF package representations.
+ *
+ * @return An Array of all VNF packages retrieved from the ETSI Catalog.
+ */
+ Optional<InlineResponse2001[]> getVnfPackages();
+
+ /**
+ * GET specific VNF package information from ETSI Catalog.
+ *
+ * @param vnfPkgId The ID of the VNF Package that you want to query.
+ * @return The VNF package retrieved from the ETSI Catalog
+ */
+ Optional<InlineResponse2001> getVnfPackage(final String vnfPkgId);
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
index 9a59620993..96b01f04e4 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
@@ -21,16 +21,21 @@
package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog;
import java.util.Optional;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPkgInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgBadRequestException;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgConflictException;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
import org.onap.so.rest.exceptions.HttpResouceNotFoundException;
+import org.onap.so.rest.exceptions.InvalidRestRequestException;
import org.onap.so.rest.exceptions.RestProcessingException;
import org.onap.so.rest.service.HttpRestServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.core.convert.ConversionService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@@ -44,31 +49,34 @@ import org.springframework.stereotype.Service;
public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvider {
private static final Logger logger = LoggerFactory.getLogger(EtsiCatalogServiceProviderImpl.class);
- @Qualifier
+ @Qualifier("etsiCatalogServiceProvider")
private final HttpRestServiceProvider httpServiceProvider;
private final EtsiCatalogUrlProvider etsiCatalogUrlProvider;
+ private final ConversionService conversionService;
@Autowired
public EtsiCatalogServiceProviderImpl(final EtsiCatalogUrlProvider etsiCatalogUrlProvider,
- final HttpRestServiceProvider httpServiceProvider) {
+ final HttpRestServiceProvider httpServiceProvider, final ConversionService conversionService) {
this.etsiCatalogUrlProvider = etsiCatalogUrlProvider;
this.httpServiceProvider = httpServiceProvider;
+ this.conversionService = conversionService;
}
@Override
- public Optional<byte[]> getVnfPackageContent(String vnfPkgId) throws EtsiCatalogManagerRequestFailureException {
+ public Optional<byte[]> getVnfPackageContent(final String vnfPkgId)
+ throws EtsiCatalogManagerRequestFailureException {
try {
- ResponseEntity<byte[]> response = httpServiceProvider
+ final ResponseEntity<byte[]> response = httpServiceProvider
.getHttpResponse(etsiCatalogUrlProvider.getVnfPackageContentUrl(vnfPkgId), byte[].class);
logger.info("getVnfPackageContent Request to ETSI Catalog Manager Status Code: {}",
response.getStatusCodeValue());
if (response.getStatusCode() == HttpStatus.OK) {
return Optional.ofNullable(response.getBody());
}
- } catch (HttpResouceNotFoundException httpResouceNotFoundException) {
+ } catch (final HttpResouceNotFoundException httpResouceNotFoundException) {
logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException);
throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId);
- } catch (RestProcessingException restProcessingException) {
+ } catch (final RestProcessingException restProcessingException) {
logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
restProcessingException);
if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) {
@@ -78,4 +86,75 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide
}
throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.");
}
+
+ @Override
+ public Optional<InlineResponse2001[]> getVnfPackages() {
+ try {
+ final ResponseEntity<VnfPkgInfo[]> response =
+ httpServiceProvider.getHttpResponse(etsiCatalogUrlProvider.getVnfPackagesUrl(), VnfPkgInfo[].class);
+ logger.info("getVnfPackages Request to ETSI Catalog Manager Status Code: {}",
+ response.getStatusCodeValue());
+ if (response.getStatusCode() == HttpStatus.OK) {
+ if (response.hasBody()) {
+ final VnfPkgInfo[] vnfPackages = response.getBody();
+ final InlineResponse2001[] responses = new InlineResponse2001[vnfPackages.length];
+ for (int index = 0; index < vnfPackages.length; index++) {
+ if (conversionService.canConvert(vnfPackages[index].getClass(), InlineResponse2001.class)) {
+ final InlineResponse2001 inlineResponse2001 =
+ conversionService.convert(vnfPackages[index], InlineResponse2001.class);
+ if (inlineResponse2001 != null) {
+ responses[index] = inlineResponse2001;
+ }
+ }
+ logger.error("Unable to find Converter for response class: {}", vnfPackages[index].getClass());
+ }
+ return Optional.ofNullable(responses);
+ }
+ logger.error("Received response without body ...");
+ }
+ logger.error("Unexpected status code received {}", response.getStatusCode());
+ return Optional.empty();
+ } catch (final InvalidRestRequestException invalidRestRequestException) {
+ logger.error("Caught InvalidRestRequestException", invalidRestRequestException);
+ throw new VnfPkgBadRequestException("Error: Bad Request Received");
+ } catch (final HttpResouceNotFoundException httpResouceNotFoundException) {
+ logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException);
+ throw new VnfPkgNotFoundException("No Vnf Packages found");
+ } catch (final RestProcessingException restProcessingException) {
+ logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
+ restProcessingException);
+ throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.");
+ }
+ }
+
+ @Override
+ public Optional<InlineResponse2001> getVnfPackage(final String vnfPkgId) {
+ try {
+ final ResponseEntity<VnfPkgInfo> response = httpServiceProvider
+ .getHttpResponse(etsiCatalogUrlProvider.getVnfPackageUrl(vnfPkgId), VnfPkgInfo.class);
+ logger.info("getVnfPackage Request for vnfPkgId {} to ETSI Catalog Manager Status Code: {}", vnfPkgId,
+ response.getStatusCodeValue());
+ if (response.getStatusCode() == HttpStatus.OK) {
+ if (response.hasBody()) {
+ final VnfPkgInfo vnfPkgInfo = response.getBody();
+ if (conversionService.canConvert(vnfPkgInfo.getClass(), InlineResponse2001.class)) {
+ return Optional.ofNullable(conversionService.convert(vnfPkgInfo, InlineResponse2001.class));
+ }
+ logger.error("Unable to find Converter for response class: {}", vnfPkgInfo.getClass());
+ }
+ logger.error("Received response without body ....");
+ }
+ return Optional.empty();
+ } catch (final InvalidRestRequestException invalidRestRequestException) {
+ logger.error("Caught InvalidRestRequestException", invalidRestRequestException);
+ throw new VnfPkgBadRequestException("Error: Bad Request Received");
+ } catch (final HttpResouceNotFoundException httpResouceNotFoundException) {
+ logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException);
+ throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId);
+ } catch (final RestProcessingException restProcessingException) {
+ logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
+ restProcessingException);
+ throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.");
+ }
+ }
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java
index e8188b9c7d..d233c3f0fd 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java
@@ -50,10 +50,33 @@ public class EtsiCatalogUrlProvider {
* @param vnfPkgId The ID of the VNF Package
* @return the URL for the GET operation
*/
-
public String getVnfPackageContentUrl(final String vnfPkgId) {
final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages/" + vnfPkgId + "/package_content";
logger.info("getEtsiCatalogVnfPackageContentUrl: {}", url);
return url;
}
+
+ /**
+ * Get the URL for retrieving VNF packages information from ETSI Catalog.".
+ *
+ * @return the URL for the GET operation
+ */
+ public String getVnfPackagesUrl() {
+ final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages";
+ logger.info("getEtsiCatalogVnfPackagesEndpoint: {}", url);
+ return url;
+ }
+
+ /**
+ * Get the URL for retrieving specific VNF package information from the ETSI Catalog.".
+ *
+ * @param vnfPkgId The ID of the VNF Package
+ * @return the URL for the GET operation
+ */
+ public String getVnfPackageUrl(final String vnfPkgId) {
+ final String url = msbEndpoint + vnfpkgmServiceUrl + "/vnf_packages/" + vnfPkgId;
+ logger.info("getEtsiCatalogVnfPackageEndpoint: {}", url);
+ return url;
+ }
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
index e12729a2e3..76ec492bd4 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java
@@ -23,7 +23,6 @@ package org.onap.so.adapters.vnfmadapter.rest;
import static org.onap.so.adapters.vnfmadapter.Constants.APPLICATION_ZIP;
import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
import static org.slf4j.LoggerFactory.getLogger;
-import java.util.List;
import java.util.Optional;
import javax.ws.rs.core.MediaType;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.EtsiCatalogServiceProvider;
@@ -50,40 +49,55 @@ import org.springframework.web.bind.annotation.RequestMapping;
public class Sol003PackageManagementController {
private final EtsiCatalogServiceProvider etsiCatalogServiceProvider;
+ private static final String LOG_REQUEST_RECEIVED = "VNF PackageManagement Controller: {} {} {}";
+ private static final Logger logger = getLogger(Sol003PackageManagementController.class);
@Autowired
Sol003PackageManagementController(final EtsiCatalogServiceProvider etsiCatalogServiceProvider) {
this.etsiCatalogServiceProvider = etsiCatalogServiceProvider;
}
-
- private static final String LOG_REQUEST_RECEIVED = "VNF PackageManagement Controller: {} {} {}";
- private static final Logger logger = getLogger(Sol003PackageManagementController.class);
-
/**
* GET VNF packages information. Will return zero or more VNF package representations that match the attribute
* filter. These representations will be in a list. Section Number: 10.4.2
*
- * @return A List of all VNF packages. Object: List<InlineResponse2001> Response Code: 200 OK
+ * @return An Array of all VNF packages. Object: InlineResponse2001[] Response Code: 200 OK
*/
-
@GetMapping(value = "/vnf_packages", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- public ResponseEntity<List<InlineResponse2001>> getVnfPackages() {
+ public ResponseEntity getVnfPackages() {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackages.");
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ final Optional<InlineResponse2001[]> response = etsiCatalogServiceProvider.getVnfPackages();
+ if (response.isPresent()) {
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackages Response: ", HttpStatus.OK);
+ return new ResponseEntity(response.get(), HttpStatus.OK);
+ }
+ final String errorMessage = "An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" \n"
+ + "endpoint.";
+ logger.error(errorMessage);
+ return new ResponseEntity(buildProblemDetails(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
* GET VNF package information. Will return a specific VNF package representation that match the attribute filter.
* Section Number: 10.4.3
- *
+ *
* @param vnfPkgId The ID of the VNF Package that you want to query.
* @return A VNF package based on vnfPkgId. Object: VnfPkgInfo Response Code: 200 OK
*/
@GetMapping(value = "/vnf_packages/{vnfPkgId}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
- public ResponseEntity<InlineResponse2001> getVnfPackage(@PathVariable("vnfPkgId") final String vnfPkgId) {
+ public ResponseEntity getVnfPackage(@PathVariable("vnfPkgId") final String vnfPkgId) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackage: ", vnfPkgId);
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ final Optional<InlineResponse2001> response = etsiCatalogServiceProvider.getVnfPackage(vnfPkgId);
+ if (response.isPresent()) {
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackage Response: ", HttpStatus.OK);
+ return new ResponseEntity(response.get(), HttpStatus.OK);
+ }
+ final String errorMessage = "An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" by vnfPkgId: \""
+ + vnfPkgId + "\" \n" + "endpoint.";
+ logger.error(errorMessage);
+ return new ResponseEntity(buildProblemDetails(errorMessage), HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
@@ -144,7 +158,7 @@ public class Sol003PackageManagementController {
* @param detail The error message retrieved from the exception thrown.
* @return ProblemDetails Object, containing error information.
*/
- private ProblemDetails buildProblemDetails(String detail) {
+ private ProblemDetails buildProblemDetails(final String detail) {
final ProblemDetails problemDetails = new ProblemDetails();
problemDetails.setDetail(detail);
return problemDetails;
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgBadRequestException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgBadRequestException.java
new file mode 100644
index 0000000000..211131c2a4
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgBadRequestException.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.adapters.vnfmadapter.rest.exceptions;
+
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+/**
+ * Exception for a Vnfpkg Bad Request failure, due to state of resource.
+ *
+ * @author andrew.a.lamb@est.tech
+ */
+@ResponseStatus(code = HttpStatus.BAD_REQUEST)
+public class VnfPkgBadRequestException extends RuntimeException {
+
+ private static final long serialVersionUID = 3301317418914258411L;
+
+ public VnfPkgBadRequestException(final String message) {
+ super(message);
+ }
+
+ @Override
+ public synchronized Throwable fillInStackTrace() {
+ return this;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java
index 59dfd50b32..857bd7dc3e 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java
@@ -20,21 +20,22 @@
package org.onap.so.adapters.vnfmadapter.rest;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Random;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication;
-import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.*;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,6 +53,7 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
+import com.google.gson.Gson;
/**
* @author gareth.roper@est.tech
@@ -81,16 +83,27 @@ public class Sol003PackageManagementControllerTest {
private static final String MSB_BASE_URL = "http://msb_iag.onap:80/api/vnfpkgm/v1/vnf_packages";
private static final String VNFPKGM_BASE_URL = PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages";
private static final String localhostUrl = "http://localhost:";
+ private static final String GET_VNF_PACKAGES_URL = "";
+ private static final String GET_VNF_PACKAGE_BY_ID_URL = "/" + VNF_PACKAGE_ID;
+ private static final String VNFD_ID = "vnfdId";
+ private static final String VNF_PROVIDER = "vnfProvider";
+ private static final String VNF_PRODUCT_NAME = "vnfProductName";
+ private static final String VNF_SOFTWARE_VERSION = "vnfSoftwareVersion";
+ private static final String VNFD_VERSION = "vnfdVersion";
+ private static final String ALGORITHM = "algorithm";
+ private static final String HASH = "hash";
+ private static final String URI_HREF = "uriHref";
private MockRestServiceServer mockRestServer;
private BasicHttpHeadersProvider basicHttpHeadersProvider;
-
+ private final Gson gson = new Gson();
public Sol003PackageManagementControllerTest() {}
@Before
public void setUp() {
- MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(testRestTemplate);
+ final MockRestServiceServer.MockRestServiceServerBuilder builder =
+ MockRestServiceServer.bindTo(testRestTemplate);
builder.ignoreExpectOrder(true);
mockRestServer = builder.build();
basicHttpHeadersProvider = new BasicHttpHeadersProvider();
@@ -98,7 +111,7 @@ public class Sol003PackageManagementControllerTest {
@Test
public void testGetPackageContent_ValidArray_Success() {
- byte[] responseArray = buildByteArrayWithRandomData(10);
+ final byte[] responseArray = buildByteArrayWithRandomData(10);
mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
.andExpect(method(HttpMethod.GET))
@@ -193,20 +206,171 @@ public class Sol003PackageManagementControllerTest {
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
}
- // The below 4 test methods are here to improve code coverage and provide a foundation for writing future tests
@Test
- public void testGetVnfPackage_Not_Implemented() {
- final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ public void testVnfPackagesReceivedAsInlineResponse2001ListIfGetVnfPackagesSuccessful() {
+ final VnfPkgInfo[] responses = createVnfPkgArray();
+
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(responses), MediaType.APPLICATION_JSON));
+
+ final String testURL = localhostUrl + port + VNFPKGM_BASE_URL;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+
+ final ResponseEntity<InlineResponse2001[]> responseEntity = restTemplate.withBasicAuth("test", "test")
+ .exchange(testURL, HttpMethod.GET, request, InlineResponse2001[].class);
+
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final InlineResponse2001[] inlineResponse2001array = responseEntity.getBody();
+ final InlineResponse2001 inlineResponse2001 = inlineResponse2001array[0];
+ assertEquals(VNF_PACKAGE_ID, inlineResponse2001.getId());
+ assertEquals(VNFD_ID, inlineResponse2001.getVnfdId());
+ assertEquals(VNFD_ID, inlineResponse2001.getSoftwareImages().get(0).getId());
+ assertEquals(VNF_PRODUCT_NAME, inlineResponse2001.getSoftwareImages().get(0).getName());
+ assertEquals(ALGORITHM, inlineResponse2001.getChecksum().getAlgorithm());
+ assertEquals(HASH, inlineResponse2001.getChecksum().getHash());
+ assertEquals(ARTIFACT_PATH, inlineResponse2001.getAdditionalArtifacts().get(0).getArtifactPath());
+ assertEquals(ALGORITHM, inlineResponse2001.getAdditionalArtifacts().get(0).getChecksum().getAlgorithm());
+ assertEquals(HASH, inlineResponse2001.getAdditionalArtifacts().get(0).getChecksum().getHash());
+ assertEquals(URI_HREF, inlineResponse2001.getLinks().getSelf().getHref());
}
@Test
- public void testGetVnfPackages_Not_Implemented() {
- final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest("");
- assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ public void test400BadRequestInfoReceivedAsProblemDetailsIfGetVnfPackagesIs400BadRequest() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL);
+ assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("Error: Bad Request Received", problemDetails.getDetail());
+ }
+
+ @Test
+ public void test404NotFoundInfoReceivedAsProblemDetailsIfGetVnfPackagesIs404NotFound() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL);
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("No Vnf Packages found", problemDetails.getDetail());
+ }
+
+ @Test
+ public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackagesReturns500InternalServerError() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("Internal Server Error Occurred.", problemDetails.getDetail());
+ }
+
+ @Test
+ public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackagesReturnsANullPackage() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET)).andRespond(withSuccess());
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" \n"
+ + "endpoint.", problemDetails.getDetail());
+ }
+
+ @Test
+ public void testVnfPackageReceivedAsInlineResponse2001IfGetVnfPackageByIdSuccessful() {
+ final VnfPkgInfo response = createVnfPkgInfo(VNF_PACKAGE_ID);
+
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(response), MediaType.APPLICATION_JSON));
+
+ final String testURL = localhostUrl + port + VNFPKGM_BASE_URL + "/" + VNF_PACKAGE_ID;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<InlineResponse2001> responseEntity = restTemplate.withBasicAuth("test", "test")
+ .exchange(testURL, HttpMethod.GET, request, InlineResponse2001.class);
+
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final InlineResponse2001 inlineResponse2001 = responseEntity.getBody();
+ assertEquals(VNF_PACKAGE_ID, inlineResponse2001.getId());
+ assertEquals(VNFD_ID, inlineResponse2001.getVnfdId());
+ assertEquals(VNFD_ID, inlineResponse2001.getSoftwareImages().get(0).getId());
+ assertEquals(VNF_PRODUCT_NAME, inlineResponse2001.getSoftwareImages().get(0).getName());
+ assertEquals(ALGORITHM, inlineResponse2001.getChecksum().getAlgorithm());
+ assertEquals(HASH, inlineResponse2001.getChecksum().getHash());
+ assertEquals(ARTIFACT_PATH, inlineResponse2001.getAdditionalArtifacts().get(0).getArtifactPath());
+ assertEquals(ALGORITHM, inlineResponse2001.getAdditionalArtifacts().get(0).getChecksum().getAlgorithm());
+ assertEquals(HASH, inlineResponse2001.getAdditionalArtifacts().get(0).getChecksum().getHash());
+ assertEquals(URI_HREF, inlineResponse2001.getLinks().getSelf().getHref());
+ }
+
+ @Test
+ public void test400BadRequestInfoReceivedAsProblemDetailsIfGetVnfPackageByIdIs400BadRequest() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL);
+
+ assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("Error: Bad Request Received", problemDetails.getDetail());
+ }
+
+ @Test
+ public void test404NotFoundInfoReceivedAsProblemDetailsIfGetVnfPackageByIdIs404NotFound() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL);
+
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("No Vnf Package found with vnfPkgId: " + VNF_PACKAGE_ID, problemDetails.getDetail());
+ }
+
+ @Test
+ public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackageByIdReturns500InternalServerError() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("Internal Server Error Occurred.", problemDetails.getDetail());
}
@Test
+ public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackageByIdReturnsANullPackage() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess());
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+
+ assertNotNull(responseEntity.getBody());
+ final ProblemDetails problemDetails = responseEntity.getBody();
+ assertEquals("An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" by vnfPkgId: \""
+ + VNF_PACKAGE_ID + "\" \n" + "endpoint.", problemDetails.getDetail());
+ }
+
+ // The below 2 test methods are here to improve code coverage and provide a foundation for writing future tests
+ @Test
public void testGetVnfd_Not_Implemented() {
final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
@@ -220,17 +384,74 @@ public class Sol003PackageManagementControllerTest {
}
// Simply returns a byte array filled with random data, for use in the tests.
- private byte[] buildByteArrayWithRandomData(int sizeInKb) {
+ private byte[] buildByteArrayWithRandomData(final int sizeInKb) {
final Random rnd = new Random();
final byte[] b = new byte[sizeInKb * 1024]; // converting kb to byte
rnd.nextBytes(b);
return b;
}
- private ResponseEntity<ProblemDetails> sendHttpRequest(String url) {
+ private ResponseEntity<ProblemDetails> sendHttpRequest(final String url) {
final String testURL = localhostUrl + port + VNFPKGM_BASE_URL + "/" + url;
final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
return restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request,
ProblemDetails.class);
}
+
+ private VnfPkgInfo[] createVnfPkgArray() {
+ final VnfPkgInfo[] vnfPkgInfoArray = new VnfPkgInfo[1];
+ final VnfPkgInfo vnfPkgInfo = createVnfPkgInfo(VNF_PACKAGE_ID);
+ vnfPkgInfoArray[0] = vnfPkgInfo;
+ return vnfPkgInfoArray;
+ }
+
+ private VnfPkgInfo createVnfPkgInfo(final String vnfPackageId) {
+ final VnfPkgInfo vnfPkgInfo = new VnfPkgInfo();
+ vnfPkgInfo.setId(vnfPackageId);
+ vnfPkgInfo.setVnfdId(VNFD_ID);
+ vnfPkgInfo.setVnfProvider(VNF_PROVIDER);
+ vnfPkgInfo.setVnfProductName(VNF_PRODUCT_NAME);
+ vnfPkgInfo.setVnfSoftwareVersion(VNF_SOFTWARE_VERSION);
+ vnfPkgInfo.setVnfdVersion(VNFD_VERSION);
+ vnfPkgInfo.setChecksum(createVnfPkgChecksum());
+ vnfPkgInfo.setSoftwareImages(createSoftwareImages());
+ vnfPkgInfo.setAdditionalArtifacts(createAdditionalArtifacts());
+ vnfPkgInfo.setLinks(createVNFPKGMLinkSerializerLinks());
+ return vnfPkgInfo;
+ }
+
+ private Checksum createVnfPkgChecksum() {
+ final Checksum checksum = new Checksum();
+ checksum.setAlgorithm(ALGORITHM);
+ checksum.setHash(HASH);
+ return checksum;
+ }
+
+ private List<VnfPackageSoftwareImageInfo> createSoftwareImages() {
+ final List<VnfPackageSoftwareImageInfo> softwareImages = new ArrayList<>();
+ final VnfPackageSoftwareImageInfo vnfPackageSoftwareImageInfo = new VnfPackageSoftwareImageInfo();
+ vnfPackageSoftwareImageInfo.setId(VNFD_ID);
+ vnfPackageSoftwareImageInfo.setName(VNF_PRODUCT_NAME);
+ vnfPackageSoftwareImageInfo.setProvider("");
+ vnfPackageSoftwareImageInfo.setVersion("");
+ vnfPackageSoftwareImageInfo.setChecksum(createVnfPkgChecksum());
+ vnfPackageSoftwareImageInfo
+ .setContainerFormat(VnfPackageSoftwareImageInfo.ContainerFormatEnum.fromValue("AKI"));
+ softwareImages.add(vnfPackageSoftwareImageInfo);
+ return softwareImages;
+ }
+
+ private List<VnfPackageArtifactInfo> createAdditionalArtifacts() {
+ final List<VnfPackageArtifactInfo> vnfPackageArtifactInfos = new ArrayList<>();
+ final VnfPackageArtifactInfo vnfPackageArtifactInfo =
+ new VnfPackageArtifactInfo().artifactPath(ARTIFACT_PATH).checksum(createVnfPkgChecksum());
+ vnfPackageArtifactInfos.add(vnfPackageArtifactInfo);
+ return vnfPackageArtifactInfos;
+ }
+
+ private VNFPKGMLinkSerializer createVNFPKGMLinkSerializerLinks() {
+ final UriLink uriLink = new UriLink().href(URI_HREF);
+ final VNFPKGMLinkSerializer vnfpkgmLinkSerializer = new VNFPKGMLinkSerializer().self(uriLink);
+ return vnfpkgmLinkSerializer;
+ }
}