diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2019-08-30 08:51:03 +0000 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2019-08-30 08:51:03 +0000 |
commit | 413bbe636e82c268d588c08185422f94ab4f75f3 (patch) | |
tree | 9f39ddf26ce7aa7513e3720c43ed71e27edc44d1 /plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test | |
parent | 5b8c4f931930cde88eceba2059785dec7f6352f0 (diff) |
Adding vnf-topology-operation endpoint
Change-Id: Ic4d0306742a7ad9c4a3ddf2532185b24d80bced9
Issue-ID: SO-2220
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test')
3 files changed, 223 insertions, 32 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java index af46ab40..18d478eb 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java @@ -22,15 +22,16 @@ package org.onap.so.sdncsimulator.controller; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Base64; +import static org.onap.so.sdncsimulator.controller.TestUtils.getInvalidRequestInput; +import static org.onap.so.sdncsimulator.controller.TestUtils.getRequestInput; +import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestInput; +import java.util.Optional; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnf; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService; import org.onap.so.sdncsimulator.models.InputRequest; import org.onap.so.sdncsimulator.models.Output; import org.onap.so.sdncsimulator.models.OutputRequest; @@ -43,12 +44,10 @@ 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.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpEntity; 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.SpringJUnit4ClassRunner; @@ -65,11 +64,15 @@ public class OperationsControllerTest { private static final String SVC_REQUEST_ID = "04fc9f50-87b8-430d-a232-ef24bd6c4150"; + private static final String VNF_SVC_REQUEST_ID = "8fd2622b-01fc-424d-bfc8-f48bcd64e546"; + private static final String SERVICE_INSTANCE_ID = "ccece8fe-13da-456a-baf6-41b3a4a2bc2b"; private static final String SERVICE_TOPOLOGY_OPERATION_URL = "/GENERIC-RESOURCE-API:service-topology-operation/"; - private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; + private static final String VNF_TOPOLOGY_OPERATION_URL = "/GENERIC-RESOURCE-API:vnf-topology-operation/"; + + private static final String VNF_INSTANCE_ID = "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701"; @LocalServerPort private int port; @@ -108,8 +111,16 @@ public class OperationsControllerTest { final GenericResourceApiInstanceReference acutalReference = actualObject.getServiceResponseInformation(); assertEquals(Constants.RESTCONF_CONFIG_END_POINT + SERVICE_INSTANCE_ID, acutalReference.getObjectPath()); assertEquals(SERVICE_INSTANCE_ID, acutalReference.getInstanceId()); - assertTrue( - cacheServiceProvider.getGenericResourceApiServiceModelInfrastructure(SERVICE_INSTANCE_ID).isPresent()); + final Optional<GenericResourceApiServicemodelinfrastructureService> optional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(optional.isPresent()); + + final GenericResourceApiServicemodelinfrastructureService service = optional.get(); + assertNotNull(service.getServiceInstanceId()); + assertEquals(SERVICE_INSTANCE_ID, service.getServiceInstanceId()); + assertNotNull(service.getServiceData()); + assertNotNull(service.getServiceStatus()); + } @Test @@ -143,39 +154,101 @@ public class OperationsControllerTest { } - private HttpHeaders getHttpHeaders() { - return getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); - } + @Test + public void test_postVnfOperationInformation_successfullyAddToExistingServiceInCache() throws Exception { + final HttpEntity<?> httpEntity = new HttpEntity<>(getRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseEntity = + restTemplate.exchange(getUrl(), HttpMethod.POST, httpEntity, OutputRequest.class); - private String getUrl() { - return "http://localhost:" + port + Constants.OPERATIONS_URL + SERVICE_TOPOLOGY_OPERATION_URL; - } + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - private String getRequestInput() throws IOException { - return getFileAsString(getFile("test-data/input.json").toPath()); - } + final HttpEntity<?> httpVnfEntity = new HttpEntity<>(getVnfRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseVnfEntity = + restTemplate.exchange(getVnfUrl(), HttpMethod.POST, httpVnfEntity, OutputRequest.class); + assertEquals(HttpStatus.OK, responseVnfEntity.getStatusCode()); + assertTrue(responseVnfEntity.hasBody()); + + final OutputRequest actualOutputRequest = responseVnfEntity.getBody(); + assertNotNull(actualOutputRequest); + assertNotNull(actualOutputRequest.getOutput()); + + final Output actualObject = actualOutputRequest.getOutput(); + + assertEquals(HttpStatus.OK.toString(), actualObject.getResponseCode()); + assertEquals(Constants.YES, actualObject.getAckFinalIndicator()); + assertEquals(VNF_SVC_REQUEST_ID, actualObject.getSvcRequestId()); + assertNotNull(actualObject.getServiceResponseInformation()); - private String getInvalidRequestInput() throws IOException { - return getFileAsString(getFile("test-data/InvalidInput.json").toPath()); + final GenericResourceApiInstanceReference acutalReference = actualObject.getServiceResponseInformation(); + assertEquals(Constants.RESTCONF_CONFIG_END_POINT + SERVICE_INSTANCE_ID, acutalReference.getObjectPath()); + assertEquals(SERVICE_INSTANCE_ID, acutalReference.getInstanceId()); + final Optional<GenericResourceApiServicemodelinfrastructureService> optional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(optional.isPresent()); + + final GenericResourceApiInstanceReference actualvnfInformation = actualObject.getVnfResponseInformation(); + assertEquals(VNF_INSTANCE_ID, actualvnfInformation.getInstanceId()); + + final Optional<GenericResourceApiServicemodelinfrastructureService> serviceOptional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(serviceOptional.isPresent()); + + final GenericResourceApiServicemodelinfrastructureService service = serviceOptional.get(); + assertNotNull(service.getServiceInstanceId()); + assertNotNull(service.getServiceData().getVnfs().getVnf()); + assertNotNull(service.getServiceData()); + assertNotNull(service.getServiceData().getVnfs()); + assertNotNull(service.getServiceData().getVnfs().getVnf()); + assertEquals(1, service.getServiceData().getVnfs().getVnf().size()); + final GenericResourceApiServicedataServicedataVnfsVnf vnf = service.getServiceData().getVnfs().getVnf().get(0); + assertNotNull(vnf.getVnfId()); + assertEquals(VNF_INSTANCE_ID, vnf.getVnfId()); + assertNotNull(vnf.getVnfData()); } - private String getFileAsString(final Path path) throws IOException { - return new String(Files.readAllBytes(path)); + @Test + public void test_postSameVnfOperationInformationTwice_ShouldReturnbadRequest() throws Exception { + + final HttpEntity<?> httpEntity = new HttpEntity<>(getRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseEntity = + restTemplate.exchange(getUrl(), HttpMethod.POST, httpEntity, OutputRequest.class); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + + final HttpEntity<?> httpVnfEntity = new HttpEntity<>(getVnfRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseVnfEntity = + restTemplate.exchange(getVnfUrl(), HttpMethod.POST, httpVnfEntity, OutputRequest.class); + assertEquals(HttpStatus.OK, responseVnfEntity.getStatusCode()); + assertTrue(responseVnfEntity.hasBody()); + + final OutputRequest actualOutputRequest = responseVnfEntity.getBody(); + assertNotNull(actualOutputRequest); + assertNotNull(actualOutputRequest.getOutput()); + + final ResponseEntity<OutputRequest> badResponse = + restTemplate.exchange(getVnfUrl(), HttpMethod.POST, httpVnfEntity, OutputRequest.class); + + final OutputRequest badOutputRequest = badResponse.getBody(); + assertNotNull(badOutputRequest); + + final Output actualObject = badOutputRequest.getOutput(); + assertNotNull(actualObject); + assertEquals(HttpStatus.BAD_REQUEST.toString(), actualObject.getResponseCode()); + assertEquals(VNF_SVC_REQUEST_ID, actualObject.getSvcRequestId()); + assertEquals(Constants.YES, actualObject.getAckFinalIndicator()); + } - private File getFile(final String file) throws IOException { - return new ClassPathResource(file).getFile(); + private HttpHeaders getHttpHeaders() { + return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); } - private HttpHeaders getHttpHeaders(final String username) { - final HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.add("Authorization", getBasicAuth(username)); - requestHeaders.setContentType(MediaType.APPLICATION_JSON); - return requestHeaders; + private String getUrl() { + return "http://localhost:" + port + Constants.OPERATIONS_URL + SERVICE_TOPOLOGY_OPERATION_URL; } - private String getBasicAuth(final String username) { - return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); + private String getVnfUrl() { + return "http://localhost:" + port + Constants.OPERATIONS_URL + VNF_TOPOLOGY_OPERATION_URL; } @After diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java new file mode 100644 index 00000000..a6814b69 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java @@ -0,0 +1,72 @@ +/*- + * ============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.sdncsimulator.controller; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Base64; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class TestUtils { + private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; + + + private TestUtils() {} + + public static String getRequestInput() throws IOException { + return getFileAsString(getFile("test-data/input.json").toPath()); + } + + public static String getVnfRequestInput() throws IOException { + return getFileAsString(getFile("test-data/vnfInput.json").toPath()); + } + + public static String getInvalidRequestInput() throws IOException { + return getFileAsString(getFile("test-data/InvalidInput.json").toPath()); + } + + public static String getFileAsString(final Path path) throws IOException { + return new String(Files.readAllBytes(path)); + } + + public static File getFile(final String file) throws IOException { + return new ClassPathResource(file).getFile(); + } + + public static HttpHeaders getHttpHeaders(final String username) { + final HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.add("Authorization", getBasicAuth(username)); + requestHeaders.setContentType(MediaType.APPLICATION_JSON); + return requestHeaders; + } + + public static String getBasicAuth(final String username) { + return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/vnfInput.json b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/vnfInput.json new file mode 100644 index 00000000..01a28617 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/vnfInput.json @@ -0,0 +1,46 @@ +{ + "input": { + "request-information": { + "request-action": "CreateVnfInstance", + "source": "MSO", + "request-id": "1a545ea9-2a5e-4df9-9c73-529b1d0b2012" + }, + "sdnc-request-header": { + "svc-request-id": "8fd2622b-01fc-424d-bfc8-f48bcd64e546", + "svc-notification-url": "http://so-bpmn-infra.onap:8081/mso/WorkflowMessage/SDNCCallback/fd40ea09-3245-476a-b6ff-58cb042edb9d", + "svc-action": "assign" + }, + "service-information": { + "onap-model-information": { + "model-name": "Sol004Zip4Service", + "model-version": "1.0", + "model-uuid": "99d59273-4450-4034-9141-027f0c1a807a", + "model-invariant-uuid": "51672777-9b8d-4e5e-b488-5f9092e03a82" + }, + "subscription-service-type": "vCPE", + "service-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b", + "global-customer-id": "NordixDemoCustomer", + "service-instance-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b" + }, + "vnf-information": { + "onap-model-information": { + "model-name": "Sol004Zip3VSP", + "model-version": "1.0", + "model-customization-uuid": "50a90cd7-a84e-4ee1-b5ba-bfa5a26f5e15", + "model-uuid": "84b9649a-4eb9-4967-9abe-e8702f55518b", + "model-invariant-uuid": "b0f14066-2b65-40d2-b5a4-c8f2116fb5fc" + }, + "vnf-id": "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701", + "vnf-name": "EsyVnfInstantiationTest2", + "vnf-type": "Sol004Zip4Service/Sol004Zip3VSP 0" + }, + "vnf-request-input": { + "aic-cloud-region": "nordixcloud", + "cloud-owner": "CloudOwner", + "tenant": "693c7729b2364a26a3ca602e6f66187d", + "vnf-network-instance-group-ids": [], + "vnf-input-parameters": {}, + "vnf-name": "EsyVnfInstantiationTest2" + } + } +}
\ No newline at end of file |