aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter
diff options
context:
space:
mode:
authorrope252 <gareth.roper@est.tech>2019-11-19 16:23:34 +0000
committerrope252 <gareth.roper@est.tech>2019-12-11 15:44:16 +0000
commit439c3a27f9f7c38f46ce3849e5b998fd5631686d (patch)
tree7c3dc7494fa07521d874fc95d6da92278323a0e2 /adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter
parentb9765b97e0fd8a99c5b27263638eb05483f14e29 (diff)
SOL003 Adapter Package Management - Fetch VNF Package Content
Change-Id: I86f1541098c7694b1624f9cdaf4e4c5cb91df3dd Issue-ID: SO-2415 Signed-off-by: rope252 <gareth.roper@est.tech>
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter')
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java66
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java49
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java41
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java56
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java81
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java59
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java20
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementController.java79
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java19
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerRequestFailureException.java43
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java43
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java43
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java210
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java4
14 files changed, 739 insertions, 74 deletions
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
new file mode 100644
index 0000000000..713bf01249
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/Sol003PackageManagementControllerExceptionHandler.java
@@ -0,0 +1,66 @@
+/*-
+ * ============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;
+
+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.VnfPkgConflictException;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.ControllerAdvice;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+
+/**
+ * Exception Handler for the Package Management Controller {@link Sol003PackageManagementController Sol003Controller}
+ *
+ * @author gareth.roper@est.tech
+ */
+@ControllerAdvice(assignableTypes = Sol003PackageManagementController.class)
+
+public class Sol003PackageManagementControllerExceptionHandler {
+
+ @ExceptionHandler(EtsiCatalogManagerRequestFailureException.class)
+ public ResponseEntity<ProblemDetails> handleEtsiCatalogManagerRequestFailureException(
+ EtsiCatalogManagerRequestFailureException etsiCatalogManagerRequestFailureException) {
+ final ProblemDetails problemDetails = new ProblemDetails();
+ problemDetails.setDetail(etsiCatalogManagerRequestFailureException.getMessage());
+ return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(problemDetails);
+ }
+
+ @ExceptionHandler(VnfPkgConflictException.class)
+ public ResponseEntity<ProblemDetails> handleVnfPkgConflictException(
+ VnfPkgConflictException vnfPkgConflictException) {
+ final ProblemDetails problemDetails = new ProblemDetails();
+ problemDetails.setDetail(vnfPkgConflictException.getMessage());
+ return ResponseEntity.status(HttpStatus.CONFLICT).body(problemDetails);
+ }
+
+ @ExceptionHandler(VnfPkgNotFoundException.class)
+ public ResponseEntity<ProblemDetails> handleVnfPkgNotFoundException(
+ VnfPkgNotFoundException vnfPkgNotFoundException) {
+ final ProblemDetails problemDetails = new ProblemDetails();
+ problemDetails.setDetail(vnfPkgNotFoundException.getMessage());
+ return ResponseEntity.status(HttpStatus.NOT_FOUND).body(problemDetails);
+ }
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java
new file mode 100644
index 0000000000..8f6d853997
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java
@@ -0,0 +1,49 @@
+/*-
+ * ============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.extclients;
+
+import com.google.gson.Gson;
+import java.util.Iterator;
+import org.onap.vnfmadapter.v1.JSON;
+import org.springframework.http.converter.HttpMessageConverter;
+import org.springframework.http.converter.json.GsonHttpMessageConverter;
+import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * A base class that can be extended by classes for configuring HttpRestServiceProvider classes. Provides common methods
+ * that will be useful to some such classes.
+ *
+ * @author gareth.roper@est.tech
+ */
+public abstract class AbstractServiceProviderConfiguration {
+
+ public void setGsonMessageConverter(final RestTemplate restTemplate) {
+ final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator();
+ while (iterator.hasNext()) {
+ if (iterator.next() instanceof MappingJackson2HttpMessageConverter) {
+ iterator.remove();
+ }
+ }
+ final Gson gson = new JSON().getGson();
+ restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson));
+ }
+}
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
new file mode 100644
index 0000000000..39efc8dc23
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java
@@ -0,0 +1,41 @@
+/*-
+ * ============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.extclients.etsicatalog;
+
+import java.util.Optional;
+
+/**
+ * Provides methods for invoking REST calls to the ETSI Catalog Manager.
+ *
+ * @author gareth.roper@est.tech
+ */
+public interface EtsiCatalogServiceProvider {
+
+ /**
+ * GET Package Content, from VNF Package.
+ *
+ * @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);
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java
new file mode 100644
index 0000000000..6840dd388b
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java
@@ -0,0 +1,56 @@
+/*-
+ * ============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.extclients.etsicatalog;
+
+import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
+import org.onap.so.adapters.vnfmadapter.extclients.AbstractServiceProviderConfiguration;
+import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
+import org.onap.so.configuration.rest.HttpHeadersProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProviderImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Configures the HttpRestServiceProvider to make REST calls to the ETSI Catalog Manager
+ *
+ * @author gareth.roper@est.tech
+ */
+
+@Configuration
+public class EtsiCatalogServiceProviderConfiguration extends AbstractServiceProviderConfiguration {
+
+ @Bean(name = "etsiCatalogServiceProvider")
+ public HttpRestServiceProvider httpRestServiceProvider(
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate) {
+ return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider());
+ }
+
+ private HttpRestServiceProvider getHttpRestServiceProvider(final RestTemplate restTemplate,
+ final HttpHeadersProvider httpHeadersProvider) {
+ setGsonMessageConverter(restTemplate);
+ return new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider);
+ }
+
+}
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
new file mode 100644
index 0000000000..9a59620993
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java
@@ -0,0 +1,81 @@
+/*-
+ * ============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.extclients.etsicatalog;
+
+import java.util.Optional;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException;
+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.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.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+
+/**
+ * Provides the implementations of the REST Requests to the ETSI Catalog Manager.
+ *
+ * @author gareth.roper@est.tech
+ */
+@Service
+public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvider {
+ private static final Logger logger = LoggerFactory.getLogger(EtsiCatalogServiceProviderImpl.class);
+
+ @Qualifier
+ private final HttpRestServiceProvider httpServiceProvider;
+ private final EtsiCatalogUrlProvider etsiCatalogUrlProvider;
+
+ @Autowired
+ public EtsiCatalogServiceProviderImpl(final EtsiCatalogUrlProvider etsiCatalogUrlProvider,
+ final HttpRestServiceProvider httpServiceProvider) {
+ this.etsiCatalogUrlProvider = etsiCatalogUrlProvider;
+ this.httpServiceProvider = httpServiceProvider;
+ }
+
+ @Override
+ public Optional<byte[]> getVnfPackageContent(String vnfPkgId) throws EtsiCatalogManagerRequestFailureException {
+ try {
+ 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) {
+ logger.error("Caught HttpResouceNotFoundException", httpResouceNotFoundException);
+ throw new VnfPkgNotFoundException("No Vnf Package found with vnfPkgId: " + vnfPkgId);
+ } catch (RestProcessingException restProcessingException) {
+ logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(),
+ restProcessingException);
+ if (restProcessingException.getStatusCode() == HttpStatus.CONFLICT.value()) {
+ throw new VnfPkgConflictException("A conflict occurred with the state of the resource,\n"
+ + "due to the attribute: onboardingState not being set to ONBOARDED.");
+ }
+ }
+ 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
new file mode 100644
index 0000000000..e8188b9c7d
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogUrlProvider.java
@@ -0,0 +1,59 @@
+/*-
+ * ============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.extclients.etsicatalog;
+
+import static org.slf4j.LoggerFactory.getLogger;
+import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+/**
+ * Provides the URLs for the REST Requests to the ETSI Catalog Manager.
+ *
+ * @author gareth.roper@est.tech
+ */
+@Service
+public class EtsiCatalogUrlProvider {
+
+ private static final Logger logger = getLogger(EtsiCatalogUrlProvider.class);
+
+ @Value("${msb.endpoint:#{\"http://msb_iag.onap:80\"}}")
+ private String msbEndpoint;
+ @Value("${msb.catalogServiceUrl:#{null}}")
+ private String catalogServiceUrl;
+ @Value("${msb.vnfpkgmServiceUrl:#{\"/api/vnfpkgm/v1\"}}")
+ private String vnfpkgmServiceUrl;
+
+ public EtsiCatalogUrlProvider() {}
+
+ /**
+ * Get the URL for retrieving the Package Content from the ETSI Catalog.".
+ *
+ * @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;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java
index ae9316cfdf..073fc93107 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java
@@ -21,7 +21,6 @@
package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
-import com.google.gson.Gson;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.KeyStore;
@@ -29,7 +28,6 @@ import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
-import java.util.Iterator;
import java.util.ListIterator;
import java.util.Map;
import java.util.UUID;
@@ -43,7 +41,7 @@ import org.apache.http.ssl.SSLContextBuilder;
import org.onap.aai.domain.yang.EsrSystemInfo;
import org.onap.aai.domain.yang.EsrVnfm;
import org.onap.logging.filter.spring.SpringClientPayloadFilter;
-import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.JSON;
+import org.onap.so.adapters.vnfmadapter.extclients.AbstractServiceProviderConfiguration;
import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter;
import org.onap.so.rest.service.HttpRestServiceProvider;
@@ -58,9 +56,6 @@ import org.springframework.core.io.Resource;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
-import org.springframework.http.converter.HttpMessageConverter;
-import org.springframework.http.converter.json.GsonHttpMessageConverter;
-import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.security.oauth2.client.OAuth2RestTemplate;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
import org.springframework.web.client.RestTemplate;
@@ -69,7 +64,7 @@ import org.springframework.web.client.RestTemplate;
* Configures the HttpRestServiceProvider for REST call to a VNFM.
*/
@Configuration
-public class VnfmServiceProviderConfiguration {
+public class VnfmServiceProviderConfiguration extends AbstractServiceProviderConfiguration {
private static final Logger logger = LoggerFactory.getLogger(VnfmServiceProviderConfiguration.class);
private Map<String, HttpRestServiceProvider> mapOfVnfmIdToHttpRestServiceProvider = new ConcurrentHashMap<>();
@@ -135,17 +130,6 @@ public class VnfmServiceProviderConfiguration {
return new OAuth2RestTemplate(resourceDetails);
}
- private void setGsonMessageConverter(final RestTemplate restTemplate) {
- final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator();
- while (iterator.hasNext()) {
- if (iterator.next() instanceof MappingJackson2HttpMessageConverter) {
- iterator.remove();
- }
- }
- final Gson gson = new JSON().getGson();
- restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson));
- }
-
private void setTrustStore(final RestTemplate restTemplate) {
SSLContext sslContext;
try {
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 1da1159be0..e12729a2e3 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
@@ -24,9 +24,13 @@ 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;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001;
import org.slf4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@@ -45,13 +49,21 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping(value = PACKAGE_MANAGEMENT_BASE_URL, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class Sol003PackageManagementController {
- private static final String LOG_REQUEST_RECEIVED = "VNF Package Management Controller: {} {} {} {} {}";
+ private final EtsiCatalogServiceProvider etsiCatalogServiceProvider;
+
+ @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. Direction: VNFM -> VNFM-Adapter. 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
- *
+ * 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
*/
@@ -62,9 +74,9 @@ public class Sol003PackageManagementController {
}
/**
- * GET VNF package information. Direction: VNFM -> VNFM-Adapter. Will return a specific VNF package representation
- * that match the attribute filter. Section Number: 10.4.3
- *
+ * 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
*/
@@ -75,44 +87,67 @@ public class Sol003PackageManagementController {
}
/**
- * GET VNFD, from VNF package. Direction: VNFM -> VNFM-Adapter. Will return a copy of the file representing the VNFD
- * or a ZIP file that contains the file/multiple files representing the VNFD specified. Section Number: 10.4.4
- *
+ * GET VNFD, from VNF package. Will return a copy of the file representing the VNFD or a ZIP file that contains the
+ * file/multiple files representing the VNFD specified. Section Number: 10.4.4
+ *
* @param vnfPkgId The ID of the VNF Package that you want to retrieve the VNFD from.
* @return The VNFD of a VNF Package as a single file or within a ZIP file. Object: byte[] Response Code: 200 OK
*/
- @GetMapping(value = "/vnf_packages/{vnfPkgId}/vnfd", produces = {MediaType.TEXT_PLAIN, APPLICATION_ZIP})
+ @GetMapping(value = "/vnf_packages/{vnfPkgId}/vnfd",
+ produces = {MediaType.TEXT_PLAIN, APPLICATION_ZIP, MediaType.APPLICATION_JSON})
public ResponseEntity<byte[]> getVnfPackageVnfd(@PathVariable("vnfPkgId") final String vnfPkgId) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageVnfd: ", vnfPkgId);
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
/**
- * GET Package Content, from VNF Package. Direction: VNFM -> VNFM-Adapter. Will return a copy of the VNF package
- * file that you specified. Section Number: 10.4.5
- *
+ * GET Package Content, from VNF Package. Will return a copy of the VNF package file that you specified. Section
+ * Number: 10.4.5
+ *
* @param vnfPkgId The ID of the VNF Package that you want to retrieve the "package_content" from.
* @return The Package Content of a VNF Package. Object: byte[] Response Code: 200 OK
*/
- @GetMapping(value = "/vnf_packages/{vnfPkgId}/package_content", produces = {APPLICATION_ZIP})
- public ResponseEntity<byte[]> getVnfPackageContent(@PathVariable("vnfPkgId") final String vnfPkgId) {
- logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent: ", vnfPkgId);
- return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
+ @GetMapping(value = "/vnf_packages/{vnfPkgId}/package_content",
+ produces = {MediaType.APPLICATION_JSON, APPLICATION_ZIP, MediaType.APPLICATION_OCTET_STREAM})
+ public ResponseEntity getVnfPackageContent(@PathVariable("vnfPkgId") final String vnfPkgId) {
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Endpoint Invoked with VNF Package ID: ", vnfPkgId);
+ final Optional<byte[]> response = etsiCatalogServiceProvider.getVnfPackageContent(vnfPkgId);
+ if (response.isPresent()) {
+ logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageContent Response: ", HttpStatus.OK);
+ return new ResponseEntity(response.get(), HttpStatus.OK);
+ }
+ logger.error("Null response was received from the EtsiCatalogManager using the GET \"package_content\"");
+ return new ResponseEntity(buildProblemDetails("An error occurred, a null response was received by the\n"
+ + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"package_content\" \n"
+ + "endpoint."), HttpStatus.INTERNAL_SERVER_ERROR);
}
/**
- * GET Artifact, from VNF Package. Direction: VNFM -> VNFM-Adapter. Will return a the content of the artifact that
- * you specified. Section Number: 10.4.6
- *
+ * GET Artifact, from VNF Package Will return a the content of the artifact that you specified. Section Number:
+ * 10.4.6
+ *
* @param vnfPkgId The ID of the VNF Package that you want to retrieve an artifact from.
* @param artifactPath The path of the artifact that you want to retrieve.
* @return An Artifact from a VNF Package. Object: byte[] Response Code: 200 OK
*/
@GetMapping(value = "/vnf_packages/{vnfPkgId}/artifacts/{artifactPath}",
- produces = {MediaType.APPLICATION_OCTET_STREAM})
+ produces = {MediaType.APPLICATION_OCTET_STREAM, MediaType.APPLICATION_JSON})
public ResponseEntity<byte[]> getVnfPackageArtifact(@PathVariable("vnfPkgId") final String vnfPkgId,
@PathVariable("artifactPath") final String artifactPath) {
logger.info(LOG_REQUEST_RECEIVED, "getVnfPackageArtifact: vnfPkgId=", vnfPkgId, " artifactPath=", artifactPath);
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
+
+ /**
+ * Builds the ProblemDetails Object, using the provided error message.
+ *
+ * @param detail The error message retrieved from the exception thrown.
+ * @return ProblemDetails Object, containing error information.
+ */
+ private ProblemDetails buildProblemDetails(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/Sol003SubscriptionManagementController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java
index 6fac952aa8..16650d4a3d 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementController.java
@@ -53,9 +53,9 @@ public class Sol003SubscriptionManagementController {
private static final Logger logger = getLogger(Sol003SubscriptionManagementController.class);
/**
- * POST Subscribe request. Direction: VNFM -> VNFM Adapter. Will send request and respond with the subscription that
- * you subscribed to, if successful. Section Number: 10.4.7
- *
+ * POST Subscribe request. Will send request and respond with the subscription that you subscribed to, if
+ * successful. Section Number: 10.4.7
+ *
* @param pkgmSubscriptionRequest This includes the details of the subscription to be created.
* @return The subscription requested, if successful. Object: InlineRespone2002 Response Code: 201 Created Response
* Code: 303 Duplicate Subscription
@@ -68,9 +68,8 @@ public class Sol003SubscriptionManagementController {
}
/**
- * GET all subscriptions. Direction: VNFM -> VNFM Adapter. Will return a list of all subscriptions currently active.
- * Section Number: 10.4.7
- *
+ * GET all subscriptions. Will return a list of all subscriptions currently active. Section Number: 10.4.7
+ *
* @return All of the current active subscriptions. Object: List<InlineResponse2002> Response Code: 200 OK
*/
@GetMapping(value = "/subscriptions")
@@ -80,8 +79,8 @@ public class Sol003SubscriptionManagementController {
}
/**
- * GET a specific subscription, by subscriptionId. Direction: VNFM -> VNFM Adapter. Section Number: 10.4.8
- *
+ * GET a specific subscription, by subscriptionId. Section Number: 10.4.8
+ *
* @param subscriptionId The ID of the subscription that you wish to retrieve.
* @return A subscription based on subscriptionId. Object: InlineResponse2002 Response Code: 200 OK
*/
@@ -93,8 +92,8 @@ public class Sol003SubscriptionManagementController {
}
/**
- * DELETE a specific subscription, by subscriptionId. Direction: VNFM -> VNFM Adapter. Section Number: 10.4.7
- *
+ * DELETE a specific subscription, by subscriptionId. Section Number: 10.4.7
+ *
* @param subscriptionId The ID of the subscription that you wish to delete.
* @return Empty response if successful. Object: Void Response Code: 204 No Content
*/
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerRequestFailureException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerRequestFailureException.java
new file mode 100644
index 0000000000..dbdc354f4e
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/EtsiCatalogManagerRequestFailureException.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 an ETSI Catalog Manager Request Failure
+ *
+ * @author gareth.roper@est.tech
+ */
+@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR)
+public class EtsiCatalogManagerRequestFailureException extends RuntimeException {
+
+ private static final long serialVersionUID = 66862444537194516L;
+
+ public EtsiCatalogManagerRequestFailureException(final String message) {
+ super(message);
+ }
+
+ @Override
+ public synchronized Throwable fillInStackTrace() {
+ return this;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.java
new file mode 100644
index 0000000000..0cc9c5bd7e
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgConflictException.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 Conflict failure, due to state of resource.
+ *
+ * @author gareth.roper@est.tech
+ */
+@ResponseStatus(code = HttpStatus.CONFLICT)
+public class VnfPkgConflictException extends RuntimeException {
+
+ private static final long serialVersionUID = 26862444537198441L;
+
+ public VnfPkgConflictException(final String message) {
+ super(message);
+ }
+
+ @Override
+ public synchronized Throwable fillInStackTrace() {
+ return this;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.java
new file mode 100644
index 0000000000..0f9f214643
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfPkgNotFoundException.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 Not Found Failure
+ *
+ * @author gareth.roper@est.tech
+ */
+@ResponseStatus(code = HttpStatus.NOT_FOUND)
+public class VnfPkgNotFoundException extends RuntimeException {
+
+ private static final long serialVersionUID = 26862444537198441L;
+
+ public VnfPkgNotFoundException(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 801c468018..59dfd50b32 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
@@ -1,74 +1,236 @@
-package org.onap.so.adapters.vnfmadapter.rest;
+/*-
+ * ============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;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL;
import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
-import java.net.URISyntaxException;
-import java.util.List;
+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.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.vnfm.packagemanagement.model.InlineResponse2001;
+import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails;
+import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
+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.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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;
+/**
+ * @author gareth.roper@est.tech
+ */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
public class Sol003PackageManagementControllerTest {
- private static final String vnfPackageId = "myVnfPackageId";
- private static final String artifactPath = "myArtifactPath";
+ private static final Logger logger = LoggerFactory.getLogger(Sol003PackageManagementControllerTest.class);
+
+ @LocalServerPort
+ private int port;
@Autowired
@Qualifier(CONFIGURABLE_REST_TEMPLATE)
private RestTemplate testRestTemplate;
- private MockRestServiceServer mockRestServer;
@Autowired
private Sol003PackageManagementController controller;
+ @Autowired
+ private TestRestTemplate restTemplate;
+
+ private static final String VNF_PACKAGE_ID = "myVnfPackageId";
+ private static final String ARTIFACT_PATH = "myArtifactPath";
+ 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 MockRestServiceServer mockRestServer;
+ private BasicHttpHeadersProvider basicHttpHeadersProvider;
+
+
+ public Sol003PackageManagementControllerTest() {}
+
@Before
- public void setUp() throws Exception {
- mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
+ public void setUp() {
+ MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(testRestTemplate);
+ builder.ignoreExpectOrder(true);
+ mockRestServer = builder.build();
+ basicHttpHeadersProvider = new BasicHttpHeadersProvider();
+ }
+
+ @Test
+ public void testGetPackageContent_ValidArray_Success() {
+ byte[] responseArray = buildByteArrayWithRandomData(10);
+
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(responseArray, MediaType.APPLICATION_OCTET_STREAM));
+
+ final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/"
+ + VNF_PACKAGE_ID + "/package_content";
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<byte[]> responseEntity =
+ restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class);
+
+ assertEquals(byte[].class, responseEntity.getBody().getClass());
+ assertArrayEquals(responseEntity.getBody(), responseArray);
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackages() throws URISyntaxException, InterruptedException {
- final ResponseEntity<List<InlineResponse2001>> response = controller.getVnfPackages();
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_Conflict_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.CONFLICT));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.CONFLICT, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackage() throws URISyntaxException, InterruptedException {
- final ResponseEntity<InlineResponse2001> response = controller.getVnfPackage(vnfPackageId);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_NotFound_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackageVnfd() throws URISyntaxException, InterruptedException {
- final ResponseEntity<byte[]> response = controller.getVnfPackageVnfd(vnfPackageId);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_UnauthorizedClient_Fail() {
+ final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/"
+ + VNF_PACKAGE_ID + "/package_content";
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<ProblemDetails> responseEntity =
+ restTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class);
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.UNAUTHORIZED, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackageContents() throws URISyntaxException, InterruptedException {
- final ResponseEntity<byte[]> response = controller.getVnfPackageContent(vnfPackageId);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_InternalServerError_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
}
@Test
- public void getVnfPackageArtifact() throws URISyntaxException, InterruptedException {
- final ResponseEntity<byte[]> response = controller.getVnfPackageArtifact(vnfPackageId, artifactPath);
- assertEquals(HttpStatus.NOT_IMPLEMENTED, response.getStatusCode());
+ public void testOnGetPackageContent_BadRequest_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
}
+ @Test
+ public void testOnGetPackageContent_UnauthorizedServer_InternalError_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetPackageContent_SuccessResponseFromServerWithNullPackage_Fail() {
+ mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withSuccess());
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/package_content");
+
+ assertEquals(ProblemDetails.class, responseEntity.getBody().getClass());
+ 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());
+ }
+
+ @Test
+ public void testGetVnfPackages_Not_Implemented() {
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest("");
+ assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetVnfd_Not_Implemented() {
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
+ assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetArtifact_Not_Implemented() {
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+ assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode());
+ }
+
+ // Simply returns a byte array filled with random data, for use in the tests.
+ private byte[] buildByteArrayWithRandomData(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) {
+ 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);
+ }
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java
index 999dd02f0f..8fc27c5943 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003SubscriptionManagementControllerTest.java
@@ -20,6 +20,10 @@ import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
+/**
+ * @author gareth.roper@est.tech
+ */
+
@RunWith(SpringRunner.class)
@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")