aboutsummaryrefslogtreecommitdiffstats
path: root/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm
diff options
context:
space:
mode:
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm')
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSubscriptionNotificationController.java194
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/utils/TestUtils.java87
2 files changed, 281 insertions, 0 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSubscriptionNotificationController.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSubscriptionNotificationController.java
new file mode 100644
index 00000000..743e2c04
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/controllers/TestSubscriptionNotificationController.java
@@ -0,0 +1,194 @@
+/*-
+ * ============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.svnfm.simulator.controllers;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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.SubscriptionsFilter1;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.VnfPackageOnboardingNotification;
+import org.onap.so.svnfm.simulator.config.SvnfmApplication;
+import org.slf4j.Logger;
+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.HttpHeaders;
+import org.springframework.http.HttpMethod;
+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;
+import java.time.LocalDateTime;
+
+import static org.junit.Assert.assertEquals;
+import static org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter.NotificationTypesEnum.VNFPACKAGECHANGENOTIFICATION;
+import static org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter.NotificationTypesEnum.VNFPACKAGEONBOARDINGNOTIFICATION;
+import static org.onap.so.svnfm.simulator.config.SslBasedRestTemplateConfiguration.SSL_BASED_CONFIGURABLE_REST_TEMPLATE;
+import static org.onap.so.svnfm.simulator.constants.Constant.NOTIFICATION_ENDPOINT;
+import static org.onap.so.svnfm.simulator.constants.Constant.PACKAGE_MANAGEMENT_BASE_URL;
+import static org.onap.so.svnfm.simulator.constants.Constant.SUBSCRIPTION_ENDPOINT;
+import static org.onap.so.svnfm.simulator.constants.Constant.VNFM_ADAPTER_SUBSCRIPTION_ENDPOINT;
+import static org.onap.so.svnfm.simulator.utils.TestUtils.getBaseUrl;
+import static org.onap.so.svnfm.simulator.utils.TestUtils.getBasicAuth;
+import static org.onap.so.svnfm.simulator.utils.TestUtils.getHttpHeaders;
+import static org.onap.so.svnfm.simulator.utils.TestUtils.getNotification;
+import static org.onap.so.svnfm.simulator.utils.TestUtils.getSubscriptionRequest;
+import static org.slf4j.LoggerFactory.getLogger;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.content;
+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.withSuccess;
+
+/**
+ * @author Andrew Lamb (andrew.a.lamb@est.tech)
+ */
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = SvnfmApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+public class TestSubscriptionNotificationController {
+
+ private static final Logger LOGGER = getLogger(TestSubscriptionNotificationController.class);
+
+ @LocalServerPort
+ private int port;
+
+ @Autowired @Qualifier(SSL_BASED_CONFIGURABLE_REST_TEMPLATE)
+ private RestTemplate restTemplate;
+ private MockRestServiceServer mockRestServiceServer;
+
+ @Autowired
+ private TestRestTemplate testRestTemplate;
+
+ private Gson gson;
+ private String vnfmSimulatorCallbackUrl;
+
+ @Before
+ public void setup() {
+ mockRestServiceServer = MockRestServiceServer.bindTo(restTemplate).build();
+ gson = new GsonBuilder().create();
+ vnfmSimulatorCallbackUrl = getBaseUrl(port) + PACKAGE_MANAGEMENT_BASE_URL + NOTIFICATION_ENDPOINT;
+ }
+
+ @After
+ public void teardown() {
+ mockRestServiceServer.reset();
+ }
+
+ @Test
+ public void testGetFromEndpoint_Success() {
+ final ResponseEntity<?> responseEntity = checkGetFromTestEndpoint();
+ assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
+ }
+
+ @Test
+ public void testPostOnboardingSubscriptionRequest_Success() throws Exception {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest =
+ gson.fromJson(getSubscriptionRequest(VNFPACKAGEONBOARDINGNOTIFICATION), PkgmSubscriptionRequest.class);
+ pkgmSubscriptionRequest.setCallbackUri(vnfmSimulatorCallbackUrl);
+ final InlineResponse201 inlineResponse =
+ new InlineResponse201().id("subscriptionId").filter(new SubscriptionsFilter1())
+ .callbackUri("callbackUri");
+
+ mockRestServiceServer.expect(requestTo(VNFM_ADAPTER_SUBSCRIPTION_ENDPOINT)).andExpect(method(HttpMethod.POST))
+ .andExpect(content().json(gson.toJson(pkgmSubscriptionRequest)))
+ .andRespond(withSuccess(gson.toJson(inlineResponse), APPLICATION_JSON));
+
+ final ResponseEntity<?> responseEntity = postSubscriptionRequest(pkgmSubscriptionRequest);
+ final InlineResponse201 responseEntityBody = (InlineResponse201) responseEntity.getBody();
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+ assertEquals(inlineResponse, responseEntityBody);
+ }
+
+ @Test
+ public void testPostChangeSubscriptionRequest_Success() throws Exception {
+ final PkgmSubscriptionRequest pkgmSubscriptionRequest =
+ gson.fromJson(getSubscriptionRequest(VNFPACKAGECHANGENOTIFICATION), PkgmSubscriptionRequest.class);
+ pkgmSubscriptionRequest.setCallbackUri(vnfmSimulatorCallbackUrl);
+ final InlineResponse201 inlineResponse =
+ new InlineResponse201().id("subscriptionId").filter(new SubscriptionsFilter1())
+ .callbackUri("callbackUri");
+
+ mockRestServiceServer.expect(requestTo(VNFM_ADAPTER_SUBSCRIPTION_ENDPOINT)).andExpect(method(HttpMethod.POST))
+ .andExpect(content().json(gson.toJson(pkgmSubscriptionRequest)))
+ .andRespond(withSuccess(gson.toJson(inlineResponse), APPLICATION_JSON));
+
+ final ResponseEntity<?> responseEntity = postSubscriptionRequest(pkgmSubscriptionRequest);
+ final InlineResponse201 responseEntityBody = (InlineResponse201) responseEntity.getBody();
+ assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
+ assertEquals(inlineResponse, responseEntityBody);
+ }
+
+ @Test
+ public void testNotificationEndpoint_Success() throws Exception {
+ final VnfPackageOnboardingNotification vnfPackageOnboardingNotification =
+ gson.fromJson(getNotification(VNFPACKAGEONBOARDINGNOTIFICATION),
+ VnfPackageOnboardingNotification.class);
+ final LocalDateTime timestamp = LocalDateTime.of(2020, 1, 1, 1, 1, 1, 1);
+ vnfPackageOnboardingNotification.setTimeStamp(timestamp);
+ final ResponseEntity<?> responseEntity = postNotification(vnfPackageOnboardingNotification);
+ assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
+ }
+
+ private ResponseEntity<Void> checkGetFromTestEndpoint() {
+ LOGGER.info("checkGetFromTestEndpoint() method...");
+ final String vnfmSimulatorTestEndpoint = getBaseUrl(port) + PACKAGE_MANAGEMENT_BASE_URL;
+ final String authHeader = getBasicAuth("vnfm", "password1$");
+ final HttpHeaders headers = getHttpHeaders(authHeader);
+ final HttpEntity<?> request = new HttpEntity<>(headers);
+
+ LOGGER.info("sending request {} to: {}", request, vnfmSimulatorTestEndpoint);
+ return testRestTemplate.exchange(vnfmSimulatorTestEndpoint, HttpMethod.GET, request, Void.class);
+ }
+
+ private ResponseEntity<?> postSubscriptionRequest(final PkgmSubscriptionRequest subscriptionRequest) {
+ LOGGER.info("postSubscriptionRequest() method...");
+ final String vnfmSimulatorSubscribeEndpoint =
+ getBaseUrl(port) + PACKAGE_MANAGEMENT_BASE_URL + SUBSCRIPTION_ENDPOINT;
+ final String authHeader = getBasicAuth("vnfm", "password1$");
+ final HttpHeaders headers = getHttpHeaders(authHeader);
+ final HttpEntity<?> request = new HttpEntity<>(subscriptionRequest, headers);
+
+ LOGGER.info("sending request {} to: {}", request, vnfmSimulatorSubscribeEndpoint);
+ return testRestTemplate
+ .exchange(vnfmSimulatorSubscribeEndpoint, HttpMethod.POST, request, InlineResponse201.class);
+ }
+
+ private ResponseEntity<?> postNotification(final Object notification) {
+ LOGGER.info("postNotification method...");
+ final String authHeader = getBasicAuth("vnfm", "password1$");
+ final HttpHeaders headers = getHttpHeaders(authHeader);
+ final HttpEntity<?> request = new HttpEntity<>(notification, headers);
+
+ LOGGER.info("sending request {} to: {}", request, vnfmSimulatorCallbackUrl);
+ return testRestTemplate.exchange(vnfmSimulatorCallbackUrl, HttpMethod.POST, request, Void.class);
+ }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/utils/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/utils/TestUtils.java
new file mode 100644
index 00000000..e03f945c
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/vnfm-simulator/vnfm-service/src/test/java/org/onap/so/svnfm/simulator/utils/TestUtils.java
@@ -0,0 +1,87 @@
+/*-
+ * ============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.svnfm.simulator.utils;
+
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsFilter;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.http.HttpHeaders;
+import javax.ws.rs.core.MediaType;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import org.apache.commons.codec.binary.Base64;
+
+/**
+ * @author Andrew Lamb (andrew.a.lamb@est.tech)
+ *
+ */
+public class TestUtils {
+
+ public static String getBasicAuth(final String username, final String password) {
+ final String auth = username + ":" + password;
+ return "Basic " + new String(Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)));
+ }
+
+ public static HttpHeaders getHttpHeaders(final String authHeader) {
+ final HttpHeaders headers = new HttpHeaders();
+ headers.add(HttpHeaders.AUTHORIZATION, authHeader);
+ headers.add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
+ headers.add(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON);
+ return headers;
+ }
+
+ public static File getFile(final String file) throws IOException {
+ return new ClassPathResource(file).getFile();
+ }
+
+ public static String getJsonString(final String file) throws IOException {
+ return new String(Files.readAllBytes(getFile(file).toPath()));
+ }
+
+ public static String getBaseUrl(final int port) {
+ return "http://localhost:" + port;
+ }
+
+ public static String getSubscriptionRequest(final SubscriptionsFilter.NotificationTypesEnum notificationType) throws Exception {
+ switch (notificationType) {
+ case VNFPACKAGECHANGENOTIFICATION:
+ return getJsonString("test-data/pkg-subscription-request-change.json");
+ case VNFPACKAGEONBOARDINGNOTIFICATION:
+ return getJsonString("test-data/pkg-subscription-request-onboarding.json");
+ default:
+ return null;
+ }
+ }
+
+ public static String getNotification(final SubscriptionsFilter.NotificationTypesEnum notificationType) throws Exception {
+ switch (notificationType) {
+ case VNFPACKAGECHANGENOTIFICATION:
+ return getJsonString("test-data/vnf-package-change-notification.json");
+ case VNFPACKAGEONBOARDINGNOTIFICATION:
+ return getJsonString("test-data/vnf-package-onboarding-notification.json");
+ default:
+ return null;
+ }
+ }
+
+ private TestUtils() {}
+
+}