diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2020-04-08 15:48:21 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2020-04-09 15:57:53 +0100 |
commit | 12bfb7b86a783f63b8072ac67462202d59173940 (patch) | |
tree | 9c7699f462510d0fee349d28a577233a9cbfb23b /adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test | |
parent | 35121d207a7408414c2e46ba8afd76fb492101b1 (diff) |
Refactor SOL003 Adapter to organize its modules
based on functions
Change-Id: I10b2376a552272ac3b405b2dae718adcb7e1e489
Issue-ID: SO-2771
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test')
9 files changed, 0 insertions, 3062 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java deleted file mode 100644 index 29afa8c549..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java +++ /dev/null @@ -1,595 +0,0 @@ -/*- - * ============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.vnfmadapter.rest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.onap.so.adapters.vnfmadapter.Constants.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.*; -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.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.vnfmadapter.Constants; -import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.NOTIFICATIONLINKSERIALIZER; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgChangeNotification; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgOnboardingNotification; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgmLinks; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthentication; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthenticationParamsBasic; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthenticationParamsOauth2ClientCredentials; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.VnfPackageChangeNotification; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.VnfPackageOnboardingNotification; -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.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.http.*; -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 org.threeten.bp.LocalDateTime; -import org.threeten.bp.OffsetDateTime; -import org.threeten.bp.ZoneOffset; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; - -/** - * @author Andrew Lamb (andrew.a.lamb@est.tech) - * - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = VnfmAdapterApplication.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 OffsetDateTime TIMESTAMP = - OffsetDateTime.of(LocalDateTime.of(2020, 1, 1, 1, 1, 1, 1), ZoneOffset.ofHours(1)); - private static final String VNFPKG_ID = UUID.randomUUID().toString(); - private static final String VNFD_ID = UUID.randomUUID().toString(); - - private BasicHttpHeadersProvider basicHttpHeadersProvider; - private final Gson gson = new GsonBuilder().create();; - - @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) - private RestTemplate restTemplate; - private MockRestServiceServer mockRestServer; - - @Autowired - private TestRestTemplate testRestTemplate; - - @Autowired - private CacheManager cacheServiceProvider; - private Cache cache; - - @Before - public void setUp() { - mockRestServer = MockRestServiceServer.bindTo(restTemplate).build(); - basicHttpHeadersProvider = new BasicHttpHeadersProvider(); - cache = cacheServiceProvider.getCache(Constants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE); - cache.clear(); - } - - @After - public void tearDown() { - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.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(TIMESTAMP.toString())) - .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID.toString())) - .andExpect(jsonPath("$.vnfdId").value(VNFD_ID.toString())) - .andExpect(jsonPath("$._links").value(buildPkgmLinks())) - .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess()); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - } - - @Test - public void testOnboardingNotificationNotSentOnToVnfmCallbackUri_SubscriptionRequestNotInCache_Fail() { - final PkgOnboardingNotification notification = buildPkgOnboardingNotification(); - final String notificationString = gson.toJson(notification); - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST)) - .andRespond(withStatus(HttpStatus.BAD_REQUEST)); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST)) - .andRespond(withStatus(HttpStatus.MOVED_PERMANENTLY)); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST)) - .andRespond(withStatus(HttpStatus.NOT_FOUND)); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST)) - .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.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(TIMESTAMP.toString())) - .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID.toString())) - .andExpect(jsonPath("$.vnfdId").value(VNFD_ID.toString())) - .andExpect( - jsonPath("$.changeType").value(PkgChangeNotification.ChangeTypeEnum.OP_STATE_CHANGE.toString())) - .andExpect(jsonPath("$.operationalState") - .value(PkgChangeNotification.OperationalStateEnum.ENABLED.toString())) - .andExpect(jsonPath("$._links").value(buildPkgmLinks())) - .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess()); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - } - - @Test - public void testChangeNotificationNotSentOnToVnfmCallbackUri_SubscriptionRequestNotInCache_Fail() { - final PkgChangeNotification notification = buildPkgChangeNotification(); - final String notificationString = gson.toJson(notification); - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST)) - .andRespond(withStatus(HttpStatus.BAD_REQUEST)); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST)) - .andRespond(withStatus(HttpStatus.NOT_FOUND)); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST)) - .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.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(TIMESTAMP.toString())) - .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID.toString())) - .andExpect(jsonPath("$.vnfdId").value(VNFD_ID.toString())) - .andExpect(jsonPath("$._links").value(buildPkgmLinks())) - .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess()); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST)) - .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)) - .andRespond(withStatus(HttpStatus.UNAUTHORIZED)); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST)) - .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)) - .andRespond(withSuccess(JSON_TOKEN, MediaType.APPLICATION_JSON)); - - mockRestServer.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(TIMESTAMP.toString())) - .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID.toString())) - .andExpect(jsonPath("$.vnfdId").value(VNFD_ID.toString())) - .andExpect( - jsonPath("$.changeType").value(PkgChangeNotification.ChangeTypeEnum.OP_STATE_CHANGE.toString())) - .andExpect(jsonPath("$.operationalState") - .value(PkgChangeNotification.OperationalStateEnum.ENABLED.toString())) - .andExpect(jsonPath("$._links").value(buildPkgmLinks())).andRespond(withSuccess()); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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(); - final String notificationString = gson.toJson(notification); - - mockRestServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST)) - .andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess()); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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 String notificationString = gson.toJson(notification); - - final ResponseEntity<?> response = sendHttpPost(notificationString); - - 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() { - final PkgmLinks pkgmLinks = new PkgmLinks(); - - final NOTIFICATIONLINKSERIALIZER subscriptionLinkSerializer = new NOTIFICATIONLINKSERIALIZER(); - subscriptionLinkSerializer.setHref("subscription_href"); - pkgmLinks.setSubscription(subscriptionLinkSerializer); - - final NOTIFICATIONLINKSERIALIZER vnfPackageLinkSerializer = new NOTIFICATIONLINKSERIALIZER(); - vnfPackageLinkSerializer.setHref("vnf_package_href"); - pkgmLinks.setVnfPackage(vnfPackageLinkSerializer); - - return pkgmLinks; - } - - 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/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java deleted file mode 100644 index 07c471ec87..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============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 org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.junit4.SpringRunner; -import java.net.URI; -import static org.junit.Assert.assertEquals; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") -public class HealthCheckTest { - - @LocalServerPort - private int port; - - private final TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); - - @Test - public void testHealthcheck() throws Exception { - final RequestEntity<Void> request = - RequestEntity.get(new URI("http://localhost:" + port + "/manage/health")).build(); - final ResponseEntity<Void> response = restTemplate.exchange(request, Void.class); - assertEquals(200, response.getStatusCode().value()); - } - -} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java deleted file mode 100644 index 69223d7922..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantControllerTest.java +++ /dev/null @@ -1,256 +0,0 @@ -/*- - * ============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.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.hamcrest.MockitoHamcrest; -import org.onap.aai.domain.yang.EsrSystemInfo; -import org.onap.aai.domain.yang.EsrSystemInfoList; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aai.domain.yang.RelationshipList; -import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantRequest.OperationEnum; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources.TypeEnum; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsLinks; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsLinksVnfLcmOpOcc; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201VimConnections; -import org.onap.so.client.aai.AAIResourcesClient; -import org.onap.so.client.aai.entities.uri.AAIResourceUri; -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.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -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; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") -public class Sol003GrantControllerTest { - - private static final String CLOUD_OWNER = "myTestCloudOwner"; - private static final String REGION = "myTestRegion"; - private static final String TENANT_ID = "myTestTenantId"; - private static final String SEPARATOR = "_"; - private static final String vimConnectionId = CLOUD_OWNER + SEPARATOR + REGION; - - @LocalServerPort - private int port; - @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) - private RestTemplate testRestTemplate; - private MockRestServiceServer mockRestServer; - - @MockBean - private AAIResourcesClient aaiResourcesClient; - - @Autowired - private Sol003GrantController controller; - - @Before - public void setUp() throws Exception { - mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build(); - setUpVimInMockAai(); - } - - @Test - public void grantRequest_ValidRequestInstantiate_GrantApproved() { - final GrantRequest grantRequest = createGrantRequest("INSTANTIATE"); - setUpGenericVnfWithVnfmRelationshipInMockAai("vnfmType", "vnfm1"); - final ResponseEntity<InlineResponse201> response = controller.grantsPost(grantRequest); - assertEquals(HttpStatus.CREATED, response.getStatusCode()); - assertEquals(1, response.getBody().getAddResources().size()); - assertNull(response.getBody().getRemoveResources()); - - assertEquals(vimConnectionId, response.getBody().getAddResources().get(0).getVimConnectionId()); - assertEquals("myTestVnfIdOnVnfm", response.getBody().getVnfInstanceId()); - assertEquals("123456", response.getBody().getVnfLcmOpOccId()); - - final InlineResponse201VimConnections vimConnections = response.getBody().getVimConnections().get(0); - assertEquals(vimConnectionId, vimConnections.getVimId()); - assertEquals("OPENSTACK", vimConnections.getVimType()); - assertNotNull(vimConnections.getAccessInfo()); - assertNotNull(vimConnections.getInterfaceInfo()); - assertEquals("INSTANTIATE", grantRequest.getOperation().toString()); - } - - @Test - public void getGrant_notSupported_returns501() { - final ResponseEntity<InlineResponse201> response2 = controller.grantsGrantIdGet("myTestGrantId"); - assertEquals(HttpStatus.NOT_IMPLEMENTED, response2.getStatusCode()); - } - - @Test - public void grantRequest_ValidRequestTerminate_GrantApproved() { - final GrantRequest grantRequest = createGrantRequest("TERMINATE"); - setUpGenericVnfWithVnfmRelationshipInMockAai("vnfmType", "vnfm1"); - final ResponseEntity<InlineResponse201> response = controller.grantsPost(grantRequest); - - assertEquals(HttpStatus.CREATED, response.getStatusCode()); - assertNull(response.getBody().getAddResources()); - assertEquals(1, response.getBody().getRemoveResources().size()); - assertEquals(vimConnectionId, response.getBody().getRemoveResources().get(0).getVimConnectionId()); - assertEquals("myTestVnfIdOnVnfm", response.getBody().getVnfInstanceId()); - assertEquals("123456", response.getBody().getVnfLcmOpOccId()); - - final InlineResponse201VimConnections vimConnections = response.getBody().getVimConnections().get(0); - assertEquals(vimConnectionId, vimConnections.getVimId()); - assertEquals("OPENSTACK", vimConnections.getVimType()); - assertNotNull(vimConnections.getAccessInfo()); - assertNotNull(vimConnections.getInterfaceInfo()); - assertEquals("TERMINATE", grantRequest.getOperation().toString()); - - } - - private GrantRequest createGrantRequest(final String operation) { - final GrantRequest grantRequest = new GrantRequest(); - grantRequest.setVnfInstanceId("myTestVnfIdOnVnfm"); - grantRequest.setVnfLcmOpOccId("123456"); - grantRequest.links(new GrantsLinks() - .vnfInstance(new GrantsLinksVnfLcmOpOcc().href("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"))); - if (operation == "INSTANTIATE") { - grantRequest.setOperation(OperationEnum.INSTANTIATE); - final GrantsAddResources resource = new GrantsAddResources(); - resource.setId("123"); - resource.setType(TypeEnum.COMPUTE); - grantRequest.addAddResourcesItem(resource); - } else if (operation == "TERMINATE") { - grantRequest.setOperation(OperationEnum.TERMINATE); - final GrantsAddResources resource = new GrantsAddResources(); - resource.setId("123"); - resource.setType(TypeEnum.COMPUTE); - grantRequest.addRemoveResourcesItem(resource); - } - - return grantRequest; - } - - private void setUpVimInMockAai() { - final EsrSystemInfo esrSystemInfo = new EsrSystemInfo(); - esrSystemInfo.setServiceUrl("http://myVim:8080"); - esrSystemInfo.setType("OPENSTACK"); - esrSystemInfo.setSystemType("VIM"); - esrSystemInfo.setCloudDomain("myDomain"); - esrSystemInfo.setUserName("myUser"); - esrSystemInfo.setPassword("myPassword"); - - final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList(); - esrSystemInfoList.getEsrSystemInfo().add(esrSystemInfo); - - doReturn(Optional.of(esrSystemInfoList)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher("/cloud-infrastructure/cloud-regions/cloud-region/" - + CLOUD_OWNER + "/" + REGION + "/esr-system-info-list"))); - } - - private GenericVnf createGenericVnf(final String type) { - final GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId("myTestVnfId"); - genericVnf.setNfType(type); - return genericVnf; - } - - private void setUpGenericVnfWithVnfmRelationshipInMockAai(final String type, final String vnfmId) { - final GenericVnf genericVnf = createGenericVnf(type); - - final Relationship relationshipToVnfm = new Relationship(); - relationshipToVnfm.setRelatedTo("tenant"); - final RelationshipData relationshipData1 = new RelationshipData(); - final RelationshipData relationshipData2 = new RelationshipData(); - final RelationshipData relationshipData3 = new RelationshipData(); - - relationshipData1.setRelationshipKey("cloud-region.cloud-owner"); - relationshipData1.setRelationshipValue(CLOUD_OWNER); - relationshipData2.setRelationshipKey("cloud-region.cloud-region-id"); - relationshipData2.setRelationshipValue(REGION); - relationshipData3.setRelationshipKey("tenant.tenant-id"); - relationshipData3.setRelationshipValue(TENANT_ID); - - relationshipToVnfm.getRelationshipData().add(relationshipData1); - relationshipToVnfm.getRelationshipData().add(relationshipData2); - relationshipToVnfm.getRelationshipData().add(relationshipData3); - - final RelationshipList relationshipList = new RelationshipList(); - relationshipList.getRelationship().add(relationshipToVnfm); - genericVnf.setRelationshipList(relationshipList); - - doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId"))); - - final List<GenericVnf> listOfGenericVnfs = new ArrayList<>(); - listOfGenericVnfs.add(genericVnf); - final GenericVnfs genericVnfs = new GenericVnfs(); - genericVnfs.getGenericVnf().addAll(listOfGenericVnfs); - doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher( - "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm"))); - } - - private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> { - - final String uriAsString; - - public AaiResourceUriMatcher(final String uriAsString) { - this.uriAsString = uriAsString; - } - - @Override - public boolean matches(final Object item) { - if (item instanceof AAIResourceUri) { - if (uriAsString.endsWith("...")) { - return ((AAIResourceUri) item).build().toString() - .startsWith(uriAsString.substring(0, uriAsString.indexOf("..."))); - } - return ((AAIResourceUri) item).build().toString().equals(uriAsString); - } - return false; - } - - @Override - public void describeTo(final Description description) {} - - } - -} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java deleted file mode 100644 index cd92d987d7..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003LcnControllerTest.java +++ /dev/null @@ -1,415 +0,0 @@ -/*- - * ============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.assertEquals; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; -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 com.google.gson.Gson; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import javax.inject.Inject; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.hamcrest.MockitoHamcrest; -import org.onap.aai.domain.yang.EsrSystemInfoList; -import org.onap.aai.domain.yang.EsrVnfm; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.GenericVnfs; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aai.domain.yang.RelationshipList; -import org.onap.aai.domain.yang.Vserver; -import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiHelper; -import org.onap.so.adapters.vnfmadapter.extclients.aai.OamIpAddressSource; -import org.onap.so.adapters.vnfmadapter.extclients.aai.OamIpAddressSource.OamIpAddressType; -import org.onap.so.adapters.vnfmadapter.extclients.vim.model.AccessInfo; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs.ChangeTypeEnum; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationComputeResource; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinks; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfIdentifierCreationNotification; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationEnum; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification.OperationStateEnum; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201Links; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201LinksSelf; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201VimConnectionInfo; -import org.onap.so.client.aai.AAIResourcesClient; -import org.onap.so.client.aai.AAIVersion; -import org.onap.so.client.aai.entities.uri.AAIResourceUri; -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.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.web.server.LocalServerPort; -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; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") -public class Sol003LcnControllerTest { - - private static final String CLOUD_OWNER = "myTestCloudOwner"; - private static final String REGION = "myTestRegion"; - private static final String TENANT_ID = "myTestTenantId"; - - @LocalServerPort - private int port; - @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) - private RestTemplate testRestTemplate; - private MockRestServiceServer mockRestServer; - - @MockBean - private AAIResourcesClient aaiResourcesClient; - - @Autowired - private Sol003LcnContoller controller; - private final Gson gson = new Gson(); - - @Inject - private AaiHelper aaiHelper; - - @Before - public void setUp() throws Exception { - mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build(); - } - - @Test - public void lcnNotification_IdentifierCreated_Returns204() throws URISyntaxException, InterruptedException { - final VnfIdentifierCreationNotification vnfIdentifierCreationNotification = - new VnfIdentifierCreationNotification(); - final ResponseEntity<Void> response = - controller.lcnVnfIdentifierCreationNotificationPost(vnfIdentifierCreationNotification); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - } - - @Test - public void lcnNotification_IdentifierDeleted_Returns204() throws URISyntaxException, InterruptedException { - final VnfIdentifierCreationNotification vnfIdentifierCreationNotification = - new VnfIdentifierCreationNotification(); - final ResponseEntity<Void> response = - controller.lcnVnfIdentifierCreationNotificationPost(vnfIdentifierCreationNotification); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - } - - @Test - public void lcnNotification_InstantiateStartingOrProcessing_NoAction() - throws URISyntaxException, InterruptedException { - final VnfLcmOperationOccurrenceNotification startingNotification = new VnfLcmOperationOccurrenceNotification(); - startingNotification.setOperation(OperationEnum.INSTANTIATE); - startingNotification.setOperationState(OperationStateEnum.STARTING); - - ResponseEntity<Void> response = controller.lcnVnfLcmOperationOccurrenceNotificationPost(startingNotification); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - - verifyZeroInteractions(aaiResourcesClient); - - final VnfLcmOperationOccurrenceNotification processingNotification = - new VnfLcmOperationOccurrenceNotification(); - processingNotification.setOperation(OperationEnum.INSTANTIATE); - processingNotification.setOperationState(OperationStateEnum.STARTING); - - response = controller.lcnVnfLcmOperationOccurrenceNotificationPost(processingNotification); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - - verifyZeroInteractions(aaiResourcesClient); - } - - @Test - public void lcnNotification_InstantiateCompleted_AaiUpdated() throws URISyntaxException, InterruptedException { - final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification = - createNotification(OperationEnum.INSTANTIATE); - addVnfcsToNotification(vnfLcmOperationOccurrenceNotification, ChangeTypeEnum.ADDED); - final InlineResponse201 vnfInstance = createVnfInstance(); - - mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"))) - .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON)); - - final GenericVnf genericVnf = createGenericVnf("vnfmType1"); - addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1"); - final List<GenericVnf> listOfGenericVnfs = new ArrayList<>(); - listOfGenericVnfs.add(genericVnf); - final GenericVnfs genericVnfs = new GenericVnfs(); - genericVnfs.getGenericVnf().addAll(listOfGenericVnfs); - doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher( - "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm"))); - EsrVnfm vnfm = new EsrVnfm(); - vnfm.setVnfmId("vnfm1"); - final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList(); - vnfm.setEsrSystemInfoList(esrSystemInfoList); - doReturn(Optional.of(vnfm)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest - .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1"))); - - final ResponseEntity<Void> response = - controller.lcnVnfLcmOperationOccurrenceNotificationPost(vnfLcmOperationOccurrenceNotification); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - - final ArgumentCaptor<Object> bodyArgument1 = ArgumentCaptor.forClass(Object.class); - final ArgumentCaptor<AAIResourceUri> uriArgument1 = ArgumentCaptor.forClass(AAIResourceUri.class); - - verify(aaiResourcesClient, timeout(1000)).update(uriArgument1.capture(), bodyArgument1.capture()); - - assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", - uriArgument1.getAllValues().get(0).build().toString()); - final GenericVnf updatedGenericVnf = (GenericVnf) bodyArgument1.getAllValues().get(0); - assertEquals("10.10.10.10", updatedGenericVnf.getIpv4OamAddress()); - assertEquals("Created", updatedGenericVnf.getOrchestrationStatus()); - - final ArgumentCaptor<Object> bodyArgument2 = ArgumentCaptor.forClass(Object.class); - final ArgumentCaptor<AAIResourceUri> uriArgument2 = ArgumentCaptor.forClass(AAIResourceUri.class); - verify(aaiResourcesClient, timeout(1000)).create(uriArgument2.capture(), bodyArgument2.capture()); - - assertEquals( - "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/" - + TENANT_ID + "/vservers/vserver/myVnfc1", - uriArgument2.getAllValues().get(0).build().toString()); - - final Vserver vserver = (Vserver) bodyArgument2.getAllValues().get(0); - assertEquals("myVnfc1", vserver.getVserverId()); - - final ArgumentCaptor<AAIResourceUri> uriArgument1Connect = ArgumentCaptor.forClass(AAIResourceUri.class); - final ArgumentCaptor<AAIResourceUri> uriArgument2Connect = ArgumentCaptor.forClass(AAIResourceUri.class); - verify(aaiResourcesClient, timeout(1000)).connect(uriArgument1Connect.capture(), uriArgument2Connect.capture()); - assertEquals( - "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/" - + TENANT_ID + "/vservers/vserver/myVnfc1", - uriArgument1Connect.getAllValues().get(0).build().toString()); - assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", - uriArgument2Connect.getAllValues().get(0).build().toString()); - } - - @Test - public void lcnNotification_TerminateCompleted_AaiUpdated() throws URISyntaxException, InterruptedException { - final VnfLcmOperationOccurrenceNotification vnfLcmOperationOccurrenceNotification = - createNotification(OperationEnum.TERMINATE); - addVnfcsToNotification(vnfLcmOperationOccurrenceNotification, ChangeTypeEnum.REMOVED); - - final InlineResponse201 vnfInstance = createVnfInstance(); - - mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"))) - .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON)); - - mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"))) - .andRespond(withStatus(HttpStatus.NO_CONTENT).contentType(MediaType.APPLICATION_JSON)); - - final GenericVnf genericVnf = createGenericVnf("vnfmType1"); - addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1"); - genericVnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"); - final List<GenericVnf> listOfGenericVnfs = new ArrayList<>(); - listOfGenericVnfs.add(genericVnf); - final GenericVnfs genericVnfs = new GenericVnfs(); - genericVnfs.getGenericVnf().addAll(listOfGenericVnfs); - addRelationshipFromGenericVnfToVserver(genericVnf, "myVnfc1"); - - doReturn(Optional.of(genericVnfs)).when(aaiResourcesClient).get(eq(GenericVnfs.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher( - "/network/generic-vnfs?selflink=http%3A%2F%2Fvnfm%3A8080%2Fvnfs%2FmyTestVnfIdOnVnfm"))); - EsrVnfm vnfm = new EsrVnfm(); - vnfm.setVnfmId("vnfm1"); - final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList(); - vnfm.setEsrSystemInfoList(esrSystemInfoList); - doReturn(Optional.of(vnfm)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest - .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1"))); - - final ResponseEntity<Void> response = - controller.lcnVnfLcmOperationOccurrenceNotificationPost(vnfLcmOperationOccurrenceNotification); - assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode()); - - final ArgumentCaptor<GenericVnf> genericVnfArgument = ArgumentCaptor.forClass(GenericVnf.class); - final ArgumentCaptor<AAIResourceUri> updateUriArgument = ArgumentCaptor.forClass(AAIResourceUri.class); - verify(aaiResourcesClient, timeout(10000000)).update(updateUriArgument.capture(), genericVnfArgument.capture()); - assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", updateUriArgument.getValue().build().toString()); - assertEquals("Assigned", genericVnfArgument.getValue().getOrchestrationStatus()); - - final ArgumentCaptor<AAIResourceUri> deleteUriArgument = ArgumentCaptor.forClass(AAIResourceUri.class); - - verify(aaiResourcesClient, timeout(10000000)).delete(deleteUriArgument.capture()); - - assertEquals( - "/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + "/" + REGION + "/tenants/tenant/" - + TENANT_ID + "/vservers/vserver/myVnfc1", - deleteUriArgument.getAllValues().get(0).build().toString()); - } - - private VnfLcmOperationOccurrenceNotification createNotification(final OperationEnum operation) { - final VnfLcmOperationOccurrenceNotification notification = new VnfLcmOperationOccurrenceNotification(); - notification.setOperation(operation); - notification.setOperationState(OperationStateEnum.COMPLETED); - - final LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance linkToVnfInstance = - new LcnVnfLcmOperationOccurrenceNotificationLinksVnfInstance() - .href("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"); - final LcnVnfLcmOperationOccurrenceNotificationLinks operationLinks = - new LcnVnfLcmOperationOccurrenceNotificationLinks().vnfInstance(linkToVnfInstance); - notification.setLinks(operationLinks); - - return notification; - } - - private void addVnfcsToNotification(final VnfLcmOperationOccurrenceNotification notification, - final ChangeTypeEnum changeType) { - final List<LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs> affectedVnfcs = new ArrayList<>();; - final LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs vnfc = - new LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs(); - vnfc.changeType(changeType); - final LcnVnfLcmOperationOccurrenceNotificationComputeResource computeResource = - new LcnVnfLcmOperationOccurrenceNotificationComputeResource(); - computeResource.setResourceId("myVnfc1"); - computeResource.setVimConnectionId(CLOUD_OWNER + "_" + REGION); - vnfc.setComputeResource(computeResource); - affectedVnfcs.add(vnfc); - notification.setAffectedVnfcs(affectedVnfcs); - } - - private InlineResponse201 createVnfInstance() { - final InlineResponse201 vnfInstance = new InlineResponse201(); - vnfInstance.setId("myTestVnfIdOnVnfm"); - final InlineResponse201LinksSelf selfLink = new InlineResponse201LinksSelf(); - selfLink.setHref("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"); - final InlineResponse201Links VnfInstancelinks = new InlineResponse201Links(); - VnfInstancelinks.setSelf(selfLink); - vnfInstance.setLinks(VnfInstancelinks); - - final Map<String, String> vnfConfigurableProperties = new HashMap<>(); - vnfConfigurableProperties.put("vnfIpAddress", "10.10.10.10"); - vnfInstance.setVnfConfigurableProperties(vnfConfigurableProperties); - - final List<InlineResponse201VimConnectionInfo> vimConnectionInfo = new ArrayList<>();; - final InlineResponse201VimConnectionInfo vimConnection = new InlineResponse201VimConnectionInfo(); - vimConnection.setVimId(CLOUD_OWNER + "_" + REGION); - vimConnection.setId(CLOUD_OWNER + "_" + REGION); - final AccessInfo accessInfo = new AccessInfo(); - accessInfo.setProjectId(TENANT_ID); - vimConnection.setAccessInfo(accessInfo); - vimConnectionInfo.add(vimConnection); - vnfInstance.setVimConnectionInfo(vimConnectionInfo); - - final OamIpAddressSource oamIpAddressSource = - new OamIpAddressSource(OamIpAddressType.CONFIGURABLE_PROPERTY, "vnfIpAddress"); - aaiHelper.setOamIpAddressSource("myTestVnfIdOnVnfm", oamIpAddressSource); - return vnfInstance; - } - - private GenericVnf createGenericVnf(final String type) { - final GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId("myTestVnfId"); - genericVnf.setNfType(type); - return genericVnf; - } - - private void addRelationshipFromGenericVnfToVnfm(final GenericVnf genericVnf, final String vnfmId) { - final Relationship relationshipToVnfm = new Relationship(); - relationshipToVnfm.setRelatedLink("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/" + vnfmId); - relationshipToVnfm.setRelatedTo("esr-vnfm"); - final RelationshipData relationshipData = new RelationshipData(); - relationshipData.setRelationshipKey("esr-vnfm.vnfm-id"); - relationshipData.setRelationshipValue(vnfmId); - relationshipToVnfm.getRelationshipData().add(relationshipData); - - if (genericVnf.getRelationshipList() == null) { - final RelationshipList relationshipList = new RelationshipList(); - genericVnf.setRelationshipList(relationshipList); - } - genericVnf.getRelationshipList().getRelationship().add(relationshipToVnfm); - } - - private void addRelationshipFromGenericVnfToVserver(final GenericVnf genericVnf, final String vserverId) { - final Relationship relationshipToVserver = new Relationship(); - relationshipToVserver.setRelatedTo("vserver"); - final RelationshipData relationshipData1 = new RelationshipData(); - relationshipData1.setRelationshipKey("vserver.vserver-id"); - relationshipData1.setRelationshipValue(vserverId); - relationshipToVserver.getRelationshipData().add(relationshipData1); - final RelationshipData relationshipData2 = new RelationshipData(); - relationshipData2.setRelationshipKey("cloud-region.cloud-owner"); - relationshipData2.setRelationshipValue(CLOUD_OWNER); - relationshipToVserver.getRelationshipData().add(relationshipData2); - final RelationshipData relationshipData3 = new RelationshipData(); - relationshipData3.setRelationshipKey("cloud-region.cloud-region-id"); - relationshipData3.setRelationshipValue(REGION); - relationshipToVserver.getRelationshipData().add(relationshipData3); - final RelationshipData relationshipData4 = new RelationshipData(); - relationshipData4.setRelationshipKey("tenant.tenant-id"); - relationshipData4.setRelationshipValue(TENANT_ID); - relationshipToVserver.getRelationshipData().add(relationshipData4); - - if (genericVnf.getRelationshipList() == null) { - final RelationshipList relationshipList = new RelationshipList(); - genericVnf.setRelationshipList(relationshipList); - } - genericVnf.getRelationshipList().getRelationship().add(relationshipToVserver); - } - - private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> { - - final String uriAsString; - - public AaiResourceUriMatcher(final String uriAsString) { - this.uriAsString = uriAsString; - } - - @Override - public boolean matches(final Object item) { - if (item instanceof AAIResourceUri) { - if (uriAsString.endsWith("...")) { - return ((AAIResourceUri) item).build().toString() - .startsWith(uriAsString.substring(0, uriAsString.indexOf("..."))); - } - return ((AAIResourceUri) item).build().toString().equals(uriAsString); - } - return false; - } - - @Override - public void describeTo(final Description description) {} - - } - -} 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 deleted file mode 100644 index be8b0c2e0b..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java +++ /dev/null @@ -1,671 +0,0 @@ -/*- - * ============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.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL; -import static org.onap.so.adapters.vnfmadapter.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.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.Checksum; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.UriLink; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VNFPKGMLinkSerializer; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPackageArtifactInfo; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPackageSoftwareImageInfo; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPkgInfo; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.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 = VnfmAdapterApplication.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 mockRestServer; - 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); - mockRestServer = builder.build(); - basicHttpHeadersProvider = new BasicHttpHeadersProvider(); - } - - @Test - public void testGetPackageContent_ValidArray_Success() { - final 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 = - 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() { - 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 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 testOnGetPackageContent_UnauthorizedClient_Fail() { - final String testURL = "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/" - + VNF_PACKAGE_ID + "/package_content"; - - mockRestServer.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() { - 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 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()); - } - - @Test - public void testGetPackageArtifact_ValidArray_Success() { - final byte[] responseArray = buildByteArrayWithRandomData(10); - - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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; - - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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(); - - mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson(responses), MediaType.APPLICATION_JSON)); - - final String testURL = localhostUrl + port + VNFPKGM_BASE_URL; - final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); - - final ResponseEntity<InlineResponse2001[]> responseEntity = 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() { - mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET)) - .andRespond(withStatus(HttpStatus.BAD_REQUEST)); - - final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL); - assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); - - assertNotNull(responseEntity.getBody()); - final ProblemDetails problemDetails = responseEntity.getBody(); - assertEquals("Error: Bad Request Received", problemDetails.getDetail()); - } - - @Test - public void test404NotFoundInfoReceivedAsProblemDetailsIfGetVnfPackagesIs404NotFound() { - mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET)) - .andRespond(withStatus(HttpStatus.NOT_FOUND)); - - final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL); - assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); - - assertNotNull(responseEntity.getBody()); - final ProblemDetails problemDetails = responseEntity.getBody(); - assertEquals("No Vnf Packages found", problemDetails.getDetail()); - } - - @Test - public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackagesReturns500InternalServerError() { - mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET)) - .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); - - final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); - - assertNotNull(responseEntity.getBody()); - final ProblemDetails problemDetails = responseEntity.getBody(); - assertEquals("Internal Server Error Occurred.", problemDetails.getDetail()); - } - - @Test - public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackagesReturnsANullPackage() { - mockRestServer.expect(requestTo(MSB_BASE_URL)).andExpect(method(HttpMethod.GET)).andRespond(withSuccess()); - - final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGES_URL); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); - - assertNotNull(responseEntity.getBody()); - final ProblemDetails problemDetails = responseEntity.getBody(); - assertEquals("An error occurred, a null response was received by the\n" - + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" \n" - + "endpoint.", problemDetails.getDetail()); - } - - @Test - public void testVnfPackageReceivedAsInlineResponse2001IfGetVnfPackageByIdSuccessful() { - final VnfPkgInfo response = createVnfPkgInfo(VNF_PACKAGE_ID); - - mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess(gson.toJson(response), MediaType.APPLICATION_JSON)); - - final String testURL = localhostUrl + port + VNFPKGM_BASE_URL + "/" + VNF_PACKAGE_ID; - final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); - final ResponseEntity<InlineResponse2001> responseEntity = 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() { - mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET)) - .andRespond(withStatus(HttpStatus.BAD_REQUEST)); - - final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL); - - assertEquals(HttpStatus.BAD_REQUEST, responseEntity.getStatusCode()); - assertNotNull(responseEntity.getBody()); - final ProblemDetails problemDetails = responseEntity.getBody(); - assertEquals("Error: Bad Request Received", problemDetails.getDetail()); - } - - @Test - public void test404NotFoundInfoReceivedAsProblemDetailsIfGetVnfPackageByIdIs404NotFound() { - mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET)) - .andRespond(withStatus(HttpStatus.NOT_FOUND)); - - final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL); - - assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); - assertNotNull(responseEntity.getBody()); - final ProblemDetails problemDetails = responseEntity.getBody(); - assertEquals("No Vnf Package found with vnfPkgId: " + VNF_PACKAGE_ID, problemDetails.getDetail()); - } - - @Test - public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackageByIdReturns500InternalServerError() { - mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET)) - .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR)); - - final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL); - - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); - assertNotNull(responseEntity.getBody()); - final ProblemDetails problemDetails = responseEntity.getBody(); - assertEquals("Internal Server Error Occurred.", problemDetails.getDetail()); - } - - @Test - public void test500InternalServerErrorProblemDetailsReceivedIfGetVnfPackageByIdReturnsANullPackage() { - mockRestServer.expect(requestTo(MSB_BASE_URL + "/" + VNF_PACKAGE_ID)).andExpect(method(HttpMethod.GET)) - .andRespond(withSuccess()); - - final ResponseEntity<ProblemDetails> responseEntity = sendHttpRequest(GET_VNF_PACKAGE_BY_ID_URL); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); - - assertNotNull(responseEntity.getBody()); - final ProblemDetails problemDetails = responseEntity.getBody(); - assertEquals("An error occurred, a null response was received by the\n" - + " Sol003PackageManagementController from the EtsiCatalogManager using the GET \"vnf_packages\" by vnfPkgId: \"" - + VNF_PACKAGE_ID + "\" \n" + "endpoint.", problemDetails.getDetail()); - } - - // The below 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); - - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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() { - mockRestServer.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/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java deleted file mode 100644 index c269af8e68..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java +++ /dev/null @@ -1,401 +0,0 @@ -/*- - * ============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.vnfmadapter.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.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL; -import static org.onap.so.adapters.vnfmadapter.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.vnfmadapter.Constants; -import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.BasicAuth; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.LinkSelf; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.NsdmSubscription; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmNotificationsFilter; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscription; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.SubscriptionAuthentication; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.Version; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfProducts; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfProductsProviders; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2002; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse201; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthentication; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter1; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilterVnfProductsFromProviders; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsLinks; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.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 = VnfmAdapterApplication.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" + Constants.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(Constants.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(Constants.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 + Constants.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.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest getEtsiCatalogPkgmSubscriptionRequest() { - return new org.onap.so.adapters.vnfmadapter.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/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java deleted file mode 100644 index fca50ea6f2..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java +++ /dev/null @@ -1,563 +0,0 @@ -/*- - * ============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.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.verify; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; -import com.google.gson.Gson; -import java.net.URI; -import java.util.Optional; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.hamcrest.MockitoHamcrest; -import org.onap.aai.domain.yang.EsrSystemInfo; -import org.onap.aai.domain.yang.EsrSystemInfoList; -import org.onap.aai.domain.yang.EsrVnfm; -import org.onap.aai.domain.yang.EsrVnfmList; -import org.onap.aai.domain.yang.GenericVnf; -import org.onap.aai.domain.yang.Relationship; -import org.onap.aai.domain.yang.RelationshipData; -import org.onap.aai.domain.yang.RelationshipList; -import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication; -import org.onap.so.adapters.vnfmadapter.extclients.SdcPackageProvider; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.JSON; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse2001; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201.InstantiationStateEnum; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201Links; -import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201LinksSelf; -import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException; -import org.onap.so.client.aai.AAIResourcesClient; -import org.onap.so.client.aai.AAIVersion; -import org.onap.so.client.aai.entities.uri.AAIResourceUri; -import org.onap.vnfmadapter.v1.model.CreateVnfRequest; -import org.onap.vnfmadapter.v1.model.CreateVnfResponse; -import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; -import org.onap.vnfmadapter.v1.model.OperationEnum; -import org.onap.vnfmadapter.v1.model.OperationStateEnum; -import org.onap.vnfmadapter.v1.model.QueryJobResponse; -import org.onap.vnfmadapter.v1.model.Tenant; -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.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; -import org.springframework.http.RequestEntity; -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 org.threeten.bp.LocalDateTime; -import org.threeten.bp.OffsetDateTime; -import org.threeten.bp.ZoneOffset; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("test") - -public class VnfmAdapterControllerTest { - - private static final OffsetDateTime JAN_1_2019_12_00 = - OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 12, 0), ZoneOffset.UTC); - private static final OffsetDateTime JAN_1_2019_1_00 = - OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 1, 0), ZoneOffset.UTC); - private static final String CLOUD_OWNER = "myTestCloudOwner"; - private static final String REGION = "myTestRegion"; - private static final String TENANT_ID = "myTestTenantId"; - - @LocalServerPort - private int port; - @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) - private RestTemplate testRestTemplate; - private MockRestServiceServer mockRestServer; - - @MockBean - AAIResourcesClient aaiResourcesClient; - - @MockBean - SdcPackageProvider sdcPackageProvider; - - @Autowired - VnfmAdapterController controller; - Gson gson = new JSON().getGson(); - - @Before - public void setUp() throws Exception { - mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build(); - } - - @Test - public void createVnf_ValidRequest_Returns202AndJobId() throws Exception { - final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID); - final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant); - - setUpGenericVnfInMockAai("vnfmType2"); - setUpVnfmsInMockAai(); - setUpVimInMockAai(); - - final String expectedsubscriptionRequest = - "{\"filter\":{\"vnfInstanceSubscriptionFilter\":{\"vnfInstanceIds\":[\"vnfId\"]},\"notificationTypes\":[\"VnfLcmOperationOccurrenceNotification\"]},\"callbackUri\":\"https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/lcn/VnfLcmOperationOccurrenceNotification\",\"authentication\":{\"authType\":[\"OAUTH2_CLIENT_CREDENTIALS\", \"BASIC\", \"TLS_CERT\"],\"paramsOauth2ClientCredentials\":{\"clientId\":\"vnfm\",\"clientPassword\":\"password1$\",\"tokenEndpoint\":\"https://so-vnfm-adapter.onap:30406/oauth/token\"},\"paramsBasic\":{\"userName\":\"vnfm\",\"password\":\"password1$\"}}}"; - final InlineResponse2001 subscriptionResponse = new InlineResponse2001(); - - final InlineResponse201 createResponse = createCreateResponse(); - mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances")) - .andRespond(withSuccess(gson.toJson(createResponse), MediaType.APPLICATION_JSON)); - - mockRestServer.expect(requestTo("http://vnfm2:8080/subscriptions")) - .andExpect(content().json(expectedsubscriptionRequest)) - .andRespond(withSuccess(gson.toJson(subscriptionResponse), MediaType.APPLICATION_JSON)); - - mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances/vnfId/instantiate")) - .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON) - .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/123456"))); - - final InlineResponse200 firstOperationQueryResponse = createOperationQueryResponse( - org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.INSTANTIATE, - org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.PROCESSING); - mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_lcm_op_occs/123456")) - .andRespond(withSuccess(gson.toJson(firstOperationQueryResponse), MediaType.APPLICATION_JSON)); - - final InlineResponse200 secondOperationQueryReponse = createOperationQueryResponse( - org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.INSTANTIATE, - org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.COMPLETED); - mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_lcm_op_occs/123456")) - .andRespond(withSuccess(gson.toJson(secondOperationQueryReponse), MediaType.APPLICATION_JSON)); - - // Invoke the create request - - final ResponseEntity<CreateVnfResponse> createVnfResponse = - controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213"); - assertEquals(HttpStatus.ACCEPTED, createVnfResponse.getStatusCode()); - assertNotNull(createVnfResponse.getBody().getJobId()); - - final ArgumentCaptor<GenericVnf> genericVnfArgument = ArgumentCaptor.forClass(GenericVnf.class); - final ArgumentCaptor<AAIResourceUri> uriArgument = ArgumentCaptor.forClass(AAIResourceUri.class); - - verify(aaiResourcesClient).update(uriArgument.capture(), genericVnfArgument.capture()); - - assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", uriArgument.getValue().build().toString()); - - assertEquals("myTestVnfId", genericVnfArgument.getValue().getVnfId()); - - final ArgumentCaptor<AAIResourceUri> uriArgument1Connect = ArgumentCaptor.forClass(AAIResourceUri.class); - final ArgumentCaptor<AAIResourceUri> uriArgument2Connect = ArgumentCaptor.forClass(AAIResourceUri.class); - verify(aaiResourcesClient, timeout(1000)).connect(uriArgument1Connect.capture(), uriArgument2Connect.capture()); - assertEquals("/external-system/esr-vnfm-list/esr-vnfm/vnfm2", - uriArgument1Connect.getAllValues().get(0).build().toString()); - assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", - uriArgument2Connect.getAllValues().get(0).build().toString()); - - // check the job status - - final ResponseEntity<QueryJobResponse> firstJobQueryResponse = - controller.jobQuery(createVnfResponse.getBody().getJobId(), "", "so", "1213"); - assertEquals(OperationEnum.INSTANTIATE, firstJobQueryResponse.getBody().getOperation()); - assertEquals(OperationStateEnum.PROCESSING, firstJobQueryResponse.getBody().getOperationState()); - assertEquals(JAN_1_2019_12_00, firstJobQueryResponse.getBody().getStartTime()); - assertEquals(JAN_1_2019_1_00, firstJobQueryResponse.getBody().getStateEnteredTime()); - - final ResponseEntity<QueryJobResponse> secondJobQueryResponse = - controller.jobQuery(createVnfResponse.getBody().getJobId(), "", "so", "1213"); - assertEquals(OperationEnum.INSTANTIATE, secondJobQueryResponse.getBody().getOperation()); - assertEquals(OperationStateEnum.COMPLETED, secondJobQueryResponse.getBody().getOperationState()); - assertEquals(JAN_1_2019_12_00, secondJobQueryResponse.getBody().getStartTime()); - assertEquals(JAN_1_2019_1_00, secondJobQueryResponse.getBody().getStateEnteredTime()); - } - - @Test(expected = IllegalArgumentException.class) - public void createVnf_VnfAlreadyExistsOnVnfm_ThrowsIllegalArgumentException() throws Exception { - final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID); - final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant); - - final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1"); - addSelfLinkToGenericVnf(genericVnf); - addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1"); - setUpVnfmsInMockAai(); - - final InlineResponse201 reponse = new InlineResponse201(); - mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"))) - .andRespond(withSuccess(gson.toJson(reponse), MediaType.APPLICATION_JSON)); - - controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213"); - } - - @Test(expected = VnfmNotFoundException.class) - public void createVnf_NoMatchingVnfmFound_ThrowsException() throws Exception { - final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID); - final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant); - - setUpGenericVnfInMockAai("anotherType"); - setUpVnfmsInMockAai(); - - controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213"); - } - - @Test - public void createVnf_VnfmAlreadyAssociatedWithVnf_Returns202AndJobId() throws Exception { - final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID); - final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant); - - final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType2"); - addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm2"); - setUpVnfmsInMockAai(); - setUpVimInMockAai(); - - final InlineResponse201 createResponse = createCreateResponse(); - mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances")) - .andRespond(withSuccess(gson.toJson(createResponse), MediaType.APPLICATION_JSON)); - - mockRestServer.expect(requestTo("http://vnfm2:8080/subscriptions")).andRespond(withBadRequest()); - - mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_instances/vnfId/instantiate")) - .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON) - .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/123456"))); - - final ResponseEntity<CreateVnfResponse> response = - controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213"); - assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); - assertNotNull(response.getBody().getJobId()); - } - - @Test - @Ignore - public void createVnf_UnauthorizedUser_Returns401() throws Exception { - final TestRestTemplate restTemplateWrongPassword = new TestRestTemplate("test", "wrongPassword"); - final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID); - final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant); - - final RequestEntity<CreateVnfRequest> request = - RequestEntity.post(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId")) - .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON) - .header("X-ONAP-RequestId", "myRequestId").header("X-ONAP-InvocationID", "myInvocationId") - .body(createVnfRequest); - final ResponseEntity<CreateVnfResponse> response = - restTemplateWrongPassword.exchange(request, CreateVnfResponse.class); - assertEquals(401, response.getStatusCode().value()); - } - - @Test - public void deleteVnf_ValidRequest_Returns202AndJobId() throws Exception { - final TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); - - final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1"); - addSelfLinkToGenericVnf(genericVnf); - addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1"); - setUpVnfmsInMockAai(); - - mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate")) - .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON) - .location(new URI("http://vnfm1:8080/vnf_lcm_op_occs/1234567"))); - - final InlineResponse200 firstOperationQueryResponse = createOperationQueryResponse( - org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.TERMINATE, - org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.PROCESSING); - mockRestServer.expect(requestTo("http://vnfm1:8080/vnf_lcm_op_occs/1234567")) - .andRespond(withSuccess(gson.toJson(firstOperationQueryResponse), MediaType.APPLICATION_JSON)); - - final InlineResponse200 secondOperationQueryReponse = createOperationQueryResponse( - org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.TERMINATE, - org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.COMPLETED); - mockRestServer.expect(requestTo("http://vnfm1:8080/vnf_lcm_op_occs/1234567")) - .andRespond(withSuccess(gson.toJson(secondOperationQueryReponse), MediaType.APPLICATION_JSON)); - - final RequestEntity<Void> request = RequestEntity - .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId")) - .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId") - .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build(); - final ResponseEntity<DeleteVnfResponse> deleteVnfResponse = - restTemplate.exchange(request, DeleteVnfResponse.class); - assertEquals(202, deleteVnfResponse.getStatusCode().value()); - assertNotNull(deleteVnfResponse.getBody().getJobId()); - - final ResponseEntity<QueryJobResponse> firstJobQueryResponse = - controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213"); - assertEquals(OperationEnum.TERMINATE, firstJobQueryResponse.getBody().getOperation()); - assertEquals(OperationStateEnum.PROCESSING, firstJobQueryResponse.getBody().getOperationState()); - assertEquals(JAN_1_2019_12_00, firstJobQueryResponse.getBody().getStartTime()); - assertEquals(JAN_1_2019_1_00, firstJobQueryResponse.getBody().getStateEnteredTime()); - - final ResponseEntity<QueryJobResponse> secondJobQueryResponse = - controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213"); - assertEquals(OperationEnum.TERMINATE, secondJobQueryResponse.getBody().getOperation()); - assertEquals(OperationStateEnum.PROCESSING, secondJobQueryResponse.getBody().getOperationState()); - assertEquals(JAN_1_2019_12_00, secondJobQueryResponse.getBody().getStartTime()); - assertEquals(JAN_1_2019_1_00, secondJobQueryResponse.getBody().getStateEnteredTime()); - } - - @Test - public void deleteVnf_VnfAlreadyTerminated_Returns202AndJobId() throws Exception { - final TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); - - final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1"); - addSelfLinkToGenericVnf(genericVnf); - addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1"); - setUpVnfmsInMockAai(); - - mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate")) - .andRespond(withStatus(HttpStatus.CONFLICT).contentType(MediaType.APPLICATION_JSON)); - - final InlineResponse201 reponse = new InlineResponse201(); - reponse.setInstantiationState(InstantiationStateEnum.NOT_INSTANTIATED); - mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"))) - .andRespond(withSuccess(gson.toJson(reponse), MediaType.APPLICATION_JSON)); - - mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")) - .andRespond(withStatus(HttpStatus.NO_CONTENT).contentType(MediaType.APPLICATION_JSON)); - - final RequestEntity<Void> request = RequestEntity - .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId")) - .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId") - .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build(); - final ResponseEntity<DeleteVnfResponse> deleteVnfResponse = - restTemplate.exchange(request, DeleteVnfResponse.class); - assertEquals(202, deleteVnfResponse.getStatusCode().value()); - assertNotNull(deleteVnfResponse.getBody().getJobId()); - - final ResponseEntity<QueryJobResponse> jobQueryResponse = - controller.jobQuery(deleteVnfResponse.getBody().getJobId(), "", "so", "1213"); - assertEquals(OperationStateEnum.COMPLETED, jobQueryResponse.getBody().getOperationState()); - } - - @Test - public void deleteVnf_GenericVnfNotFound_Returns404() throws Exception { - final TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); - - final RequestEntity<Void> request = RequestEntity - .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myNonExistingVnfId")) - .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId") - .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build(); - final ResponseEntity<DeleteVnfResponse> deleteVnfResponse = - restTemplate.exchange(request, DeleteVnfResponse.class); - assertEquals(404, deleteVnfResponse.getStatusCode().value()); - assertNull(deleteVnfResponse.getBody().getJobId()); - } - - @Test - public void deleteVnf_NoAssignedVnfm_Returns400() throws Exception { - final TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); - - setUpGenericVnfInMockAai("vnfmType"); - - final RequestEntity<Void> request = RequestEntity - .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId")) - .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId") - .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build(); - final ResponseEntity<DeleteVnfResponse> deleteVnfResponse = - restTemplate.exchange(request, DeleteVnfResponse.class); - assertEquals(400, deleteVnfResponse.getStatusCode().value()); - assertNull(deleteVnfResponse.getBody().getJobId()); - } - - @Test - public void deleteVnf_ErrorStatusCodeFromVnfm_Returns500() throws Exception { - final TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); - - final GenericVnf genericVnf = setUpGenericVnfInMockAai("vnfmType1"); - addSelfLinkToGenericVnf(genericVnf); - addRelationshipFromGenericVnfToVnfm(genericVnf, "vnfm1"); - setUpVnfmsInMockAai(); - - mockRestServer.expect(requestTo("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm/terminate")) - .andRespond(withStatus(HttpStatus.BAD_REQUEST).contentType(MediaType.APPLICATION_JSON)); - - final RequestEntity<Void> request = RequestEntity - .delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myTestVnfId")) - .accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId") - .header("X-ONAP-InvocationID", "myInvocationId").header("Content-Type", "application/json").build(); - final ResponseEntity<DeleteVnfResponse> deleteVnfResponse = - restTemplate.exchange(request, DeleteVnfResponse.class); - assertEquals(500, deleteVnfResponse.getStatusCode().value()); - assertNull(deleteVnfResponse.getBody().getJobId()); - - } - - private InlineResponse200 createOperationQueryResponse( - final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum operation, - final org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum operationState) { - final InlineResponse200 response = new InlineResponse200(); - response.setId("9876"); - response.setOperation(operation); - response.setOperationState(operationState); - response.setStartTime(JAN_1_2019_12_00); - response.setStateEnteredTime(JAN_1_2019_1_00); - response.setVnfInstanceId("myVnfInstanceId"); - return response; - } - - private GenericVnf createGenericVnf(final String type) { - final GenericVnf genericVnf = new GenericVnf(); - genericVnf.setVnfId("myTestVnfId"); - genericVnf.setNfType(type); - return genericVnf; - } - - private GenericVnf setUpGenericVnfInMockAai(final String type) { - final GenericVnf genericVnf = createGenericVnf(type); - - doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId"))); - return genericVnf; - } - - private void addSelfLinkToGenericVnf(final GenericVnf vnf) { - vnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm"); - } - - private void addRelationshipFromGenericVnfToVnfm(final GenericVnf genericVnf, final String vnfmId) { - final Relationship relationshipToVnfm = new Relationship(); - relationshipToVnfm - .setRelatedLink("/aai/" + AAIVersion.LATEST + "/external-system/esr-vnfm-list/esr-vnfm/" + vnfmId); - relationshipToVnfm.setRelatedTo("esr-vnfm"); - final RelationshipData relationshipData = new RelationshipData(); - relationshipData.setRelationshipKey("esr-vnfm.vnfm-id"); - relationshipData.setRelationshipValue(vnfmId); - relationshipToVnfm.getRelationshipData().add(relationshipData); - - final RelationshipList relationshipList = new RelationshipList(); - relationshipList.getRelationship().add(relationshipToVnfm); - genericVnf.setRelationshipList(relationshipList); - } - - private void setUpVnfmsInMockAai() { - final EsrSystemInfo esrSystemInfo1 = new EsrSystemInfo(); - esrSystemInfo1.setServiceUrl("http://vnfm1:8080"); - esrSystemInfo1.setType("vnfmType1"); - esrSystemInfo1.setSystemType("VNFM"); - final EsrSystemInfoList esrSystemInfoList1 = new EsrSystemInfoList(); - esrSystemInfoList1.getEsrSystemInfo().add(esrSystemInfo1); - - final EsrVnfm esrVnfm1 = new EsrVnfm(); - esrVnfm1.setVnfmId("vnfm1"); - esrVnfm1.setEsrSystemInfoList(esrSystemInfoList1); - esrVnfm1.setResourceVersion("1234"); - - final EsrSystemInfo esrSystemInfo2 = new EsrSystemInfo(); - esrSystemInfo2.setServiceUrl("http://vnfm2:8080"); - esrSystemInfo2.setType("vnfmType2"); - esrSystemInfo2.setSystemType("VNFM"); - final EsrSystemInfoList esrSystemInfoList2 = new EsrSystemInfoList(); - esrSystemInfoList2.getEsrSystemInfo().add(esrSystemInfo2); - - final EsrVnfm esrVnfm2 = new EsrVnfm(); - esrVnfm2.setVnfmId("vnfm2"); - esrVnfm2.setEsrSystemInfoList(esrSystemInfoList2); - esrVnfm2.setResourceVersion("1234"); - - final EsrVnfmList esrVnfmList = new EsrVnfmList(); - esrVnfmList.getEsrVnfm().add(esrVnfm1); - esrVnfmList.getEsrVnfm().add(esrVnfm2); - - doReturn(Optional.of(esrVnfm1)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest - .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1?depth=1"))); - - doReturn(Optional.of(esrVnfm2)).when(aaiResourcesClient).get(eq(EsrVnfm.class), MockitoHamcrest - .argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm2?depth=1"))); - - doReturn(Optional.of(esrVnfmList)).when(aaiResourcesClient).get(eq(EsrVnfmList.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list"))); - - doReturn(Optional.of(esrSystemInfoList1)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher( - "/external-system/esr-vnfm-list/esr-vnfm/vnfm1/esr-system-info-list"))); - doReturn(Optional.of(esrSystemInfoList2)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher( - "/external-system/esr-vnfm-list/esr-vnfm/vnfm2/esr-system-info-list"))); - } - - private void setUpVimInMockAai() { - final EsrSystemInfo esrSystemInfo = new EsrSystemInfo(); - esrSystemInfo.setServiceUrl("http://myVim:8080"); - esrSystemInfo.setType("openstack"); - esrSystemInfo.setSystemType("VIM"); - esrSystemInfo.setCloudDomain("myDomain"); - esrSystemInfo.setUserName("myUser"); - esrSystemInfo.setPassword("myPassword"); - - final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList(); - esrSystemInfoList.getEsrSystemInfo().add(esrSystemInfo); - - doReturn(Optional.of(esrSystemInfoList)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class), - MockitoHamcrest.argThat(new AaiResourceUriMatcher("/cloud-infrastructure/cloud-regions/cloud-region/" - + CLOUD_OWNER + "/" + REGION + "/esr-system-info-list"))); - } - - private InlineResponse201 createCreateResponse() { - final InlineResponse201 createResponse = new InlineResponse201(); - createResponse.setVnfdId("myTestVnfd"); - final InlineResponse201Links links = new InlineResponse201Links(); - final InlineResponse201LinksSelf self = new InlineResponse201LinksSelf(); - self.setHref("http://vnfm2:8080/vnf_instances/vnfId"); - links.setSelf(self); - createResponse.setLinks(links); - createResponse.setId("vnfId"); - return createResponse; - } - - - private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> { - - final String uriAsString; - - public AaiResourceUriMatcher(final String uriAsString) { - this.uriAsString = uriAsString; - } - - @Override - public boolean matches(final Object item) { - if (item instanceof AAIResourceUri) { - if (uriAsString.endsWith("...")) { - return ((AAIResourceUri) item).build().toString() - .startsWith(uriAsString.substring(0, uriAsString.indexOf("..."))); - } - return ((AAIResourceUri) item).build().toString().equals(uriAsString); - } - return false; - } - - @Override - public void describeTo(final Description description) {} - - } - -} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application.yaml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application.yaml deleted file mode 100644 index cdb6662191..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application.yaml +++ /dev/null @@ -1,61 +0,0 @@ -# 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/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/requests/SubscriptionRequest.json b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/requests/SubscriptionRequest.json deleted file mode 100644 index c38466f8e5..0000000000 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/requests/SubscriptionRequest.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "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" - } - } -} |