aboutsummaryrefslogtreecommitdiffstats
path: root/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test')
-rw-r--r--so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/EtsiSubscriptionNotificationControllerTest.java591
-rw-r--r--so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementControllerTest.java677
-rw-r--r--so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementSubscriptionControllerTest.java403
-rwxr-xr-xso-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/TestApplication.java38
-rw-r--r--so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/resources/application.yaml61
-rw-r--r--so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/resources/requests/SubscriptionRequest.json45
6 files changed, 1815 insertions, 0 deletions
diff --git a/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/EtsiSubscriptionNotificationControllerTest.java b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/EtsiSubscriptionNotificationControllerTest.java
new file mode 100644
index 0000000..efe6891
--- /dev/null
+++ b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/EtsiSubscriptionNotificationControllerTest.java
@@ -0,0 +1,591 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.etsisol003adapter.pkgm.rest;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL;
+import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
+import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.jsonPath;
+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.net.URI;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.NOTIFICATIONLINKSERIALIZER;
+import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgChangeNotification;
+import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgOnboardingNotification;
+import org.onap.so.adapters.etsisol003adapter.etsicatalog.notification.model.PkgmLinks;
+import org.onap.so.adapters.etsisol003adapter.pkgm.JSON;
+import org.onap.so.adapters.etsisol003adapter.pkgm.PackageManagementConstants;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.ProblemDetails;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.notification.model.VnfPackageChangeNotification;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm.notification.model.VnfPackageOnboardingNotification;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.PkgmSubscriptionRequest;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthenticationParamsBasic;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthenticationParamsOauth2ClientCredentials;
+import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
+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.client.RestTemplateBuilder;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.cache.Cache;
+import org.springframework.cache.CacheManager;
+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.http.converter.json.GsonHttpMessageConverter;
+import org.springframework.test.annotation.DirtiesContext;
+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 Andrew Lamb (andrew.a.lamb@est.tech)
+ *
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+@DirtiesContext(classMode = BEFORE_CLASS)
+public class EtsiSubscriptionNotificationControllerTest {
+
+ @LocalServerPort
+ private int port;
+
+ private static final URI CALLBACK_URI = URI.create("http://test_callback_uri/notification");
+ private static final String TOKEN_ENDPOINT = "http://test_token_endpoint_uri/";
+ private static final String TOKEN = "dXNlcm5hbWU6cGFzc3dvcmQ=......";
+ private static final String JSON_TOKEN = "{\"access_token\":\"" + TOKEN + "\"}";
+ private static final String LOCALHOST_URL = "http://localhost:";
+ private static final String NOTIFICATION_BASE_URL =
+ ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL + "/notification";
+ private static final String USERNAME = "username";
+ private static final String PASSWORD = "password";
+ private static final String EXPECTED_BASIC_AUTHORIZATION = "Basic dXNlcm5hbWU6cGFzc3dvcmQ=";
+ private static final String EXPECTED_OAUTH_AUTHORIZATION = "Bearer " + TOKEN;
+ private static final String NOTIFICATION_ID = "NOTIFICATION_ID";
+ private static final String SUBSCRIPTION_ID = "SUBSCRIPTION_ID";
+ private static final String TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG = "2020-01-01 01:01:01";
+ private static final java.time.LocalDateTime TIMESTAMP = java.time.LocalDateTime.of(2020, 1, 1, 1, 1, 1, 1);
+ private static final String VNFPKG_ID = UUID.randomUUID().toString();
+ private static final String VNFD_ID = UUID.randomUUID().toString();
+ private static final String EXPECTED_VNF_PACKAGE_HREF =
+ "https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/vnfpkgm/v1/vnf_packages/" + VNFPKG_ID;
+ private static final String EXPECTED_SUBSCRIPTION_HREF =
+ "https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/vnfpkgm/v1/subscriptions/" + SUBSCRIPTION_ID;
+
+
+ private BasicHttpHeadersProvider basicHttpHeadersProvider;
+
+ @Autowired
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE)
+ private RestTemplate restTemplate;
+ private MockRestServiceServer mockRestServiceServer;
+
+ private TestRestTemplate testRestTemplate;
+
+ @Autowired
+ private CacheManager cacheServiceProvider;
+ private Cache cache;
+
+ @Before
+ public void setUp() {
+ mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build();
+ basicHttpHeadersProvider = new BasicHttpHeadersProvider();
+ cache = cacheServiceProvider.getCache(PackageManagementConstants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE);
+ cache.clear();
+
+ final Gson gson = JSON.createGson().registerTypeAdapter(LocalDateTime.class,
+ new EtsiSubscriptionNotificationController.LocalDateTimeTypeAdapter()).create();
+ testRestTemplate = new TestRestTemplate(
+ new RestTemplateBuilder().additionalMessageConverters(new GsonHttpMessageConverter(gson)));
+ }
+
+
+ @After
+ public void tearDown() {
+ mockRestServiceServer.reset();
+ cache.clear();
+ }
+
+ @Test
+ public void testSubscriptionNotificationEndPoint_ReturnsNoContent() {
+ final ResponseEntity<?> response = sendHttpGet(NOTIFICATION_BASE_URL);
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+ }
+
+ @Test
+ public void testOnboardingNotificationSentOnToVnfmCallbackUri_SubscriptionRequestInCache_Success() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
+ .andExpect(jsonPath("$.notificationType")
+ .value(VnfPackageOnboardingNotification.NotificationTypeEnum.VNFPACKAGEONBOARDINGNOTIFICATION
+ .toString()))
+ .andExpect(jsonPath("$.subscriptionId").value(SUBSCRIPTION_ID))
+ .andExpect(jsonPath("$.timeStamp").value(TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG))
+ .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID)).andExpect(jsonPath("$.vnfdId").value(VNFD_ID))
+ .andExpect(jsonPath("$._links")
+ .value(buildPkgmLinks(EXPECTED_VNF_PACKAGE_HREF, EXPECTED_SUBSCRIPTION_HREF)))
+ .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess());
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+ }
+
+ @Test
+ public void testOnboardingNotificationNotSentOnToVnfmCallbackUri_SubscriptionRequestNotInCache_Fail() {
+ final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "No subscription found with subscriptionId " + SUBSCRIPTION_ID
+ + ". Unable to forward notification to subscriber.";
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testOnboardingNotificationSentOnToVnfmCallbackUri_BadRequestResponseFromCallbackUri_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: "
+ + HttpStatus.BAD_REQUEST + ".\n" + "No result found for given url: " + CALLBACK_URI;
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testOnboardingNotificationSentOnToVnfmCallbackUri_301MovedPermanentlyResponseFromCallbackUri_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andRespond(withStatus(HttpStatus.MOVED_PERMANENTLY));
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Sending of notification to VNFM failed.";
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testOnboardingNotificationSentOnToVnfmCallbackUri_NotFoundResponseFromCallbackUri_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: "
+ + HttpStatus.NOT_FOUND + ".\n" + "No result found for given url: " + CALLBACK_URI;
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testOnboardingNotificationSentOnToVnfmCallbackUri_InternalServerErrorResponseFromCallbackUri_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: "
+ + HttpStatus.INTERNAL_SERVER_ERROR.value() + ".\n" + "Unable to invoke HTTP POST using URL: "
+ + CALLBACK_URI;
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testChangeNotificationSentOnToVnfmCallbackUri_SubscriptionRequestInCache_Success() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgChangeNotification notification = buildPkgChangeNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
+ .andExpect(jsonPath("$.notificationType").value(
+ VnfPackageChangeNotification.NotificationTypeEnum.VNFPACKAGECHANGENOTIFICATION.getValue()))
+ .andExpect(jsonPath("$.subscriptionId").value(SUBSCRIPTION_ID))
+ .andExpect(jsonPath("$.timeStamp").value(TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG))
+ .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID)).andExpect(jsonPath("$.vnfdId").value(VNFD_ID))
+ .andExpect(
+ jsonPath("$.changeType").value(PkgChangeNotification.ChangeTypeEnum.OP_STATE_CHANGE.toString()))
+ .andExpect(jsonPath("$.operationalState")
+ .value(PkgChangeNotification.OperationalStateEnum.ENABLED.toString()))
+ .andExpect(jsonPath("$._links")
+ .value(buildPkgmLinks(EXPECTED_VNF_PACKAGE_HREF, EXPECTED_SUBSCRIPTION_HREF)))
+ .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess());
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+ }
+
+ @Test
+ public void testChangeNotificationNotSentOnToVnfmCallbackUri_SubscriptionRequestNotInCache_Fail() {
+ final PkgChangeNotification notification = buildPkgChangeNotification();
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "No subscription found with subscriptionId " + SUBSCRIPTION_ID
+ + ". Unable to forward notification to subscriber.";
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testChangeNotificationSentOnToVnfmCallbackUri_BadRequestResponseFromCallbackUri_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgChangeNotification notification = buildPkgChangeNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: "
+ + HttpStatus.BAD_REQUEST + ".\n" + "No result found for given url: " + CALLBACK_URI;
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testChangeNotificationSentOnToVnfmCallbackUri_NotFoundResponseFromCallbackUri_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgChangeNotification notification = buildPkgChangeNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: "
+ + HttpStatus.NOT_FOUND + ".\n" + "No result found for given url: " + CALLBACK_URI;
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testChangeNotificationSentOnToVnfmCallbackUri_InternalServerErrorResponseFromCallbackUri_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgChangeNotification notification = buildPkgChangeNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: "
+ + HttpStatus.INTERNAL_SERVER_ERROR.value() + ".\n" + "Unable to invoke HTTP POST using URL: "
+ + CALLBACK_URI;
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testNotificationSentOnToVnfm_BasicAuthUserPasswordAuthorized_Success() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
+ .andExpect(jsonPath("$.notificationType")
+ .value(VnfPackageOnboardingNotification.NotificationTypeEnum.VNFPACKAGEONBOARDINGNOTIFICATION
+ .toString()))
+ .andExpect(jsonPath("$.subscriptionId").value(SUBSCRIPTION_ID))
+ .andExpect(jsonPath("$.timeStamp").value(TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG))
+ .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID)).andExpect(jsonPath("$.vnfdId").value(VNFD_ID))
+ .andExpect(jsonPath("$._links")
+ .value(buildPkgmLinks(EXPECTED_VNF_PACKAGE_HREF, EXPECTED_SUBSCRIPTION_HREF)))
+ .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess());
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+ }
+
+ @Test
+ public void testNotificationSentOnToVnfm_BasicAuthUserPasswordNotAuthorized_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgChangeNotification notification = buildPkgChangeNotification();
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION))
+ .andRespond(withStatus(HttpStatus.UNAUTHORIZED));
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Sending of notification to VNFM failed with response: "
+ + HttpStatus.UNAUTHORIZED.value() + ".\n" + "Unable to invoke HTTP POST using URL: " + CALLBACK_URI;
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testNotificationSentOnToVnfm_OAuthAuthorized_Success() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.OAUTH2_CLIENT_CREDENTIALS);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgChangeNotification notification = buildPkgChangeNotification();
+
+ mockRestServiceServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST))
+ .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION))
+ .andRespond(withSuccess(JSON_TOKEN, MediaType.APPLICATION_JSON));
+
+ mockRestServiceServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
+ .andExpect(header("Authorization", EXPECTED_OAUTH_AUTHORIZATION))
+ .andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
+ .andExpect(jsonPath("$.notificationType").value(
+ VnfPackageChangeNotification.NotificationTypeEnum.VNFPACKAGECHANGENOTIFICATION.toString()))
+ .andExpect(jsonPath("$.subscriptionId").value(SUBSCRIPTION_ID))
+ .andExpect(jsonPath("$.timeStamp").value(TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG))
+ .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID)).andExpect(jsonPath("$.vnfdId").value(VNFD_ID))
+ .andExpect(
+ jsonPath("$.changeType").value(PkgChangeNotification.ChangeTypeEnum.OP_STATE_CHANGE.toString()))
+ .andExpect(jsonPath("$.operationalState")
+ .value(PkgChangeNotification.OperationalStateEnum.ENABLED.toString()))
+ .andExpect(jsonPath("$._links")
+ .value(buildPkgmLinks(EXPECTED_VNF_PACKAGE_HREF, EXPECTED_SUBSCRIPTION_HREF)))
+ .andRespond(withSuccess());
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
+ }
+
+ @Test
+ public void testNotificationSentOnToVnfm_OAuthTokenNotReceived_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.OAUTH2_CLIENT_CREDENTIALS);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgChangeNotification notification = buildPkgChangeNotification();
+
+ mockRestServiceServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST))
+ .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess());
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Unable to retrieve OAuth Token from VNFM for notification.";
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ @Test
+ public void testNotificationSentOnToVnfm_TLSCertNotYetSupported_Fail() {
+ final PkgmSubscriptionRequest subscriptionRequest =
+ buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.TLS_CERT);
+ cache.put(SUBSCRIPTION_ID, subscriptionRequest);
+ final PkgChangeNotification notification = buildPkgChangeNotification();
+
+ final ResponseEntity<?> response = sendHttpPost(notification);
+
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+
+ final ProblemDetails problemDetails = (ProblemDetails) response.getBody();
+ final String errorMessage = "An error occurred. Authentication type "
+ + subscriptionRequest.getAuthentication().getAuthType().toString() + " not currently supported.";
+
+ assertEquals(errorMessage, problemDetails.getDetail());
+ }
+
+ private PkgOnboardingNotification buildPkgOnboardingNotification() {
+ final PkgOnboardingNotification notification = new PkgOnboardingNotification();
+ notification.setId(NOTIFICATION_ID);
+ notification
+ .setNotificationType(PkgOnboardingNotification.NotificationTypeEnum.VNFPACKAGEONBOARDINGNOTIFICATION);
+ notification.setSubscriptionId(SUBSCRIPTION_ID);
+ notification.setTimeStamp(TIMESTAMP);
+ notification.setVnfPkgId(VNFPKG_ID);
+ notification.setVnfdId(VNFD_ID);
+ notification.setLinks(buildPkgmLinks());
+ return notification;
+ }
+
+ private PkgChangeNotification buildPkgChangeNotification() {
+ final PkgChangeNotification notification = new PkgChangeNotification();
+ notification.setId(NOTIFICATION_ID);
+ notification.setNotificationType(PkgChangeNotification.NotificationTypeEnum.VNFPACKAGECHANGENOTIFICATION);
+ notification.setSubscriptionId(SUBSCRIPTION_ID);
+ notification.setTimeStamp(TIMESTAMP);
+ notification.setVnfPkgId(VNFPKG_ID);
+ notification.setVnfdId(VNFD_ID);
+ notification.setChangeType(PkgChangeNotification.ChangeTypeEnum.OP_STATE_CHANGE);
+ notification.setOperationalState(PkgChangeNotification.OperationalStateEnum.ENABLED);
+ notification.setLinks(buildPkgmLinks());
+ return notification;
+ }
+
+ private PkgmLinks buildPkgmLinks() {
+ return buildPkgmLinks("vnf_package_href", "subscription_href");
+ }
+
+ private PkgmLinks buildPkgmLinks(final String vnfPkgHref, final String subscriptionHref) {
+ return new PkgmLinks().vnfPackage(new NOTIFICATIONLINKSERIALIZER().href(vnfPkgHref))
+ .subscription(new NOTIFICATIONLINKSERIALIZER().href(subscriptionHref));
+ }
+
+ private PkgmSubscriptionRequest buildPkgmSubscriptionRequest(
+ final SubscriptionsAuthentication.AuthTypeEnum authTypeEnum) {
+ final PkgmSubscriptionRequest subscriptionRequest = new PkgmSubscriptionRequest();
+ subscriptionRequest.setCallbackUri(CALLBACK_URI.toString());
+ subscriptionRequest.setAuthentication(buildSubscriptionsAuthentication(authTypeEnum));
+ return subscriptionRequest;
+ }
+
+ // TODO update for auth types other than basicAuth
+ private SubscriptionsAuthentication buildSubscriptionsAuthentication(
+ final SubscriptionsAuthentication.AuthTypeEnum authTypeEnum) {
+ final SubscriptionsAuthentication subscriptionsAuthentication = new SubscriptionsAuthentication();
+ final List<SubscriptionsAuthentication.AuthTypeEnum> authTypes = new ArrayList<>();
+ authTypes.add(authTypeEnum);
+ subscriptionsAuthentication.setAuthType(authTypes);
+ if (authTypeEnum == SubscriptionsAuthentication.AuthTypeEnum.TLS_CERT) {
+ // TODO: remove basic params and code for TLS
+ final SubscriptionsAuthenticationParamsBasic basicParams =
+ new SubscriptionsAuthenticationParamsBasic().userName(USERNAME).password(PASSWORD);
+ subscriptionsAuthentication.setParamsBasic(basicParams);
+ } else if (authTypeEnum == SubscriptionsAuthentication.AuthTypeEnum.OAUTH2_CLIENT_CREDENTIALS) {
+ final SubscriptionsAuthenticationParamsOauth2ClientCredentials oathParams =
+ new SubscriptionsAuthenticationParamsOauth2ClientCredentials().clientId(USERNAME)
+ .clientPassword(PASSWORD).tokenEndpoint(TOKEN_ENDPOINT);
+ subscriptionsAuthentication.setParamsOauth2ClientCredentials(oathParams);
+ } else {
+ final SubscriptionsAuthenticationParamsBasic basicParams =
+ new SubscriptionsAuthenticationParamsBasic().userName(USERNAME).password(PASSWORD);
+ subscriptionsAuthentication.setParamsBasic(basicParams);
+ }
+
+ return subscriptionsAuthentication;
+ }
+
+ private <T> ResponseEntity<ProblemDetails> sendHttpPost(final T notification) {
+ final String testURL = LOCALHOST_URL + port + NOTIFICATION_BASE_URL;
+ final HttpEntity<?> request = new HttpEntity<>(notification, basicHttpHeadersProvider.getHttpHeaders());
+ return testRestTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.POST, request,
+ ProblemDetails.class);
+ }
+
+ private ResponseEntity<Void> sendHttpGet(final String url) {
+ final String testURL = LOCALHOST_URL + port + url;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ return testRestTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, Void.class);
+ }
+
+}
diff --git a/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementControllerTest.java b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementControllerTest.java
new file mode 100644
index 0000000..10e4ea3
--- /dev/null
+++ b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementControllerTest.java
@@ -0,0 +1,677 @@
+/*-
+ * ============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.etsisol003adapter.pkgm.rest;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.PACKAGE_MANAGEMENT_BASE_URL;
+import static org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_REST_TEMPLATE_BEAN;
+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.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.Checksum;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.ProblemDetails;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.UriLink;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VNFPKGMLinkSerializer;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPackageArtifactInfo;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPackageSoftwareImageInfo;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.InlineResponse2001;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.VnfPackagesLinks;
+import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
+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;
+import com.google.gson.Gson;
+
+/**
+ * @author gareth.roper@est.tech
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+public class Sol003PackageManagementControllerTest {
+
+ @LocalServerPort
+ private int port;
+
+ @Autowired
+ @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN)
+ private RestTemplate restTemplate;
+
+ @Autowired
+ private TestRestTemplate testRestTemplate;
+
+ 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 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 EXPECTED_BASE_URL =
+ "https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/vnfpkgm/v1/vnf_packages/";
+ private static final String EXPECTED_SELF_HREF = EXPECTED_BASE_URL + VNF_PACKAGE_ID;
+ private static final String EXPECTED_VNFD_HREF = EXPECTED_BASE_URL + VNF_PACKAGE_ID + "/vnfd";
+ private static final String EXPECTED_PACKAGE_CONTENT_HREF = EXPECTED_BASE_URL + VNF_PACKAGE_ID + "/package_content";
+
+ private MockRestServiceServer mockRestServiceServer;
+ private BasicHttpHeadersProvider basicHttpHeadersProvider;
+ private final Gson gson = new Gson();
+
+ public Sol003PackageManagementControllerTest() {}
+
+ @Before
+ public void setUp() {
+ final MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(restTemplate);
+ builder.ignoreExpectOrder(true);
+ mockRestServiceServer = builder.build();
+ basicHttpHeadersProvider = new BasicHttpHeadersProvider();
+ }
+
+ @After
+ public void after() {
+ mockRestServiceServer.reset();
+ }
+
+ @Test
+ public void testGetPackageContent_ValidArray_Success() {
+ final byte[] responseArray = buildByteArrayWithRandomData(10);
+
+ mockRestServiceServer.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 =
+ testRestTemplate.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 testOnGetPackageContent_Conflict_Fail() {
+ mockRestServiceServer.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 testOnGetPackageContent_NotFound_Fail() {
+ mockRestServiceServer.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 testOnGetPackageContent_UnauthorizedClient_Fail() {
+ final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/"
+ + VNF_PACKAGE_ID + "/package_content";
+
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/package_content"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
+
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ testRestTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class);
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageContent_InternalServerError_Fail() {
+ mockRestServiceServer.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 testOnGetPackageContent_BadRequest_Fail() {
+ mockRestServiceServer.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() {
+ mockRestServiceServer.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() {
+ mockRestServiceServer.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());
+ }
+
+ @Test
+ public void testGetPackageArtifact_ValidArray_Success() {
+ final byte[] responseArray = buildByteArrayWithRandomData(10);
+
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .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 + "/artifacts/" + ARTIFACT_PATH;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<byte[]> responseEntity =
+ testRestTemplate.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 testOnGetPackageArtifact_Conflict_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.CONFLICT));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.CONFLICT, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_NotFound_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_UnauthorizedClient_Fail() {
+ final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/"
+ + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH;
+
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
+
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<ProblemDetails> responseEntity =
+ testRestTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_InternalServerError_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_BadRequest_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageArtifact_UnauthorizedServer_InternalError_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetPackageArtifact_SuccessResponseFromServerWithNullPackage_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH))
+ .andExpect(method(HttpMethod.GET)).andRespond(withSuccess());
+
+ final ResponseEntity<ProblemDetails> responseEntity =
+ sendHttpRequest(VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH);
+
+ assertNotNull(responseEntity.getBody());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testVnfPackagesReceivedAsInlineResponse2001ListIfGetVnfPackagesSuccessful() {
+ final VnfPkgInfo[] responses = createVnfPkgArray();
+
+ mockRestServiceServer.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 = testRestTemplate.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());
+ final VnfPackagesLinks links = inlineResponse2001.getLinks();
+ assertNotNull(links);
+ assertEquals(EXPECTED_SELF_HREF, links.getSelf().getHref());
+ assertEquals(EXPECTED_VNFD_HREF, links.getVnfd().getHref());
+ assertEquals(EXPECTED_PACKAGE_CONTENT_HREF, links.getPackageContent().getHref());
+ }
+
+ @Test
+ public void test400BadRequestInfoReceivedAsProblemDetailsIfGetVnfPackagesIs400BadRequest() {
+ mockRestServiceServer.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() {
+ mockRestServiceServer.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() {
+ mockRestServiceServer.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() {
+ mockRestServiceServer.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);
+
+ mockRestServiceServer.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 = testRestTemplate.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());
+ final VnfPackagesLinks links = inlineResponse2001.getLinks();
+ assertNotNull(links);
+ assertEquals(EXPECTED_SELF_HREF, links.getSelf().getHref());
+ assertEquals(EXPECTED_VNFD_HREF, links.getVnfd().getHref());
+ assertEquals(EXPECTED_PACKAGE_CONTENT_HREF, links.getPackageContent().getHref());
+
+ }
+
+ @Test
+ public void test400BadRequestInfoReceivedAsProblemDetailsIfGetVnfPackageByIdIs400BadRequest() {
+ mockRestServiceServer.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() {
+ mockRestServiceServer.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() {
+ mockRestServiceServer.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() {
+ mockRestServiceServer.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 test method is here to improve code coverage and provide a foundation for writing
+ // future tests
+ @Test
+ public void testGetPackageVnfd_ValidArray_Success() {
+ final byte[] responseArray = buildByteArrayWithRandomData(10);
+
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd"))
+ .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 + "/vnfd";
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ final ResponseEntity<byte[]> responseEntity =
+ testRestTemplate.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 testOnGetPackageVnfd_Conflict_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.CONFLICT));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.CONFLICT, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageVnfd_NotFound_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageVnfd_UnauthorizedClient_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageVnfd_InternalServerError_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageVnfd_BadRequest_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.BAD_REQUEST));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testOnGetPackageVnfd_UnauthorizedServer_InternalError_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.UNAUTHORIZED));
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
+
+ assertTrue(responseEntity.getBody() instanceof ProblemDetails);
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testGetPackageVnfd_SuccessResponseFromServerWithNullPackage_Fail() {
+ mockRestServiceServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID + "/vnfd"))
+ .andExpect(method(HttpMethod.GET)).andRespond(withSuccess());
+
+ final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(VNF_PACKAGE_ID + "/vnfd");
+
+ assertEquals(ProblemDetails.class, responseEntity.getBody().getClass());
+ assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode());
+ }
+
+ // Simply returns a byte array filled with random data, for use in the tests.
+ 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(final String url) {
+ final String testURL = localhostUrl + port + VNFPKGM_BASE_URL + "/" + url;
+ final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders());
+ return testRestTemplate.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 String baseUrl = "http://msb-iag:443/api/vnfpkgm/v1/vnf_packages";
+ return new VNFPKGMLinkSerializer().self(new UriLink().href(baseUrl + "/myVnfPackageId"))
+ .vnfd(new UriLink().href(baseUrl + "/myVnfPackageId/vnfd"))
+ .packageContent(new UriLink().href(baseUrl + "/myVnfPackageId/package_content"));
+ }
+
+}
diff --git a/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementSubscriptionControllerTest.java b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementSubscriptionControllerTest.java
new file mode 100644
index 0000000..65be6a8
--- /dev/null
+++ b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/Sol003PackageManagementSubscriptionControllerTest.java
@@ -0,0 +1,403 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.etsisol003adapter.pkgm.rest;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.ETSI_SUBSCRIPTION_NOTIFICATION_BASE_URL;
+import static org.onap.so.adapters.etsi.sol003.adapter.common.CommonConstants.PACKAGE_MANAGEMENT_BASE_URL;
+import static org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_REST_TEMPLATE_BEAN;
+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.io.File;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.GeneralSecurityException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.UUID;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.so.adapters.etsisol003adapter.pkgm.PackageManagementConstants;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.BasicAuth;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.LinkSelf;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdmSubscription;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmNotificationsFilter;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscription;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.ProblemDetails;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.SubscriptionAuthentication;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.Version;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfProducts;
+import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfProductsProviders;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.InlineResponse2002;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.InlineResponse201;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.PkgmSubscriptionRequest;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsAuthentication;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilter1;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsFilterVnfProductsFromProviders;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.SubscriptionsLinks;
+import org.onap.so.adapters.etsisol003adapter.pkgm.model.VnfPackagesLinksSelf;
+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.cache.Cache;
+import org.springframework.cache.CacheManager;
+import org.springframework.http.HttpHeaders;
+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.test.web.client.match.MockRestRequestMatchers;
+import org.springframework.web.client.RestTemplate;
+import com.google.gson.Gson;
+
+/**
+ * @author Ronan Kenny (ronan.kenny@est.tech)
+ * @author Gareth Roper (gareth.roper@est.tech)
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+public class Sol003PackageManagementSubscriptionControllerTest {
+
+ private final Gson gson = new Gson();
+ private final URI msbEndpoint = URI.create("http://msb-iag.onap:80/api/vnfpkgm/v1/subscriptions");
+ private static final String _NOTIFICATION_CALLBACK_URI =
+ "https://so-vnfm-adapter.onap:30406" + ETSI_SUBSCRIPTION_NOTIFICATION_BASE_URL;
+ private static final String LOCALHOST_URL = "http://localhost:";
+
+ @Autowired
+ @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN)
+ private RestTemplate restTemplate;
+ private MockRestServiceServer mockRestServiceServer;
+ @Autowired
+ private CacheManager cacheServiceProvider;
+ @Autowired
+ private Sol003PackageManagementSubscriptionController sol003PackageManagementSubscriptionController;
+
+ @Autowired
+ private TestRestTemplate testRestTemplate;
+
+ @LocalServerPort
+ private int port;
+
+ private static final String ID = UUID.randomUUID().toString();
+
+ @Before
+ public void setUp() {
+ mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build();
+ final Cache cache =
+ cacheServiceProvider.getCache(PackageManagementConstants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE);
+ cache.clear();
+ }
+
+ @After
+ public void after() {
+ mockRestServiceServer.reset();
+ }
+
+ @Test
+ public void testSuccessPostSubscription() throws GeneralSecurityException, URISyntaxException {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = postSubscriptionForTest();
+ final ResponseEntity<InlineResponse201> response =
+ (ResponseEntity<InlineResponse201>) sol003PackageManagementSubscriptionController
+ .postSubscriptionRequest(pkgmSubscriptionRequest);
+
+ final HttpHeaders headers = buildHttpHeaders(Objects.requireNonNull(response.getBody()).getCallbackUri());
+
+ final SubscriptionsLinks subscriptionsLinks = new SubscriptionsLinks();
+ final VnfPackagesLinksSelf vnfPackagesLinksSelf = new VnfPackagesLinksSelf();
+ vnfPackagesLinksSelf.setHref("https://so-vnfm-adapter.onap:30406" + PACKAGE_MANAGEMENT_BASE_URL
+ + "/subscriptions/" + response.getBody().getId());
+ subscriptionsLinks.setSelf(vnfPackagesLinksSelf);
+
+ assertEquals(pkgmSubscriptionRequest.getFilter(), response.getBody().getFilter());
+ assertEquals(subscriptionsLinks, response.getBody().getLinks());
+ assertEquals(response.getBody().getFilter(), pkgmSubscriptionRequest.getFilter());
+ assert (response.getHeaders().equals(headers));
+ assertThat(response.getStatusCode(), is(HttpStatus.CREATED));
+ assertNotNull(response.getBody().getCallbackUri());
+ }
+
+ @Test
+ public void testFailPostSubscriptionAlreadyExists() throws GeneralSecurityException {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = postSubscriptionForTest();
+
+ final ResponseEntity<InlineResponse2002> response =
+ (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
+ .postSubscriptionRequest(pkgmSubscriptionRequest);
+
+ // Create duplicate entry
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest2 = buildPkgmSubscriptionRequest();
+
+ final ResponseEntity<InlineResponse2002> response2002 =
+ (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
+ .postSubscriptionRequest(pkgmSubscriptionRequest2);
+
+ assertEquals(HttpStatus.SEE_OTHER, response2002.getStatusCode());
+ }
+
+ @Test
+ public void testSuccessGetSubscriptionWithSubscriptionId() throws GeneralSecurityException, URISyntaxException {
+
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = postSubscriptionForTest();
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(new NsdmSubscription().id(ID)), MediaType.APPLICATION_JSON));
+
+ final ResponseEntity<InlineResponse201> response =
+ (ResponseEntity<InlineResponse201>) sol003PackageManagementSubscriptionController
+ .postSubscriptionRequest(pkgmSubscriptionRequest);
+ final String subscriptionId = response.getBody().getId();
+
+
+
+ final ResponseEntity<InlineResponse201> responseEntity =
+ (ResponseEntity<InlineResponse201>) sol003PackageManagementSubscriptionController
+ .getSubscription(subscriptionId);
+
+ final HttpHeaders headers = buildHttpHeaders(response.getBody().getCallbackUri());
+
+ assertEquals(response.getBody().getFilter(), pkgmSubscriptionRequest.getFilter());
+ assertEquals(response.getHeaders(), headers);
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+ assertEquals(pkgmSubscriptionRequest.getFilter(), response.getBody().getFilter());
+ // Ensure CallBackUri is set to new URI
+ assertNotEquals(pkgmSubscriptionRequest.getCallbackUri(), response.getBody().getCallbackUri());
+ }
+
+ @Test
+ public void testFailGetSubscriptionWithInvalidSubscriptionId() {
+ final String invalidId = "invalidSubscriptionId";
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + invalidId)).andExpect(method(HttpMethod.GET))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
+ final ResponseEntity<?> response = sol003PackageManagementSubscriptionController.getSubscription(invalidId);
+ assertEquals(HttpStatus.NOT_FOUND, response.getStatusCode());
+ assertTrue(response.getBody() instanceof ProblemDetails);
+ }
+
+ @Test
+ public void testSuccessGetSubscriptions() throws GeneralSecurityException {
+ final PkgmSubscription pkgmSubscription = buildPkgmSubscription();
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = buildPkgmSubscriptionRequest();
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ .andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON));
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + ID)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(new NsdmSubscription().id(ID)), MediaType.APPLICATION_JSON));
+
+ sol003PackageManagementSubscriptionController.postSubscriptionRequest(pkgmSubscriptionRequest);
+ final ResponseEntity<List<InlineResponse201>> response =
+ sol003PackageManagementSubscriptionController.getSubscriptions();
+
+ final List<InlineResponse201> subscriptionsList = response.getBody();
+
+ assertEquals(Objects.requireNonNull(response.getBody()).get(0).getFilter(),
+ pkgmSubscriptionRequest.getFilter());
+ assertNotNull(subscriptionsList != null);
+ assertNotEquals('0', subscriptionsList.size());
+ assertEquals(HttpStatus.OK, response.getStatusCode());
+ }
+
+ @Test
+ public void testSuccessDeleteSubscriptionWithSubscriptionId() throws GeneralSecurityException {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = buildPkgmSubscriptionRequest();
+ final PkgmSubscription pkgmSubscription = buildPkgmSubscription();
+ final String subscriptionId = pkgmSubscription.getId();
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ .andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON));
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + subscriptionId)).andExpect(method(HttpMethod.DELETE))
+ .andRespond(withStatus(HttpStatus.NO_CONTENT));
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + subscriptionId)).andExpect(method(HttpMethod.GET))
+ .andRespond(withSuccess(gson.toJson(new NsdmSubscription().id(subscriptionId)),
+ MediaType.APPLICATION_JSON));
+
+ final ResponseEntity<InlineResponse2002> responsePost =
+ (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
+ .postSubscriptionRequest(pkgmSubscriptionRequest);
+
+ final ResponseEntity responseDelete =
+ sol003PackageManagementSubscriptionController.deleteSubscription(subscriptionId);
+
+ // Attempt to retrieve the subscription after delete
+ final ResponseEntity<InlineResponse2002> responseGetSubscription =
+ (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
+ .getSubscription(subscriptionId);
+
+ assertEquals(HttpStatus.NOT_FOUND, responseGetSubscription.getStatusCode());
+ assertEquals(HttpStatus.NO_CONTENT, responseDelete.getStatusCode());
+ }
+
+ @Test
+ public void testDeleteSubscription_SubscripitonNotFoundInEtsiCatalogManager_SubscriptionDeletedFromLocalCache()
+ throws GeneralSecurityException {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = buildPkgmSubscriptionRequest();
+ final PkgmSubscription pkgmSubscription = buildPkgmSubscription();
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ .andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON));
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint + "/" + ID)).andExpect(method(HttpMethod.DELETE))
+ .andRespond(withStatus(HttpStatus.NOT_FOUND));
+
+ final ResponseEntity<InlineResponse2002> responsePost =
+ (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController
+ .postSubscriptionRequest(pkgmSubscriptionRequest);
+
+ final Cache cache =
+ cacheServiceProvider.getCache(PackageManagementConstants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE);
+ assertNotNull(cache.get(ID));
+
+ final ResponseEntity responseDelete = sol003PackageManagementSubscriptionController.deleteSubscription(ID);
+
+ assertEquals(HttpStatus.NO_CONTENT, responseDelete.getStatusCode());
+ assertNull(cache.get(ID));
+
+ }
+
+ @Test
+ public void testFailDeleteSubscriptionWithInvalidSubscriptionId() throws URISyntaxException, InterruptedException {
+ final ResponseEntity<Void> responseDelete = (ResponseEntity<Void>) sol003PackageManagementSubscriptionController
+ .deleteSubscription("invalidSubscriptionId");
+ assertEquals(HttpStatus.NOT_FOUND, responseDelete.getStatusCode());
+ }
+
+
+ @Test
+ public void testSuccessPostSubscriptionWithValidNotificationTypes() throws Exception {
+
+ final String file = getAbsolutePath("src/test/resources/requests/SubscriptionRequest.json");
+ final String json = new String(Files.readAllBytes(Paths.get(file)));
+ final PkgmSubscriptionRequest request = gson.fromJson(json, PkgmSubscriptionRequest.class);
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ .andExpect(MockRestRequestMatchers.content().json(gson.toJson(getEtsiCatalogPkgmSubscriptionRequest())))
+ .andRespond(withSuccess(gson.toJson(buildPkgmSubscription()), MediaType.APPLICATION_JSON));
+
+
+ final ResponseEntity<InlineResponse201> responseEntity =
+ testRestTemplate.postForEntity(LOCALHOST_URL + port + PACKAGE_MANAGEMENT_BASE_URL + "/subscriptions",
+ request, InlineResponse201.class);
+
+ assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
+ assertTrue(responseEntity.hasBody());
+ final InlineResponse201 actual = responseEntity.getBody();
+ assertEquals(ID, actual.getId());
+
+
+ }
+
+ private org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest getEtsiCatalogPkgmSubscriptionRequest() {
+ return new org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.PkgmSubscriptionRequest()
+ .filter(new PkgmNotificationsFilter()
+ .addNotificationTypesItem(
+ PkgmNotificationsFilter.NotificationTypesEnum.VNFPACKAGEONBOARDINGNOTIFICATION)
+ .addVnfdIdItem("VNFDID").addVnfPkgIdItem("VNFPKGID")
+ .addOperationalStateItem(PkgmNotificationsFilter.OperationalStateEnum.ENABLED)
+ .addVnfProductsFromProvidersItem(new VnfProductsProviders().vnfProvider("EST")
+ .addVnfProductsItem(new VnfProducts().vnfProductName("VnfProducts")
+ .addVersionsItem(new Version().vnfSoftwareVersion("vnfSoftwareVersion")
+ .addVnfdVersionsItem("version1")))))
+ .callbackUri(_NOTIFICATION_CALLBACK_URI).authentication(
+ new SubscriptionAuthentication().addAuthTypeItem(SubscriptionAuthentication.AuthTypeEnum.BASIC)
+ .paramsBasic(new BasicAuth().userName("vnfm").password("password1$")));
+ }
+
+ private PkgmSubscriptionRequest buildPkgmSubscriptionRequest() {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = new PkgmSubscriptionRequest();
+ final SubscriptionsFilter1 sub = buildSubscriptionsFilter();
+ final SubscriptionsAuthentication auth = new SubscriptionsAuthentication();
+ pkgmSubscriptionRequest.setFilter(sub);
+ pkgmSubscriptionRequest.setCallbackUri(msbEndpoint.toString());
+ pkgmSubscriptionRequest.setAuthentication(auth);
+ return pkgmSubscriptionRequest;
+ }
+
+ private SubscriptionsFilter1 buildSubscriptionsFilter() {
+ final SubscriptionsFilter1 sub = new SubscriptionsFilter1();
+ final List<String> vnfdIdList = new ArrayList<>();
+ final List<String> vnfPkgIdList = new ArrayList<>();
+ final List<SubscriptionsFilter1.NotificationTypesEnum> notificationTypes = new ArrayList<>();
+ final SubscriptionsFilterVnfProductsFromProviders subscriptionsFilterVnfProductsFromProviders =
+ new SubscriptionsFilterVnfProductsFromProviders();
+ final List<SubscriptionsFilterVnfProductsFromProviders> vnfProductsFromProviders = new ArrayList<>();
+
+ vnfProductsFromProviders.add(subscriptionsFilterVnfProductsFromProviders);
+ sub.setVnfdId(vnfdIdList);
+ sub.setNotificationTypes(notificationTypes);
+ sub.setVnfPkgId(vnfPkgIdList);
+ sub.setVnfProductsFromProviders(vnfProductsFromProviders);
+ return sub;
+ }
+
+ private PkgmSubscription buildPkgmSubscription() {
+ final PkgmSubscription pkgmSubscription = new PkgmSubscription();
+ final PkgmNotificationsFilter pkgmNotificationsFilter = new PkgmNotificationsFilter();
+ final LinkSelf linkSelf = new LinkSelf();
+
+ pkgmSubscription.setId(ID);
+ pkgmSubscription.setCallbackUri(msbEndpoint + "/" + pkgmSubscription.getId().toString());
+ pkgmSubscription.setFilter(pkgmNotificationsFilter);
+ pkgmSubscription.setLinks(linkSelf);
+ return pkgmSubscription;
+ }
+
+ private PkgmSubscriptionRequest postSubscriptionForTest() {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest = buildPkgmSubscriptionRequest();
+ final PkgmSubscription pkgmSubscription = buildPkgmSubscription();
+
+ mockRestServiceServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST))
+ .andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON));
+ return pkgmSubscriptionRequest;
+ }
+
+ private HttpHeaders buildHttpHeaders(final String uri) throws URISyntaxException {
+ final HttpHeaders headers = new HttpHeaders();
+ final URI myUri = new URI(uri);
+ headers.setLocation(myUri);
+ return headers;
+ }
+
+ private String getAbsolutePath(final String path) {
+ final File file = new File(path);
+ return file.getAbsolutePath();
+ }
+
+}
diff --git a/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/TestApplication.java b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/TestApplication.java
new file mode 100755
index 0000000..3353552
--- /dev/null
+++ b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/TestApplication.java
@@ -0,0 +1,38 @@
+/*-
+ * ============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.etsisol003adapter.pkgm.rest;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
+import org.springframework.cache.annotation.EnableCaching;
+
+@EnableCaching
+@SpringBootApplication(scanBasePackages = {"org.onap.so"})
+@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class})
+public class TestApplication {
+
+ public static void main(final String[] args) {
+ new SpringApplication(TestApplication.class).run(args);
+ }
+
+}
diff --git a/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/resources/application.yaml b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/resources/application.yaml
new file mode 100644
index 0000000..cdb6662
--- /dev/null
+++ b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/resources/application.yaml
@@ -0,0 +1,61 @@
+# Copyright © 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.
+spring:
+ security:
+ usercredentials:
+ - username: test
+ password: '$2a$12$Zi3AuYcZoZO/gBQyUtST2.F5N6HqcTtaNci2Et.ufsQhski56srIu'
+ role: BPEL-Client
+ - username: vnfm
+ password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke'
+ role: BPEL-Client
+ main:
+ allow-bean-definition-overriding: true
+
+mso:
+ key: 07a7159d3bf51a0e53be7a8f89699be7
+
+aai:
+ auth: 2A11B07DB6214A839394AA1EC5844695F5114FC407FF5422625FB00175A3DCB8A1FF745F22867EFA72D5369D599BBD88DA8BED4233CF5586
+ endpoint: https://aai.onap:8443
+ version: v15
+
+sdc:
+ username: sdcUser
+ password: sdcPassword
+ key: adadadadad
+ endpoint: http://sdc.onap/1234A
+
+
+vnfmadapter:
+ endpoint: https://so-vnfm-adapter.onap:30406
+
+
+#Actuator
+management:
+ endpoints:
+ web:
+ base-path: /manage
+ exposure:
+ include: "*"
+ metrics:
+ se-global-registry: false
+ export:
+ prometheus:
+ enabled: true # Whether exporting of metrics to Prometheus is enabled.
+ step: 1m # Step size (i.e. reporting frequency) to use.
+
+etsi-catalog-manager:
+ vnfpkgm:
+ endpoint: http://msb-iag.onap:80/api/vnfpkgm/v1
diff --git a/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/resources/requests/SubscriptionRequest.json b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/resources/requests/SubscriptionRequest.json
new file mode 100644
index 0000000..c38466f
--- /dev/null
+++ b/so-etsi-sol003-adapter-pkgm/so-etsi-sol003-adapter-pkgm-service/src/test/resources/requests/SubscriptionRequest.json
@@ -0,0 +1,45 @@
+{
+ "filter":
+ {
+ "notificationTypes": [
+ "VnfPackageOnboardingNotification"
+ ],
+ "vnfProductsFromProviders": [
+ {
+ "vnfProvider": "EST",
+ "vnfProducts": [
+ {
+ "vnfProductName": "VnfProducts",
+ "versions": [
+ {
+ "vnfSoftwareVersion": "vnfSoftwareVersion",
+ "vnfdVersions": [
+ "version1"
+ ]
+ }
+ ]
+ }
+ ]
+ }
+ ],
+ "vnfdId": [
+ "VNFDID"
+ ],
+ "vnfPkgId": [
+ "VNFPKGID"
+ ],
+ "operationalState": ["ENABLED"]
+ },
+ "callbackUri": "http://so-vnfm-adapter:9093/api/vnfpkgm/v1/subscriptions",
+ "authentication":
+ {
+ "authType": [
+ "BASIC"
+ ],
+ "paramsBasic":
+ {
+ "userName": "vnfm",
+ "password": "vnfm"
+ }
+ }
+}