summaryrefslogtreecommitdiffstats
path: root/mso-api-handlers/mso-api-handler-infra/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test')
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java181
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java3
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java31
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/activateRequest.json9
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/allocateRequest.json55
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deActivateRequest.json9
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deAllocate.json13
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/modifyRequest.json18
-rw-r--r--mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/BPMN_response.json7
9 files changed, 323 insertions, 3 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java
new file mode 100644
index 0000000000..503af1bdcb
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java
@@ -0,0 +1,181 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2020 Wipro Limited.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.apihandlerinfra;
+
+import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
+import static org.junit.Assert.assertEquals;
+import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_PARTNER_NAME;
+import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID;
+import static org.onap.logging.filter.base.Constants.HttpHeaders.TRANSACTION_ID;
+import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.http.HttpStatus;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.db.catalog.beans.Service;
+import org.onap.so.db.catalog.beans.ServiceRecipe;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.util.UriComponentsBuilder;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class Onap3gppServiceInstancesTest extends BaseTest {
+
+ private String onap3gppServicesUri = "/onap/so/infra/onap3gppServiceInstances/";
+
+ private final ObjectMapper mapper = new ObjectMapper();
+
+ @Before
+ public void init() throws JsonProcessingException {
+
+ Service defaultService = new Service();
+ defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a");
+ ServiceRecipe serviceRecipe = new ServiceRecipe();
+ serviceRecipe.setServiceModelUUID(defaultService.getModelUUID());
+ serviceRecipe.setRecipeTimeout(180);
+ serviceRecipe.setOrchestrationUri("/mso/async/services/commonNssmfTest");
+
+ wireMockServer.stubFor(get(urlPathEqualTo("/service/search/findFirstByModelNameOrderByModelVersionDesc"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK)));
+
+ wireMockServer.stubFor(get(urlPathEqualTo("/serviceRecipe/search/findFirstByServiceModelUUIDAndAction"))
+ .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
+ .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK)));
+ wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/")).willReturn(aResponse()
+ .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK)));
+ Mockito.doReturn(null).when(requestsDbClient).getInfraActiveRequestbyRequestId(Mockito.any());
+ }
+
+ public String inputStream(String JsonInput) throws IOException {
+ JsonInput = "src/test/resources/Onap3gppServiceInstancesTest" + JsonInput;
+ return new String(Files.readAllBytes(Paths.get(JsonInput)));
+ }
+
+ public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod) {
+ HttpHeaders headers = new HttpHeaders();
+ headers.set("Accept", MediaType.APPLICATION_JSON);
+ headers.set("Content-Type", MediaType.APPLICATION_JSON);
+ headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "test_name");
+ headers.set(TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
+ headers.set(ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
+ headers.set(ONAPLogConstants.MDCs.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d");
+ headers.set(ONAP_PARTNER_NAME, "VID");
+ headers.set(REQUESTOR_ID, "xxxxxx");
+ UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath));
+ HttpEntity<String> request = new HttpEntity<>(requestJson, headers);
+
+ return restTemplate.exchange(builder.toUriString(), reqMethod, request, String.class);
+ }
+
+ @Test
+ public void createServiceInstanceTest() throws IOException {
+ String uri = onap3gppServicesUri + "v1/allocate";
+ wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn(
+ aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json")
+ .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED)));
+
+ String expectedResponse =
+ "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}";
+ ResponseEntity<String> response = sendRequest(inputStream("/allocateRequest.json"), uri, HttpMethod.POST);
+
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ String actualResponse = response.getBody();
+ assertEquals(expectedResponse, actualResponse);
+ }
+
+ @Test
+ public void updateServiceInstanceTest() throws IOException {
+ String uri = onap3gppServicesUri + "v1/modify";
+ wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn(
+ aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json")
+ .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED)));
+
+ String expectedResponse =
+ "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}";
+ ResponseEntity<String> response = sendRequest(inputStream("/modifyRequest.json"), uri, HttpMethod.PUT);
+
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ String actualResponse = response.getBody();
+ assertEquals(expectedResponse, actualResponse);
+ }
+
+ @Test
+ public void deleteServiceInstanceTest() throws IOException {
+ String uri = onap3gppServicesUri + "v1/deAllocate";
+ wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn(
+ aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json")
+ .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED)));
+ String expectedResponse =
+ "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}";
+ ResponseEntity<String> response = sendRequest(inputStream("/deAllocate.json"), uri, HttpMethod.DELETE);
+
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ String actualResponse = response.getBody();
+ assertEquals(expectedResponse, actualResponse);
+ }
+
+ @Test
+ public void activateServiceInstanceTest() throws IOException {
+ String uri = onap3gppServicesUri + "v1/activate";
+ wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn(
+ aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json")
+ .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED)));
+ String expectedResponse =
+ "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}";
+ ResponseEntity<String> response = sendRequest(inputStream("/activateRequest.json"), uri, HttpMethod.POST);
+
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ String actualResponse = response.getBody();
+ assertEquals(expectedResponse, actualResponse);
+ }
+
+ @Test
+ public void deActivateServiceInstance() throws IOException {
+ String uri = onap3gppServicesUri + "v1/deActivate";
+ wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn(
+ aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json")
+ .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED)));
+ String expectedResponse =
+ "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}";
+ ResponseEntity<String> response = sendRequest(inputStream("/deActivateRequest.json"), uri, HttpMethod.POST);
+
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
+ String actualResponse = response.getBody();
+ assertEquals(expectedResponse, actualResponse);
+ }
+
+}
+
+
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java
index 7711608288..1f944da7ba 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsTest.java
@@ -335,7 +335,6 @@ public class OrchestrationRequestsTest extends BaseTest {
Map<String, List<String>> orchestrationMap = new HashMap<>();
orchestrationMap.put("modelType", values);
- List<GetOrchestrationResponse> testResponses = new ArrayList<>();
List<InfraActiveRequests> requests = requestsDbClient.getOrchestrationFiltersFromInfraActive(orchestrationMap);
HttpHeaders headers = new HttpHeaders();
@@ -427,7 +426,6 @@ public class OrchestrationRequestsTest extends BaseTest {
public void testUnlockOrchestrationRequest_Valid_Status()
throws JsonParseException, JsonMappingException, IOException, ValidationException {
setupTestUnlockOrchestrationRequest_Valid_Status("5ffbabd6-b793-4377-a1ab-082670fbc7ac", "PENDING");
- ObjectMapper mapper = new ObjectMapper();
String requestJSON =
new String(Files.readAllBytes(Paths.get("src/test/resources/OrchestrationRequest/Request.json")));
HttpHeaders headers = new HttpHeaders();
@@ -481,7 +479,6 @@ public class OrchestrationRequestsTest extends BaseTest {
assertThat(actualProcessingData, sameBeanAs(expectedDataList));
}
-
public void setupTestGetOrchestrationRequest() throws Exception {
// For testGetOrchestrationRequest
wireMockServer.stubFor(any(urlPathEqualTo("/infraActiveRequests/00032ab7-1a18-42e5-965d-8ea592502018"))
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java
index 7f9ff98b19..2ba646fba0 100644
--- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java
@@ -39,6 +39,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.util.HashMap;
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.apache.http.HttpStatus;
@@ -338,4 +339,34 @@ public class RequestHandlerUtilsTest extends BaseTest {
assertEquals(expectedBasicAuth, basicAuth);
}
+ @Test
+ public void getServiceInstanceIdForValidationErrorTest() {
+ ServiceInstancesRequest sir = new ServiceInstancesRequest();
+ String requestScope = "vnf";
+ HashMap<String, String> instanceIdMap = new HashMap<String, String>();
+ instanceIdMap.put("serviceInstanceId", "testServiceInstanceId");
+ String serviceInstanceId =
+ requestHandlerUtils.getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).get();
+ assertEquals("testServiceInstanceId", serviceInstanceId);
+ }
+
+ @Test
+ public void getServiceInstanceIdForValidationErrorInstanceGroupTest() throws Exception {
+ ServiceInstancesRequest sir =
+ mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class);
+ String requestScope = "instanceGroup";
+ String serviceInstanceId =
+ requestHandlerUtils.getServiceInstanceIdForValidationError(sir, null, requestScope).get();
+ assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", serviceInstanceId);
+ }
+
+ @Test
+ public void getServiceInstanceIdForInstanceGroupTest() throws Exception {
+ ServiceInstancesRequest sir =
+ mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class);
+ String requestScope = "instanceGroup";
+ String serviceInstanceId = requestHandlerUtils.getServiceInstanceIdForInstanceGroup(requestScope, sir).get();
+ assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", serviceInstanceId);
+ }
+
}
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/activateRequest.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/activateRequest.json
new file mode 100644
index 0000000000..e67809c80e
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/activateRequest.json
@@ -0,0 +1,9 @@
+{
+ "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX",
+ "networkType": "an/cn/tn",
+ "globalSubscriberId": "5GCustomer",
+ "subscriptionServiceType": "5G",
+ "additionalProperties": {
+ "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX"
+ }
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/allocateRequest.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/allocateRequest.json
new file mode 100644
index 0000000000..24cea593b9
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/allocateRequest.json
@@ -0,0 +1,55 @@
+{
+ "name": "eMBB-001",
+ "modelInvariantUuid": "NSST-C-001-HDBNJ-NSSMF-01-A-ZX",
+ "modelUuid": "NSST-C-001-HDBNJ-NSSMF-01-A-ZX-UUID",
+ "globalSubscriberId": "5GCustomer",
+ "subscriptionServiceType": "5G",
+ "networkType": "an/cn/tn",
+ "additionalProperties": {
+ "sliceProfile": {
+ "snssaiList": [
+ "001-100001"
+ ],
+ "sliceProfileId": "ab9af40f13f721b5f13539d87484098",
+ "plmnIdList": [
+ "460-00",
+ "460-01"
+ ],
+ "perfReq": {
+ "perfReqEmbbList ": [
+ {
+ "activityFactor": 50
+ }
+ ]
+ },
+ "maxNumberofUEs": 200,
+ "coverageAreaTAList": [
+ "1",
+ "2",
+ "3",
+ "4"
+ ],
+ "latency": 2,
+ "resourceSharingLevel": "non-shared"
+ },
+ "endPoints": [
+ {
+ "nodeId": "",
+ "additionalInfo": {
+ "xxx": "xxx"
+ }
+ },
+ {
+ "nodeId": "",
+ "additionalInfo": {
+ "xxx": "xxx"
+ }
+ }
+ ],
+ "nsiInfo": {
+ "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX",
+ "nsiName": "eMBB-001"
+ },
+ "scriptName": "AN1"
+ }
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deActivateRequest.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deActivateRequest.json
new file mode 100644
index 0000000000..e67809c80e
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deActivateRequest.json
@@ -0,0 +1,9 @@
+{
+ "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX",
+ "networkType": "an/cn/tn",
+ "globalSubscriberId": "5GCustomer",
+ "subscriptionServiceType": "5G",
+ "additionalProperties": {
+ "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX"
+ }
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deAllocate.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deAllocate.json
new file mode 100644
index 0000000000..50729317e3
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deAllocate.json
@@ -0,0 +1,13 @@
+{
+ "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX ",
+ "networkType": "an/cn/tn",
+ "globalSubscriberId": "5GCustomer",
+ "subscriptionServiceType": "5G",
+ "additionalProperties": {
+ "snssaiList": [
+ "001-100001"
+ ],
+ "scriptName": "AN1",
+ "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX"
+ }
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/modifyRequest.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/modifyRequest.json
new file mode 100644
index 0000000000..6a7db0165b
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/modifyRequest.json
@@ -0,0 +1,18 @@
+{
+ "name": "eMBB-001",
+ "globalSubscriberId": "5GCustomer",
+ "subscriptionServiceType": "5G",
+ "networkType": "an/cn/tn",
+ "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX",
+ "additionalProperties": {
+ "modifyAction": "allocate/deallocate",
+ "snssaiList": [
+ "001-100001"
+ ],
+ "nsiInfo": {
+ "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX",
+ "nsiName": "eMBB-001"
+ },
+ "scriptName": "AN1"
+ }
+} \ No newline at end of file
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/BPMN_response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/BPMN_response.json
new file mode 100644
index 0000000000..b2c29ac4c6
--- /dev/null
+++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/BPMN_response.json
@@ -0,0 +1,7 @@
+{
+ "response":"{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}",
+ "message":"Success",
+ "processInstanceID":"8878ccf8-1efc-11e8-b332-0050569a141e",
+ "variables":null,
+ "messageCode":202
+}