diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test')
7 files changed, 292 insertions, 0 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/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 +} |