diff options
author | 2020-05-06 01:14:00 +0100 | |
---|---|---|
committer | 2020-05-12 13:37:28 +0100 | |
commit | 125390ba301915c0829ad4c0b7eff0c935b6956c (patch) | |
tree | c49de4f058ebb4ce93fe90b72816246db7c938e4 /plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org | |
parent | 9c41697bdcef2eddd9af6436f3feb5821c238b44 (diff) |
Seperating usecase test suite dependencies
# Refactoring BulkPM Dataplane test suite
Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Change-Id: I4b2ad0dc5147e10ffc55f4ec210a29f073cd865b
Issue-ID: INT-832
Signed-off-by: efiacor <fiachra.corcoran@est.tech>
Diffstat (limited to 'plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org')
16 files changed, 2990 insertions, 0 deletions
diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java new file mode 100755 index 00000000..4fe5c403 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AaiSimulatorControllerTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestConstants; +import org.springframework.beans.factory.annotation.Autowired; +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.context.annotation.Configuration; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ActiveProfiles("test") +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Configuration +public class AaiSimulatorControllerTest { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void test_healthCheck_matchContent() { + final String url = getBaseUrl() + "/healthcheck"; + final ResponseEntity<String> object = restTemplate.getForEntity(url, String.class); + + assertEquals(Constants.HEALTHY, object.getBody()); + } + + private String getBaseUrl() { + return "https://localhost:" + port + TestConstants.BASE_URL_V17; + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AbstractSpringBootTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AbstractSpringBootTest.java new file mode 100755 index 00000000..84bb8cab --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/AbstractSpringBootTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.aaisimulator.controller; + +import java.util.List; +import org.junit.runner.RunWith; +import org.onap.aai.domain.yang.RelatedToProperty; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.so.aaisimulator.utils.TestRestTemplateService; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ActiveProfiles("test") +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Configuration +public abstract class AbstractSpringBootTest { + + @LocalServerPort + private int port; + + @Autowired + protected TestRestTemplateService testRestTemplateService; + + public String getUrl(final String... urls) { + return TestUtils.getUrl(port, urls); + } + + public RelationshipData getRelationshipData(final List<RelationshipData> relationshipData, final String key) { + return relationshipData.stream().filter(data -> data.getRelationshipKey().equals(key)).findFirst().orElse(null); + } + + public RelatedToProperty getRelatedToProperty(final List<RelatedToProperty> relatedToPropertyList, + final String key) { + return relatedToPropertyList.stream().filter(data -> data.getPropertyKey().equals(key)).findFirst() + .orElse(null); + } +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java new file mode 100755 index 00000000..c08c51ec --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java @@ -0,0 +1,397 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.RELATED_TO_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCES_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_TYPE; +import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID; +import static org.onap.so.aaisimulator.utils.TestUtils.getCustomer; +import static org.onap.so.aaisimulator.utils.TestUtils.getServiceInstance; +import java.io.IOException; +import java.util.Optional; +import java.util.UUID; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.Customer; +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.ServiceInstance; +import org.onap.aai.domain.yang.ServiceInstances; +import org.onap.aai.domain.yang.ServiceSubscription; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.utils.RequestError; +import org.onap.so.aaisimulator.utils.RequestErrorResponseUtils; +import org.onap.so.aaisimulator.utils.ServiceException; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class BusinessControllerTest extends AbstractSpringBootTest { + + private static final String FIREWALL_SERVICE_TYPE = "Firewall"; + + private static final String ORCHESTRATION_STATUS = "Active"; + + @Autowired + private CustomerCacheServiceProvider cacheServiceProvider; + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + + @Test + public void test_putCustomer_successfullyAddedToCache() throws Exception { + invokeCustomerEndPointAndAssertResponse(); + assertTrue(cacheServiceProvider.getCustomer(GLOBAL_CUSTOMER_ID).isPresent()); + } + + @Test + public void test_getCustomer_ableToRetrieveCustomer() throws Exception { + final String url = getUrl(CUSTOMERS_URL); + + final ResponseEntity<Void> response = testRestTemplateService.invokeHttpPut(url, getCustomer(), Void.class); + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final ResponseEntity<Customer> actual = testRestTemplateService.invokeHttpGet(url, Customer.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final Customer actualCustomer = actual.getBody(); + assertEquals(GLOBAL_CUSTOMER_ID, actualCustomer.getGlobalCustomerId()); + assertNotNull(actualCustomer.getResourceVersion()); + assertFalse(actualCustomer.getResourceVersion().isEmpty()); + } + + @Test + public void test_getCustomer_returnRequestError_ifCustomerNotInCache() throws Exception { + final String url = getUrl(CUSTOMERS_URL); + + final ResponseEntity<RequestError> actual = testRestTemplateService.invokeHttpGet(url, RequestError.class); + + assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); + + final RequestError actualError = actual.getBody(); + final ServiceException serviceException = actualError.getServiceException(); + + assertNotNull(serviceException); + assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE_ID, serviceException.getMessageId()); + assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE, serviceException.getText()); + assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); + + } + + @Test + public void test_getServiceSubscription_ableToRetrieveServiceSubscriptionFromCache() throws Exception { + final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL); + + invokeCustomerEndPointAndAssertResponse(); + + final ResponseEntity<ServiceSubscription> actual = + testRestTemplateService.invokeHttpGet(url, ServiceSubscription.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceSubscription actualServiceSubscription = actual.getBody(); + assertEquals(SERVICE_TYPE, actualServiceSubscription.getServiceType()); + assertNotNull(actualServiceSubscription.getRelationshipList()); + assertFalse(actualServiceSubscription.getRelationshipList().getRelationship().isEmpty()); + } + + @Test + public void test_putSericeInstance_ableToRetrieveServiceInstanceFromCache() throws Exception { + + invokeCustomerEndPointAndAssertResponse(); + invokeServiceInstanceEndPointAndAssertResponse(); + + + final Optional<ServiceInstance> actual = + cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); + + assertTrue(actual.isPresent()); + final ServiceInstance actualServiceInstance = actual.get(); + + assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId()); + assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName()); + + } + + @Test + public void test_getSericeInstance_usingServiceInstanceName_ableToRetrieveServiceInstanceFromCache() + throws Exception { + + invokeCustomerEndPointAndAssertResponse(); + invokeServiceInstanceEndPointAndAssertResponse(); + + + final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCES_URL) + + "?depth=2&service-instance-name=" + SERVICE_NAME; + + final ResponseEntity<ServiceInstances> actual = + testRestTemplateService.invokeHttpGet(serviceInstanceUrl, ServiceInstances.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceInstances actualServiceInstances = actual.getBody(); + assertFalse(actualServiceInstances.getServiceInstance().isEmpty()); + + assertEquals(SERVICE_NAME, actualServiceInstances.getServiceInstance().get(0).getServiceInstanceName()); + + } + + @Test + public void test_getSericeInstance_usingServiceInstanceName_returnRequestErrorIfnoServiceInstanceFound() + throws Exception { + + invokeCustomerEndPointAndAssertResponse(); + + final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCES_URL) + + "?depth=2&service-instance-name=" + SERVICE_NAME; + + final ResponseEntity<RequestError> actual = + testRestTemplateService.invokeHttpGet(serviceInstanceUrl, RequestError.class); + + assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + assertNotNull(actual.getBody().getServiceException()); + + } + + @Test + public void test_getSericeInstance_usingServiceInstanceId_ableToRetrieveServiceInstanceFromCache() + throws Exception { + + final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + + invokeCustomerEndPointAndAssertResponse(); + invokeServiceInstanceEndPointAndAssertResponse(); + + final ResponseEntity<ServiceInstance> actual = + testRestTemplateService.invokeHttpGet(url, ServiceInstance.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceInstance actualServiceInstance = actual.getBody(); + + assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName()); + assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId()); + + } + + @Test + public void test_getSericeInstance_usinginvalidServiceInstanceId_shouldReturnError() throws Exception { + + invokeCustomerEndPointAndAssertResponse(); + + invokeServiceInstanceEndPointAndAssertResponse(); + + + final String invalidServiceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, + SERVICE_INSTANCES_URL + "/service-instance/" + UUID.randomUUID()); + + final ResponseEntity<RequestError> actual = + testRestTemplateService.invokeHttpGet(invalidServiceInstanceUrl, RequestError.class); + + assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); + + final RequestError actualError = actual.getBody(); + final ServiceException serviceException = actualError.getServiceException(); + + assertNotNull(serviceException); + assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE_ID, serviceException.getMessageId()); + assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE, serviceException.getText()); + assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); + + } + + @Test + public void test_getSericeInstance_usingInvalidServiceInstanceName_shouldReturnError() throws Exception { + + invokeCustomerEndPointAndAssertResponse(); + invokeServiceInstanceEndPointAndAssertResponse(); + + + final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCES_URL) + + "?service-instance-name=Dummy&depth=2"; + + final ResponseEntity<RequestError> actual = + testRestTemplateService.invokeHttpGet(serviceInstanceUrl, RequestError.class); + + assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode()); + + final RequestError actualError = actual.getBody(); + final ServiceException serviceException = actualError.getServiceException(); + + assertNotNull(serviceException); + assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE_ID, serviceException.getMessageId()); + assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE, serviceException.getText()); + assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString())); + + } + + @Test + public void test_PathSericeInstance_usingServiceInstanceId_OrchStatusChangedInCache() throws Exception { + + final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + + invokeCustomerEndPointAndAssertResponse(); + invokeServiceInstanceEndPointAndAssertResponse(); + + final HttpHeaders httpHeaders = testRestTemplateService.getHttpHeaders(); + httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString()); + + final ResponseEntity<Void> orchStatuUpdateServiceInstanceResponse = testRestTemplateService + .invokeHttpPost(httpHeaders, url, TestUtils.getOrchStatuUpdateServiceInstance(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode()); + + final ResponseEntity<ServiceInstance> actual = + testRestTemplateService.invokeHttpGet(url, ServiceInstance.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceInstance actualServiceInstance = actual.getBody(); + + assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName()); + assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId()); + assertEquals(ORCHESTRATION_STATUS, actualServiceInstance.getOrchestrationStatus()); + + } + + @Test + public void test_putServiceSubscription_successfullyAddedToCache() throws Exception { + final String serviceSubscriptionurl = + getUrl(CUSTOMERS_URL, "/service-subscriptions/service-subscription/", FIREWALL_SERVICE_TYPE); + + invokeCustomerEndPointAndAssertResponse(); + + final ResponseEntity<Void> responseEntity = testRestTemplateService.invokeHttpPut(serviceSubscriptionurl, + TestUtils.getServiceSubscription(), Void.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final ResponseEntity<ServiceSubscription> actual = + testRestTemplateService.invokeHttpGet(serviceSubscriptionurl, ServiceSubscription.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceSubscription actualServiceSubscription = actual.getBody(); + assertEquals(FIREWALL_SERVICE_TYPE, actualServiceSubscription.getServiceType()); + + } + + @Test + public void test_putSericeInstanceRelatedTo_ableToRetrieveServiceInstanceFromCache() throws Exception { + + final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + + invokeCustomerEndPointAndAssertResponse(); + + invokeServiceInstanceEndPointAndAssertResponse(); + + final String relationShipUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL, + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); + + final ResponseEntity<Relationship> responseEntity2 = testRestTemplateService.invokeHttpPut(relationShipUrl, + TestUtils.getRelationShipJsonObject(), Relationship.class); + + assertEquals(HttpStatus.ACCEPTED, responseEntity2.getStatusCode()); + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> genericVnfResponse = + testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); + + final ResponseEntity<GenericVnfs> actual = testRestTemplateService + .invokeHttpGet(url + RELATED_TO_URL + "?vnf-name=" + GENERIC_VNF_NAME, GenericVnfs.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + + assertTrue(actual.hasBody()); + final GenericVnfs genericVnfs = actual.getBody(); + assertFalse(genericVnfs.getGenericVnf().isEmpty()); + final GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0); + assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName()); + } + + @Test + public void test_DeleteSericeInstance_ServiceInstanceRemovedFromCache() throws Exception { + final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + + invokeCustomerEndPointAndAssertResponse(); + + invokeServiceInstanceEndPointAndAssertResponse(); + + final Optional<ServiceInstance> optional = + cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); + assertTrue(optional.isPresent()); + final ServiceInstance serviceInstance = optional.get(); + + final ResponseEntity<Void> responseEntity = testRestTemplateService + .invokeHttpDelete(url + "?resource-version=" + serviceInstance.getResourceVersion(), Void.class); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + assertFalse(cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID) + .isPresent()); + } + + private void invokeServiceInstanceEndPointAndAssertResponse() throws IOException { + final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + final ResponseEntity<Void> responseEntity = + testRestTemplateService.invokeHttpPut(url, getServiceInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + } + + private void invokeCustomerEndPointAndAssertResponse() throws Exception, IOException { + final ResponseEntity<Void> response = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), getCustomer(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java new file mode 100755 index 00000000..1b967596 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java @@ -0,0 +1,420 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.Constants.VSERVER; +import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_OWNER_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_REGION_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_PASSWORD; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SERVICE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_LIST_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SYSTEM_TYPE; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_TYEP; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_USERNAME; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_VENDOR; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SYSTEM_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.TENANTS_TENANT; +import static org.onap.so.aaisimulator.utils.TestConstants.TENANT_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.VSERVER_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.VSERVER_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.VSERVER_URL; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.CloudRegion; +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.RelatedToProperty; +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.Tenant; +import org.onap.aai.domain.yang.Vserver; +import org.onap.so.aaisimulator.models.CloudRegionKey; +import org.onap.so.aaisimulator.service.providers.CloudRegionCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestConstants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class CloudRegionsControllerTest extends AbstractSpringBootTest { + + private static final CloudRegionKey CLOUD_REGION_KEY = new CloudRegionKey(CLOUD_OWNER_NAME, CLOUD_REGION_NAME); + + @Autowired + private CloudRegionCacheServiceProvider cloudRegionCacheServiceProvider; + + @Autowired + private CustomerCacheServiceProvider customerCacheServiceProvider; + + @Autowired + private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider; + + @After + public void after() { + cloudRegionCacheServiceProvider.clearAll(); + customerCacheServiceProvider.clearAll(); + genericVnfCacheServiceProvider.clearAll(); + } + + @Test + public void test_putCloudRegion_successfullyAddedToCache() throws Exception { + final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + invokeCloudRegionHttpPutEndPointAndAssertResponse(url); + + final ResponseEntity<CloudRegion> response = testRestTemplateService.invokeHttpGet(url, CloudRegion.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final CloudRegion cloudRegion = response.getBody(); + assertEquals(CLOUD_OWNER_NAME, cloudRegion.getCloudOwner()); + assertEquals(CLOUD_REGION_NAME, cloudRegion.getCloudRegionId()); + + assertNotNull("ResourceVersion should not be null", cloudRegion.getResourceVersion()); + + } + + @Test + public void test_getCloudRegionWithDepthValue_shouldReturnMatchedCloudRegion() throws Exception { + final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + invokeCloudRegionHttpPutEndPointAndAssertResponse(url); + + final ResponseEntity<CloudRegion> response = + testRestTemplateService.invokeHttpGet(url + "?depth=2", CloudRegion.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final CloudRegion cloudRegion = response.getBody(); + assertEquals(CLOUD_OWNER_NAME, cloudRegion.getCloudOwner()); + assertEquals(CLOUD_REGION_NAME, cloudRegion.getCloudRegionId()); + + assertNotNull("ResourceVersion should not be null", cloudRegion.getResourceVersion()); + + } + + @Test + public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { + + final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + invokeCloudRegionHttpPutEndPointAndAssertResponse(url); + + final String relationShipUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME, + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); + + final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, + TestUtils.getGenericVnfRelationShip(), Relationship.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final Optional<CloudRegion> optional = cloudRegionCacheServiceProvider.getCloudRegion(CLOUD_REGION_KEY); + assertTrue(optional.isPresent()); + + final CloudRegion actual = optional.get(); + + assertNotNull(actual.getRelationshipList()); + final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship(); + assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); + final Relationship relationship = relationshipList.get(0); + + assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink()); + + assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); + assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); + + final RelationshipData relationshipData = relationship.getRelationshipData().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey()); + assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue()); + + final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey()); + assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue()); + + } + + @Test + public void test_putTenant_successfullyAddedToCache() throws Exception { + final String cloudRegionUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + invokeCloudRegionHttpPutEndPointAndAssertResponse(cloudRegionUrl); + + final String tenantUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, + "/" + CLOUD_REGION_NAME + TENANTS_TENANT + TENANT_ID); + addTenantAndAssertResponse(tenantUrl); + + final ResponseEntity<Tenant> response = testRestTemplateService.invokeHttpGet(tenantUrl, Tenant.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Tenant tenant = response.getBody(); + assertEquals(TENANT_ID, tenant.getTenantId()); + assertEquals("admin", tenant.getTenantName()); + + assertNotNull("ResourceVersion should not be null", tenant.getResourceVersion()); + + } + + @Test + public void test_putTenantRelationToGenericVnf_successfullyAddedToCache() throws Exception { + + addCustomerServiceAndGenericVnf(); + + final String cloudRegionUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + invokeCloudRegionHttpPutEndPointAndAssertResponse(cloudRegionUrl); + + final String tenantUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME, + TENANTS_TENANT + TENANT_ID); + addTenantAndAssertResponse(tenantUrl); + + final String tenantRelationShipUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, + "/" + CLOUD_REGION_NAME, TENANTS_TENANT + TENANT_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); + + final ResponseEntity<Void> tenantRelationShipResponse = testRestTemplateService + .invokeHttpPut(tenantRelationShipUrl, TestUtils.getGenericVnfRelatedLink(), Void.class); + assertEquals(HttpStatus.ACCEPTED, tenantRelationShipResponse.getStatusCode()); + + final Optional<Tenant> optional = cloudRegionCacheServiceProvider.getTenant(CLOUD_REGION_KEY, TENANT_ID); + + assertTrue(optional.isPresent()); + final Tenant actualTenant = optional.get(); + final RelationshipList relationshipList = actualTenant.getRelationshipList(); + assertNotNull(relationshipList); + assertFalse(relationshipList.getRelationship().isEmpty()); + + final Relationship relationship = relationshipList.getRelationship().get(0); + + assertEquals(Constants.BELONGS_TO, relationship.getRelationshipLabel()); + assertFalse(relationship.getRelationshipData().isEmpty()); + assertEquals(1, relationship.getRelationshipData().size()); + + final List<RelationshipData> relationshipDataList = relationship.getRelationshipData(); + + final RelationshipData relationshipData = + getRelationshipData(relationshipDataList, Constants.GENERIC_VNF_VNF_ID); + assertNotNull(relationshipData); + assertEquals(VNF_ID, relationshipData.getRelationshipValue()); + + final List<RelatedToProperty> relatedToPropertyList = relationship.getRelatedToProperty(); + + final RelatedToProperty property = getRelatedToProperty(relatedToPropertyList, Constants.GENERIC_VNF_VNF_NAME); + assertNotNull(property); + assertEquals(GENERIC_VNF_NAME, property.getPropertyValue()); + + final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(genericVnfOptional.isPresent()); + final GenericVnf actualGenericVnf = genericVnfOptional.get(); + final RelationshipList relationshipListGenericVnf = actualGenericVnf.getRelationshipList(); + assertNotNull(relationshipListGenericVnf); + assertFalse(relationshipListGenericVnf.getRelationship().isEmpty()); + + final Relationship relationshipGenericVnf = relationshipListGenericVnf.getRelationship().get(0); + + assertEquals(Constants.BELONGS_TO, relationshipGenericVnf.getRelationshipLabel()); + assertFalse(relationshipGenericVnf.getRelationshipData().isEmpty()); + assertEquals(3, relationshipGenericVnf.getRelationshipData().size()); + + } + + @Test + public void test_putEsrSystemInfo_successfullyAddedToCache() throws Exception { + final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + invokeCloudRegionHttpPutEndPointAndAssertResponse(url); + + final String esrSystemInfoListUrl = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, + "/" + CLOUD_REGION_NAME, ESR_SYSTEM_INFO_LIST_URL); + + final String esrSystemInfoUrl = esrSystemInfoListUrl + "/esr-system-info/" + ESR_SYSTEM_INFO_ID; + final ResponseEntity<Void> esrSystemInfoResponse = + testRestTemplateService.invokeHttpPut(esrSystemInfoUrl, TestUtils.getEsrSystemInfo(), Void.class); + assertEquals(HttpStatus.ACCEPTED, esrSystemInfoResponse.getStatusCode()); + + final ResponseEntity<EsrSystemInfoList> response = + testRestTemplateService.invokeHttpGet(esrSystemInfoListUrl, EsrSystemInfoList.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + final EsrSystemInfoList actualEsrSystemInfoList = response.getBody(); + + final List<EsrSystemInfo> esrSystemInfoList = actualEsrSystemInfoList.getEsrSystemInfo(); + assertNotNull(esrSystemInfoList); + assertEquals(1, esrSystemInfoList.size()); + + final EsrSystemInfo esrSystemInfo = esrSystemInfoList.get(0); + assertEquals(ESR_SYSTEM_INFO_ID, esrSystemInfo.getEsrSystemInfoId()); + assertEquals(SYSTEM_NAME, esrSystemInfo.getSystemName()); + assertEquals(ESR_TYEP, esrSystemInfo.getType()); + assertEquals(ESR_VENDOR, esrSystemInfo.getVendor()); + assertEquals(ESR_SERVICE_URL, esrSystemInfo.getServiceUrl()); + assertEquals(ESR_USERNAME, esrSystemInfo.getUserName()); + assertEquals(ESR_PASSWORD, esrSystemInfo.getPassword()); + assertEquals(ESR_SYSTEM_TYPE, esrSystemInfo.getSystemType()); + } + + @Test + public void test_putVServer_successfullyAddedToCache() throws Exception { + final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + invokeCloudRegionHttpPutEndPointAndAssertResponse(url); + addCustomerServiceAndGenericVnf(); + + final String tenantUrl = url + TENANTS_TENANT + TENANT_ID; + addTenantAndAssertResponse(tenantUrl); + + final String vServerUrl = tenantUrl + VSERVER_URL + VSERVER_ID; + + final ResponseEntity<Void> vServerResponse = + testRestTemplateService.invokeHttpPut(vServerUrl, TestUtils.getVserver(), Void.class); + assertEquals(HttpStatus.ACCEPTED, vServerResponse.getStatusCode()); + + final ResponseEntity<Vserver> response = testRestTemplateService.invokeHttpGet(vServerUrl, Vserver.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + final Vserver actualVserver = response.getBody(); + assertEquals(VSERVER_NAME, actualVserver.getVserverName()); + assertEquals(VSERVER_ID, actualVserver.getVserverId()); + assertEquals("active", actualVserver.getProvStatus()); + assertNotNull(actualVserver.getRelationshipList()); + assertFalse(actualVserver.getRelationshipList().getRelationship().isEmpty()); + + final Optional<GenericVnf> optional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(optional.isPresent()); + final GenericVnf genericVnf = optional.get(); + assertNotNull(genericVnf.getRelationshipList()); + assertFalse(genericVnf.getRelationshipList().getRelationship().isEmpty()); + + final Relationship expectedRelationShip = genericVnf.getRelationshipList().getRelationship().get(0); + assertEquals(VSERVER, expectedRelationShip.getRelatedTo()); + assertNotNull(expectedRelationShip.getRelationshipData()); + assertEquals(4, expectedRelationShip.getRelationshipData().size()); + + final List<RelationshipData> relationshipDataList = expectedRelationShip.getRelationshipData(); + final RelationshipData vServerrelationshipData = + getRelationshipData(relationshipDataList, Constants.VSERVER_VSERVER_ID); + assertNotNull(vServerrelationshipData); + assertEquals(VSERVER_ID, vServerrelationshipData.getRelationshipValue()); + + final RelationshipData cloudOwnerRelationshipData = + getRelationshipData(relationshipDataList, Constants.CLOUD_REGION_CLOUD_OWNER); + assertNotNull(cloudOwnerRelationshipData); + assertEquals(CLOUD_OWNER_NAME, cloudOwnerRelationshipData.getRelationshipValue()); + + final RelationshipData cloudRegionIdRelationshipData = + getRelationshipData(relationshipDataList, Constants.CLOUD_REGION_CLOUD_REGION_ID); + assertNotNull(cloudRegionIdRelationshipData); + assertEquals(CLOUD_REGION_NAME, cloudRegionIdRelationshipData.getRelationshipValue()); + + final RelationshipData tenantRelationshipData = + getRelationshipData(relationshipDataList, Constants.TENANT_TENANT_ID); + assertNotNull(tenantRelationshipData); + assertEquals(TENANT_ID, tenantRelationshipData.getRelationshipValue()); + + } + + @Test + public void test_deleteVServer_successfullyRemoveFromCache() throws Exception { + final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + invokeCloudRegionHttpPutEndPointAndAssertResponse(url); + addCustomerServiceAndGenericVnf(); + + final String tenantUrl = url + TENANTS_TENANT + TENANT_ID; + addTenantAndAssertResponse(tenantUrl); + + final String vServerAddUrl = tenantUrl + VSERVER_URL + VSERVER_ID; + + final ResponseEntity<Void> vServerAddResponse = + testRestTemplateService.invokeHttpPut(vServerAddUrl, TestUtils.getVserver(), Void.class); + assertEquals(HttpStatus.ACCEPTED, vServerAddResponse.getStatusCode()); + + final Optional<Vserver> optional = + cloudRegionCacheServiceProvider.getVserver(CLOUD_REGION_KEY, TENANT_ID, VSERVER_ID); + assertTrue(optional.isPresent()); + final Vserver vserver = optional.get(); + + final String vServerRemoveUrl = vServerAddUrl + "?resource-version=" + vserver.getResourceVersion(); + + final ResponseEntity<Void> responseEntity = + testRestTemplateService.invokeHttpDelete(vServerRemoveUrl, Void.class); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + assertFalse(cloudRegionCacheServiceProvider.getVserver(CLOUD_REGION_KEY, TENANT_ID, VSERVER_ID).isPresent()); + + + } + + private void addTenantAndAssertResponse(final String tenantUrl) throws IOException { + final ResponseEntity<Void> responseEntity = + testRestTemplateService.invokeHttpPut(tenantUrl, TestUtils.getTenant(), Void.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + } + + private void addCustomerServiceAndGenericVnf() throws Exception, IOException { + final ResponseEntity<Void> customerResponse = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); + assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); + + final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + final ResponseEntity<Void> serviceInstanceResponse = + testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> genericVnfResponse = + testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); + + } + + private void invokeCloudRegionHttpPutEndPointAndAssertResponse(final String url) throws IOException { + final ResponseEntity<Void> responseEntity = + testRestTemplateService.invokeHttpPut(url, TestUtils.getCloudRegion(), Void.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ExternalSystemEsrControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ExternalSystemEsrControllerTest.java new file mode 100755 index 00000000..2fd5f7b8 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ExternalSystemEsrControllerTest.java @@ -0,0 +1,233 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_PASSWORD; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SERVICE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SYSTEM_INFO_LIST_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_SYSTEM_TYPE; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_TYEP; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_USERNAME; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_VENDOR; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_VIM_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_VNFM_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.ESR_VNFM_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SYSTEM_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import org.junit.After; +import org.junit.Test; +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.aaisimulator.service.providers.ExternalSystemCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestConstants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class ExternalSystemEsrControllerTest extends AbstractSpringBootTest { + + @Autowired + private ExternalSystemCacheServiceProvider externalSystemCacheServiceProvider; + + + @Autowired + private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider; + + @After + public void after() { + externalSystemCacheServiceProvider.clearAll(); + genericVnfCacheServiceProvider.clearAll(); + } + + @Test + public void test_putEsrVnfm_successfullyAddedToCache() throws Exception { + final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID); + addEsrVnfmAndAssertResponse(esrVnfmUrl); + + final ResponseEntity<EsrVnfm> response = testRestTemplateService.invokeHttpGet(esrVnfmUrl, EsrVnfm.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final EsrVnfm actualEsrVnfm = response.getBody(); + assertEquals(ESR_VNFM_ID, actualEsrVnfm.getVnfmId()); + assertEquals(ESR_VIM_ID, actualEsrVnfm.getVimId()); + + } + + @Test + public void test_getEsrVnfmList_getAllEsrVnfmsFromCache() throws Exception { + final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID); + addEsrVnfmAndAssertResponse(esrVnfmUrl); + + final String esrVnfmListUrl = getUrl(TestConstants.EXTERNAL_SYSTEM_ESR_VNFM_LIST_URL); + final ResponseEntity<EsrVnfmList> response = + testRestTemplateService.invokeHttpGet(esrVnfmListUrl, EsrVnfmList.class); + + assertTrue(response.hasBody()); + + final EsrVnfmList actualEsrVnfmList = response.getBody(); + + final List<EsrVnfm> esrVnfmList = actualEsrVnfmList.getEsrVnfm(); + assertNotNull(esrVnfmList); + assertEquals(1, esrVnfmList.size()); + final EsrVnfm actualEsrVnfm = esrVnfmList.get(0); + assertEquals(ESR_VNFM_ID, actualEsrVnfm.getVnfmId()); + assertEquals(ESR_VIM_ID, actualEsrVnfm.getVimId()); + + } + + @Test + public void test_putEsrSystemInfo_successfullyAddedToCache() throws Exception { + final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID); + addEsrVnfmAndAssertResponse(esrVnfmUrl); + final String esrSystemInfoListUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID, ESR_SYSTEM_INFO_LIST_URL); + + final String esrSystemInfoUrl = esrSystemInfoListUrl + "/esr-system-info/" + ESR_SYSTEM_INFO_ID; + final ResponseEntity<Void> esrSystemInfoResponse = + testRestTemplateService.invokeHttpPut(esrSystemInfoUrl, TestUtils.getEsrSystemInfo(), Void.class); + assertEquals(HttpStatus.ACCEPTED, esrSystemInfoResponse.getStatusCode()); + + final ResponseEntity<EsrSystemInfoList> response = + testRestTemplateService.invokeHttpGet(esrSystemInfoListUrl, EsrSystemInfoList.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + final EsrSystemInfoList actualEsrSystemInfoList = response.getBody(); + + final List<EsrSystemInfo> esrSystemInfoList = actualEsrSystemInfoList.getEsrSystemInfo(); + assertNotNull(esrSystemInfoList); + assertEquals(1, esrSystemInfoList.size()); + + final EsrSystemInfo esrSystemInfo = esrSystemInfoList.get(0); + assertEquals(ESR_SYSTEM_INFO_ID, esrSystemInfo.getEsrSystemInfoId()); + assertEquals(SYSTEM_NAME, esrSystemInfo.getSystemName()); + assertEquals(ESR_TYEP, esrSystemInfo.getType()); + assertEquals(ESR_VENDOR, esrSystemInfo.getVendor()); + assertEquals(ESR_SERVICE_URL, esrSystemInfo.getServiceUrl()); + assertEquals(ESR_USERNAME, esrSystemInfo.getUserName()); + assertEquals(ESR_PASSWORD, esrSystemInfo.getPassword()); + assertEquals(ESR_SYSTEM_TYPE, esrSystemInfo.getSystemType()); + + + } + + @Test + public void test_putEsrRelationToGenericVnfm_successfullyAddedToCache() throws Exception { + final String esrVnfmUrl = getUrl(ESR_VNFM_URL, ESR_VNFM_ID); + + addEsrVnfmAndAssertResponse(esrVnfmUrl); + addCustomerServiceAndGenericVnf(); + + final String relationShipUrl = esrVnfmUrl + RELATIONSHIP_LIST_RELATIONSHIP_URL; + + final ResponseEntity<Void> response = testRestTemplateService.invokeHttpPut(relationShipUrl, + TestUtils.getGenericVnfRelatedLink(), Void.class); + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final Optional<EsrVnfm> optional = externalSystemCacheServiceProvider.getEsrVnfm(ESR_VNFM_ID); + assertTrue(optional.isPresent()); + + final EsrVnfm actualEsrVnfm = optional.get(); + final RelationshipList relationshipList = actualEsrVnfm.getRelationshipList(); + assertNotNull(relationshipList); + assertFalse(relationshipList.getRelationship().isEmpty()); + + final Relationship relationship = relationshipList.getRelationship().get(0); + + assertEquals(Constants.DEPENDS_ON, relationship.getRelationshipLabel()); + assertFalse(relationship.getRelationshipData().isEmpty()); + assertEquals(1, relationship.getRelationshipData().size()); + + final RelationshipData relationshipData = + getRelationshipData(relationship.getRelationshipData(), Constants.GENERIC_VNF_VNF_ID); + assertNotNull(relationshipData); + assertEquals(VNF_ID, relationshipData.getRelationshipValue()); + + final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(genericVnfOptional.isPresent()); + final GenericVnf actualGenericVnf = genericVnfOptional.get(); + final RelationshipList relationshipListGenericVnf = actualGenericVnf.getRelationshipList(); + assertNotNull(relationshipListGenericVnf); + assertFalse(relationshipListGenericVnf.getRelationship().isEmpty()); + + final Relationship relationshipGenericVnf = relationshipListGenericVnf.getRelationship().get(0); + + assertEquals(Constants.DEPENDS_ON, relationshipGenericVnf.getRelationshipLabel()); + assertFalse(relationshipGenericVnf.getRelationshipData().isEmpty()); + assertEquals(1, relationshipGenericVnf.getRelationshipData().size()); + + final RelationshipData esrRelationshipData = + getRelationshipData(relationshipGenericVnf.getRelationshipData(), Constants.ESR_VNFM_VNFM_ID); + assertNotNull(esrRelationshipData); + assertEquals(ESR_VNFM_ID, esrRelationshipData.getRelationshipValue()); + + + } + + private void addEsrVnfmAndAssertResponse(final String esrVnfmUrl) throws IOException { + final ResponseEntity<Void> esrVnfmResponse = + testRestTemplateService.invokeHttpPut(esrVnfmUrl, TestUtils.getEsrVnfm(), Void.class); + assertEquals(HttpStatus.ACCEPTED, esrVnfmResponse.getStatusCode()); + } + + private void addCustomerServiceAndGenericVnf() throws Exception, IOException { + final ResponseEntity<Void> customerResponse = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); + assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); + + final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + final ResponseEntity<Void> serviceInstanceResponse = + testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> genericVnfResponse = + testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); + + } +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java new file mode 100755 index 00000000..8b6ec8c7 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java @@ -0,0 +1,430 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; +import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_OWNER_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_REGION_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.PLATFORM_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_TYPE; +import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.GenericVnfs; +import org.onap.aai.domain.yang.RelatedToProperty; +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.ServiceInstance; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestConstants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class GenericVnfsControllerTest extends AbstractSpringBootTest { + + @Autowired + private CustomerCacheServiceProvider customerCacheServiceProvider; + + @Autowired + private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider; + + @Autowired + private LinesOfBusinessCacheServiceProvider linesOfBusinessCacheServiceProvider; + + @Autowired + private PlatformCacheServiceProvider platformVnfCacheServiceProvider; + + @After + public void after() { + customerCacheServiceProvider.clearAll(); + genericVnfCacheServiceProvider.clearAll(); + platformVnfCacheServiceProvider.clearAll(); + linesOfBusinessCacheServiceProvider.clearAll(); + } + + @Test + public void test_putGenericVnf_successfullyAddedToCache() throws Exception { + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> genericVnfResponse = + testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); + + final ResponseEntity<GenericVnf> response = + testRestTemplateService.invokeHttpGet(genericVnfUrl, GenericVnf.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final GenericVnf actualGenericVnf = response.getBody(); + assertEquals(GENERIC_VNF_NAME, actualGenericVnf.getVnfName()); + assertEquals(VNF_ID, actualGenericVnf.getVnfId()); + + } + + @Test + public void test_putGenericVnfRelation_successfullyAddedToCache() throws Exception { + + addCustomerServiceAndGenericVnf(); + + final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); + final ResponseEntity<Void> genericVnfRelationShipResponse = testRestTemplateService + .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getRelationShip(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode()); + + + final Optional<ServiceInstance> optional = + customerCacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); + + assertTrue(optional.isPresent()); + + final ServiceInstance actualServiceInstance = optional.get(); + final RelationshipList actualRelationshipList = actualServiceInstance.getRelationshipList(); + assertNotNull(actualRelationshipList); + assertFalse(actualRelationshipList.getRelationship().isEmpty()); + final Relationship actualRelationShip = actualRelationshipList.getRelationship().get(0); + + assertEquals(Constants.COMPOSED_OF, actualRelationShip.getRelationshipLabel()); + assertEquals(GENERIC_VNF_URL + VNF_ID, actualRelationShip.getRelatedLink()); + + + assertFalse(actualRelationShip.getRelatedToProperty().isEmpty()); + assertFalse(actualRelationShip.getRelationshipData().isEmpty()); + final RelatedToProperty actualRelatedToProperty = actualRelationShip.getRelatedToProperty().get(0); + final RelationshipData actualRelationshipData = actualRelationShip.getRelationshipData().get(0); + + assertEquals(Constants.GENERIC_VNF_VNF_NAME, actualRelatedToProperty.getPropertyKey()); + assertEquals(GENERIC_VNF_NAME, actualRelatedToProperty.getPropertyValue()); + assertEquals(Constants.GENERIC_VNF_VNF_ID, actualRelationshipData.getRelationshipKey()); + assertEquals(VNF_ID, actualRelationshipData.getRelationshipValue()); + + final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(genericVnfOptional.isPresent()); + final GenericVnf actualGenericVnf = genericVnfOptional.get(); + final RelationshipList relationshipList = actualGenericVnf.getRelationshipList(); + assertNotNull(relationshipList); + assertFalse(relationshipList.getRelationship().isEmpty()); + + final Relationship relationship = relationshipList.getRelationship().get(0); + assertFalse(relationship.getRelatedToProperty().isEmpty()); + assertEquals(3, relationship.getRelationshipData().size()); + assertEquals(CUSTOMERS_URL + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL, relationship.getRelatedLink()); + + + final List<RelatedToProperty> relatedToProperty = relationship.getRelatedToProperty(); + final RelatedToProperty firstRelatedToProperty = relatedToProperty.get(0); + assertEquals(Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_NAME, firstRelatedToProperty.getPropertyKey()); + assertEquals(SERVICE_NAME, firstRelatedToProperty.getPropertyValue()); + + final List<RelationshipData> relationshipData = relationship.getRelationshipData(); + + final RelationshipData globalRelationshipData = + getRelationshipData(relationshipData, Constants.CUSTOMER_GLOBAL_CUSTOMER_ID); + assertNotNull(globalRelationshipData); + assertEquals(GLOBAL_CUSTOMER_ID, globalRelationshipData.getRelationshipValue()); + + final RelationshipData serviceSubscriptionRelationshipData = + getRelationshipData(relationshipData, Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE); + assertNotNull(serviceSubscriptionRelationshipData); + assertEquals(SERVICE_TYPE, serviceSubscriptionRelationshipData.getRelationshipValue()); + + final RelationshipData serviceInstanceRelationshipData = + getRelationshipData(relationshipData, Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID); + assertNotNull(serviceInstanceRelationshipData); + assertEquals(SERVICE_INSTANCE_ID, serviceInstanceRelationshipData.getRelationshipValue()); + + } + + @Test + public void test_putGenericVnfRelationToPlatform_successfullyAddedToCache() throws Exception { + addCustomerServiceAndGenericVnf(); + + final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); + final ResponseEntity<Void> platformResponse = + testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); + assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); + + final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); + final ResponseEntity<Void> genericVnfRelationShipResponse = testRestTemplateService + .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getPlatformRelatedLink(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode()); + + final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(genericVnfOptional.isPresent()); + final GenericVnf actualGenericVnf = genericVnfOptional.get(); + final RelationshipList relationshipList = actualGenericVnf.getRelationshipList(); + assertNotNull(relationshipList); + assertFalse(relationshipList.getRelationship().isEmpty()); + + final Relationship relationship = relationshipList.getRelationship().get(0); + + assertEquals(Constants.USES, relationship.getRelationshipLabel()); + assertFalse(relationship.getRelationshipData().isEmpty()); + assertEquals(1, relationship.getRelationshipData().size()); + assertEquals(TestConstants.PLATFORMS_URL + PLATFORM_NAME, relationship.getRelatedLink()); + + + final List<RelationshipData> relationshipData = relationship.getRelationshipData(); + + final RelationshipData platformRelationshipData = + getRelationshipData(relationshipData, Constants.PLATFORM_PLATFORM_NAME); + assertNotNull(platformRelationshipData); + assertEquals(PLATFORM_NAME, platformRelationshipData.getRelationshipValue()); + + } + + @Test + public void test_putGenericVnfRelationToLineOfBusiness_successfullyAddedToCache() throws Exception { + addCustomerServiceAndGenericVnf(); + + final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); + final ResponseEntity<Void> responseEntity = + testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); + final ResponseEntity<Void> genericVnfRelationShipResponse = testRestTemplateService + .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getLineOfBusinessRelatedLink(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode()); + + final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(genericVnfOptional.isPresent()); + final GenericVnf actualGenericVnf = genericVnfOptional.get(); + final RelationshipList relationshipList = actualGenericVnf.getRelationshipList(); + assertNotNull(relationshipList); + assertFalse(relationshipList.getRelationship().isEmpty()); + + final Relationship relationship = relationshipList.getRelationship().get(0); + + assertEquals(Constants.USES, relationship.getRelationshipLabel()); + assertEquals(TestConstants.LINES_OF_BUSINESS_URL + LINE_OF_BUSINESS_NAME, relationship.getRelatedLink()); + + assertFalse(relationship.getRelationshipData().isEmpty()); + assertEquals(1, relationship.getRelationshipData().size()); + + final List<RelationshipData> relationshipData = relationship.getRelationshipData(); + + final RelationshipData lineOfBusinessRelationshipData = + getRelationshipData(relationshipData, Constants.LINE_OF_BUSINESS_LINE_OF_BUSINESS_NAME); + assertNotNull(lineOfBusinessRelationshipData); + assertEquals(LINE_OF_BUSINESS_NAME, lineOfBusinessRelationshipData.getRelationshipValue()); + + } + + @Test + public void test_putGenericVnfRelationToCloudRegion_successfullyAddedToCache() throws Exception { + addCustomerServiceAndGenericVnf(); + + final String url = getUrl(TestConstants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME); + + final ResponseEntity<Void> responseEntity = + testRestTemplateService.invokeHttpPut(url, TestUtils.getCloudRegion(), Void.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL); + final ResponseEntity<Void> genericVnfRelationShipResponse = testRestTemplateService + .invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getCloudRegionRelatedLink(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode()); + + final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(genericVnfOptional.isPresent()); + final GenericVnf actualGenericVnf = genericVnfOptional.get(); + final RelationshipList relationshipList = actualGenericVnf.getRelationshipList(); + assertNotNull(relationshipList); + assertFalse(relationshipList.getRelationship().isEmpty()); + + final Relationship relationship = relationshipList.getRelationship().get(0); + + assertEquals(Constants.LOCATED_IN, relationship.getRelationshipLabel()); + assertEquals(TestConstants.CLOUD_REGIONS + CLOUD_OWNER_NAME + "/" + CLOUD_REGION_NAME, + relationship.getRelatedLink()); + + assertFalse(relationship.getRelationshipData().isEmpty()); + assertEquals(2, relationship.getRelationshipData().size()); + + final List<RelationshipData> relationshipDataList = relationship.getRelationshipData(); + + final RelationshipData cloudOwnerRelationshipData = + getRelationshipData(relationshipDataList, Constants.CLOUD_REGION_CLOUD_OWNER); + assertNotNull(cloudOwnerRelationshipData); + assertEquals(CLOUD_OWNER_NAME, cloudOwnerRelationshipData.getRelationshipValue()); + + final RelationshipData cloudRegionIdRelationshipData = + getRelationshipData(relationshipDataList, Constants.CLOUD_REGION_CLOUD_REGION_ID); + assertNotNull(cloudRegionIdRelationshipData); + assertEquals(CLOUD_REGION_NAME, cloudRegionIdRelationshipData.getRelationshipValue()); + + final List<RelatedToProperty> relatedToPropertyList = relationship.getRelatedToProperty(); + + final RelatedToProperty cloudRegionOwnerDefinedTypeProperty = + getRelatedToProperty(relatedToPropertyList, Constants.CLOUD_REGION_OWNER_DEFINED_TYPE); + assertNotNull(cloudRegionOwnerDefinedTypeProperty); + assertEquals("OwnerType", cloudRegionOwnerDefinedTypeProperty.getPropertyValue()); + + } + + @Test + public void test_putBiDirectionalRelationShip_successfullyAddedToCache() throws Exception { + addCustomerServiceAndGenericVnf(); + + final String relationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); + + final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, + TestUtils.getTenantRelationShip(), Relationship.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final Optional<GenericVnf> optional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(optional.isPresent()); + + final GenericVnf actual = optional.get(); + + assertNotNull(actual.getRelationshipList()); + final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship(); + assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); + final Relationship relationship = relationshipList.get(0); + + assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); + assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); + } + + @Test + public void test_patchGenericVnf_usingVnfId_OrchStatusChangedInCache() throws Exception { + addCustomerServiceAndGenericVnf(); + + final HttpHeaders httpHeaders = testRestTemplateService.getHttpHeaders(); + httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString()); + httpHeaders.remove(HttpHeaders.CONTENT_TYPE); + httpHeaders.add(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_MERGE_PATCH_JSON); + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> orchStatuUpdateServiceInstanceResponse = testRestTemplateService + .invokeHttpPost(httpHeaders, genericVnfUrl, TestUtils.getGenericVnfOrchStatuUpdate(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode()); + + final ResponseEntity<GenericVnf> response = + testRestTemplateService.invokeHttpGet(genericVnfUrl, GenericVnf.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final GenericVnf actualGenericVnf = response.getBody(); + assertEquals(GENERIC_VNF_NAME, actualGenericVnf.getVnfName()); + assertEquals(VNF_ID, actualGenericVnf.getVnfId()); + assertEquals("Assigned", actualGenericVnf.getOrchestrationStatus()); + + } + + @Test + public void test_getGenericVnfs_usingSelfLink_getAllGenericVnfsInCache() throws Exception { + + addCustomerServiceAndGenericVnf(); + + final String selfLink = "http://localhost:9921/generic-vnf/" + VNF_ID; + final String url = getUrl(TestConstants.GENERIC_VNFS_URL_1) + "?selflink=" + selfLink; + final ResponseEntity<GenericVnfs> response = testRestTemplateService.invokeHttpGet(url, GenericVnfs.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final GenericVnfs actualGenericVnfs = response.getBody(); + final List<GenericVnf> genericVnfList = actualGenericVnfs.getGenericVnf(); + assertNotNull(genericVnfList); + assertEquals(1, genericVnfList.size()); + final GenericVnf actualGenericVnf = genericVnfList.get(0); + assertEquals(selfLink, actualGenericVnf.getSelflink()); + assertEquals(GENERIC_VNF_NAME, actualGenericVnf.getVnfName()); + assertEquals(VNF_ID, actualGenericVnf.getVnfId()); + } + + @Test + public void test_deleteGenericVnf_usingVnfIdAndResourceVersion_removedFromCache() throws Exception { + + addCustomerServiceAndGenericVnf(); + + final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID); + assertTrue(genericVnfOptional.isPresent()); + final GenericVnf genericVnf = genericVnfOptional.get(); + + final String genericVnfDeleteUrl = + getUrl(GENERIC_VNF_URL, genericVnf.getVnfId()) + "?resource-version=" + genericVnf.getResourceVersion(); + + final ResponseEntity<Void> responseEntity = + testRestTemplateService.invokeHttpDelete(genericVnfDeleteUrl, Void.class); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + assertFalse(genericVnfCacheServiceProvider.getGenericVnf(VNF_ID).isPresent()); + + } + + private void addCustomerServiceAndGenericVnf() throws Exception, IOException { + final ResponseEntity<Void> customerResponse = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); + assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); + + final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + final ResponseEntity<Void> serviceInstanceResponse = + testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> genericVnfResponse = + testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); + + } + + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java new file mode 100755 index 00000000..30b3d279 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java @@ -0,0 +1,143 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID; +import java.util.List; +import java.util.Optional; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.LineOfBusiness; +import org.onap.aai.domain.yang.RelatedToProperty; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; +import org.onap.so.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestConstants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class LinesOfBusinessControllerTest extends AbstractSpringBootTest { + + @Autowired + private LinesOfBusinessCacheServiceProvider linesOfBusinessCacheServiceProvider; + + @After + public void after() { + linesOfBusinessCacheServiceProvider.clearAll(); + } + + @Test + public void test_putLineOfBusiness_successfullyAddedToCache() throws Exception { + + final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); + final ResponseEntity<Void> lineOfBusinessResponse = + testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); + assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode()); + + final ResponseEntity<LineOfBusiness> response = + testRestTemplateService.invokeHttpGet(url, LineOfBusiness.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final LineOfBusiness actualLineOfBusiness = response.getBody(); + assertEquals(LINE_OF_BUSINESS_NAME, actualLineOfBusiness.getLineOfBusinessName()); + assertNotNull("resource version should not be null", actualLineOfBusiness.getResourceVersion()); + + } + + @Test + public void test_getLineOfBusinessWithFormatCount() throws Exception { + + final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); + final ResponseEntity<Void> lineOfBusinessResponse = + testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); + assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode()); + + final ResponseEntity<Results> response = testRestTemplateService + .invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Results result = response.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(Constants.LINE_OF_BUSINESS)); + } + + + @Test + public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { + + final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME); + final ResponseEntity<Void> response = + testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class); + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final String relationShipUrl = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME, + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); + + final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl, + TestUtils.getGenericVnfRelationShip(), Relationship.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final Optional<LineOfBusiness> optional = + linesOfBusinessCacheServiceProvider.getLineOfBusiness(LINE_OF_BUSINESS_NAME); + assertTrue(optional.isPresent()); + + final LineOfBusiness actual = optional.get(); + + assertNotNull(actual.getRelationshipList()); + final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship(); + assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); + final Relationship relationship = relationshipList.get(0); + + assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink()); + assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); + assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); + + final RelationshipData relationshipData = relationship.getRelationshipData().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey()); + assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue()); + + final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey()); + assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue()); + + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java new file mode 100755 index 00000000..378d77df --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java @@ -0,0 +1,156 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.RESOURCE_LINK; +import static org.onap.so.aaisimulator.utils.Constants.RESOURCE_TYPE; +import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNFS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID; +import java.io.IOException; +import java.util.Map; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.GenericVnfs; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.NodesCacheServiceProvider; +import org.onap.so.aaisimulator.utils.TestConstants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class NodesControllerTest extends AbstractSpringBootTest { + + @Autowired + private NodesCacheServiceProvider nodesCacheServiceProvider; + + @Autowired + private CustomerCacheServiceProvider customerCacheServiceProvider; + + @After + public void after() { + nodesCacheServiceProvider.clearAll(); + customerCacheServiceProvider.clearAll(); + } + + @Test + public void test_getNodesSericeInstance_usingServiceInstanceId_ableToRetrieveServiceInstanceFromCache() + throws Exception { + + invokeCustomerandServiceInstanceUrls(); + + final ResponseEntity<ServiceInstance> actual = testRestTemplateService + .invokeHttpGet(getUrl(TestConstants.NODES_URL, SERVICE_INSTANCE_URL), ServiceInstance.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceInstance actualServiceInstance = actual.getBody(); + + assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName()); + assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId()); + + } + + @Test + public void test_getNodesSericeInstance_usingServiceInstanceIdAndFormatPathed_ableToRetrieveServiceInstanceFromCache() + throws Exception { + + invokeCustomerandServiceInstanceUrls(); + + final ResponseEntity<Results> actual = testRestTemplateService.invokeHttpGet( + getUrl(TestConstants.NODES_URL, SERVICE_INSTANCE_URL) + "?format=" + Format.PATHED.getValue(), + Results.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final Results result = actual.getBody(); + + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + final Map<String, Object> actualMap = result.getValues().get(0); + + assertEquals(CUSTOMERS_URL + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL, actualMap.get(RESOURCE_LINK)); + assertEquals(SERVICE_RESOURCE_TYPE, actualMap.get(RESOURCE_TYPE)); + + } + + @Test + public void test_getNodesGenericVnfs_usingVnfName_ableToRetrieveItFromCache() throws Exception { + invokeCustomerandServiceInstanceUrls(); + + final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID); + final ResponseEntity<Void> genericVnfResponse = + testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode()); + + final String nodeGenericVnfsUrl = + getUrl(TestConstants.NODES_URL, GENERIC_VNFS_URL) + "?vnf-name=" + GENERIC_VNF_NAME; + + final ResponseEntity<GenericVnfs> actual = + testRestTemplateService.invokeHttpGet(nodeGenericVnfsUrl, GenericVnfs.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final GenericVnfs genericVnfs = actual.getBody(); + assertEquals(1, genericVnfs.getGenericVnf().size()); + + final GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0); + assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName()); + assertEquals(VNF_ID, genericVnf.getVnfId()); + + } + + private void invokeCustomerandServiceInstanceUrls() throws Exception, IOException { + final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + + final ResponseEntity<Void> response = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final ResponseEntity<Void> response2 = + testRestTemplateService.invokeHttpPut(url, TestUtils.getServiceInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode()); + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java new file mode 100755 index 00000000..015994a5 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/OwningEntityControllerTest.java @@ -0,0 +1,199 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_TYPE; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.OwningEntity; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.OwnEntityCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestConstants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class OwningEntityControllerTest extends AbstractSpringBootTest { + + private static final String OWN_ENTITY_ID_VALUE = "oe_1"; + private static final String OWN_ENTITY_NAME_VALUE = "oe_2"; + + @Autowired + private OwnEntityCacheServiceProvider cacheServiceProvider; + + @Autowired + private CustomerCacheServiceProvider customerCacheServiceProvider; + + @After + public void after() { + cacheServiceProvider.clearAll(); + customerCacheServiceProvider.clearAll(); + } + + @Test + public void test_putOwningEntity_successfullyAddedToCache() throws Exception { + final String url = getUrl(TestConstants.OWNING_ENTITY_URL, OWN_ENTITY_ID_VALUE); + final ResponseEntity<Void> actual = + testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity<OwningEntity> actualResponse = + testRestTemplateService.invokeHttpGet(url, OwningEntity.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final OwningEntity actualOwningEntity = actualResponse.getBody(); + assertEquals(OWN_ENTITY_ID_VALUE, actualOwningEntity.getOwningEntityId()); + assertEquals(OWN_ENTITY_NAME_VALUE, actualOwningEntity.getOwningEntityName()); + assertNotNull(actualOwningEntity.getResourceVersion()); + + } + + @Test + public void test_getOwningEntityCount_correctResult() throws Exception { + final String url = getUrl(TestConstants.OWNING_ENTITY_URL, OWN_ENTITY_ID_VALUE); + final ResponseEntity<Void> actual = + testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity<Results> actualResponse = testRestTemplateService + .invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final Results result = actualResponse.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(Constants.OWNING_ENTITY)); + } + + @Test + public void test_putOwningEntityRelationShip_successfullyAddedToCache() throws Exception { + addCustomerAndServiceInstance(); + + final String url = getUrl(TestConstants.OWNING_ENTITY_URL, OWN_ENTITY_ID_VALUE); + final ResponseEntity<Void> actual = + testRestTemplateService.invokeHttpPut(url, TestUtils.getOwningEntity(), Void.class); + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final String owningEntityRelationshipUrl = url + RELATIONSHIP_LIST_RELATIONSHIP_URL; + + final ResponseEntity<Void> putResponse = testRestTemplateService.invokeHttpPut(owningEntityRelationshipUrl, + TestUtils.getOwningEntityRelationship(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode()); + + final ResponseEntity<OwningEntity> actualResponse = + testRestTemplateService.invokeHttpGet(url, OwningEntity.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final OwningEntity actualOwningEntity = actualResponse.getBody(); + assertEquals(OWN_ENTITY_ID_VALUE, actualOwningEntity.getOwningEntityId()); + assertEquals(OWN_ENTITY_NAME_VALUE, actualOwningEntity.getOwningEntityName()); + assertNotNull(actualOwningEntity.getRelationshipList()); + assertFalse(actualOwningEntity.getRelationshipList().getRelationship().isEmpty()); + assertNotNull(actualOwningEntity.getRelationshipList().getRelationship().get(0)); + + final Relationship actualRelationship = actualOwningEntity.getRelationshipList().getRelationship().get(0); + final List<RelationshipData> relationshipDataList = actualRelationship.getRelationshipData(); + assertEquals(Constants.BELONGS_TO, actualRelationship.getRelationshipLabel()); + assertFalse(relationshipDataList.isEmpty()); + assertEquals(3, relationshipDataList.size()); + + final RelationshipData globalRelationshipData = + getRelationshipData(relationshipDataList, Constants.CUSTOMER_GLOBAL_CUSTOMER_ID); + assertNotNull(globalRelationshipData); + assertEquals(GLOBAL_CUSTOMER_ID, globalRelationshipData.getRelationshipValue()); + + final RelationshipData serviceSubscriptionRelationshipData = + getRelationshipData(relationshipDataList, Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE); + assertNotNull(serviceSubscriptionRelationshipData); + assertEquals(SERVICE_TYPE, serviceSubscriptionRelationshipData.getRelationshipValue()); + + final RelationshipData serviceInstanceRelationshipData = + getRelationshipData(relationshipDataList, Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID); + assertNotNull(serviceInstanceRelationshipData); + assertEquals(SERVICE_INSTANCE_ID, serviceInstanceRelationshipData.getRelationshipValue()); + + final Optional<ServiceInstance> optional = + customerCacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); + assertTrue(optional.isPresent()); + + final ServiceInstance serviceInstance = optional.get(); + + assertNotNull(serviceInstance.getRelationshipList()); + final List<Relationship> serviceRelationshipList = serviceInstance.getRelationshipList().getRelationship(); + assertFalse(serviceRelationshipList.isEmpty()); + assertEquals(1, serviceRelationshipList.size()); + final Relationship relationship = serviceRelationshipList.get(0); + assertEquals(Constants.BELONGS_TO, relationship.getRelationshipLabel()); + assertEquals(TestConstants.OWNING_ENTITY_URL + OWN_ENTITY_ID_VALUE, relationship.getRelatedLink()); + + final List<RelationshipData> serviceRelationshipDataList = serviceRelationshipList.get(0).getRelationshipData(); + assertFalse(serviceRelationshipDataList.isEmpty()); + assertEquals(1, serviceRelationshipDataList.size()); + + final RelationshipData owningEntityRelationshipData = + getRelationshipData(serviceRelationshipDataList, Constants.OWNING_ENTITY_OWNING_ENTITY_ID); + assertNotNull(owningEntityRelationshipData); + assertEquals(OWN_ENTITY_ID_VALUE, owningEntityRelationshipData.getRelationshipValue()); + + } + + private void addCustomerAndServiceInstance() throws Exception, IOException { + final ResponseEntity<Void> customerResponse = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); + assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); + + final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + final ResponseEntity<Void> serviceInstanceResponse = + testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); + + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java new file mode 100755 index 00000000..7e88eec5 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java @@ -0,0 +1,142 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.PLATFORM_NAME; +import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID; +import java.util.List; +import java.util.Optional; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.Platform; +import org.onap.aai.domain.yang.RelatedToProperty; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.so.aaisimulator.models.Format; +import org.onap.so.aaisimulator.models.Results; +import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestConstants; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class PlatformControllerTest extends AbstractSpringBootTest { + + @Autowired + private PlatformCacheServiceProvider platformCacheServiceProvider; + + @After + public void after() { + platformCacheServiceProvider.clearAll(); + } + + @Test + public void test_putPlatform_successfullyAddedToCache() throws Exception { + + final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); + final ResponseEntity<Void> platformResponse = + testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); + assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); + + final ResponseEntity<Platform> response = testRestTemplateService.invokeHttpGet(platformUrl, Platform.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Platform actualPlatform = response.getBody(); + assertEquals(PLATFORM_NAME, actualPlatform.getPlatformName()); + assertNotNull("resource version should not be null", actualPlatform.getResourceVersion()); + + } + + @Test + public void test_getPlatformWithFormatCount() throws Exception { + + final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); + + final ResponseEntity<Void> platformResponse = + testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); + assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); + + final ResponseEntity<Results> response = testRestTemplateService.invokeHttpGet( + platformUrl + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Results result = response.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(Constants.PLATFORM)); + + } + + @Test + public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception { + + final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME); + final ResponseEntity<Void> platformResponse = + testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class); + assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode()); + + final String platformRelationShipUrl = + getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL); + + final ResponseEntity<Relationship> responseEntity = testRestTemplateService + .invokeHttpPut(platformRelationShipUrl, TestUtils.getGenericVnfRelationShip(), Relationship.class); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final Optional<Platform> optional = platformCacheServiceProvider.getPlatform(PLATFORM_NAME); + assertTrue(optional.isPresent()); + + final Platform actual = optional.get(); + + assertNotNull(actual.getRelationshipList()); + final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship(); + assertFalse("Relationship list should not be empty", relationshipList.isEmpty()); + final Relationship relationship = relationshipList.get(0); + + assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink()); + assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty()); + assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty()); + + final RelationshipData relationshipData = relationship.getRelationshipData().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey()); + assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue()); + + final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0); + assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey()); + assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue()); + + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PnfsControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PnfsControllerTest.java new file mode 100755 index 00000000..10e9b66f --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PnfsControllerTest.java @@ -0,0 +1,72 @@ +/*- + * ============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.aaisimulator.controller; + +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.v15.Pnf; +import org.onap.so.aaisimulator.service.providers.PnfCacheServiceProvider; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + + +/** + * @author Raj Gumma (raj.gumma@est.tech) + * + */ +public class PnfsControllerTest extends AbstractSpringBootTest { + + @Autowired + private PnfCacheServiceProvider cacheServiceProvider; + + private final String PNF="test-008"; + private final String PNF_URL= "/aai/v15/network/pnfs/pnf/"; + + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + + @Test + public void test_pnf_successfullyAddedToCache() throws Exception { + + final String url = getUrl(PNF_URL, PNF); + final ResponseEntity<Void> pnfResponse = + testRestTemplateService.invokeHttpPut(url, TestUtils.getPnf(), Void.class); + assertEquals(HttpStatus.ACCEPTED, pnfResponse.getStatusCode()); + + final ResponseEntity<Pnf> response = + testRestTemplateService.invokeHttpGet(url, Pnf.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final Pnf actualPnf = response.getBody(); + assertEquals("test-008", actualPnf.getPnfName()); + assertEquals("5f2602dc-f647-4535-8f1d-9ec079e68a49", actualPnf.getPnfId()); + + } +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java new file mode 100755 index 00000000..678d417b --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/ProjectControllerTest.java @@ -0,0 +1,205 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_TYPE; +import java.io.IOException; +import java.util.List; +import java.util.Optional; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.Project; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipData; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.so.aaisimulator.models.Results; +import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aaisimulator.service.providers.ProjectCacheServiceProvider; +import org.onap.so.aaisimulator.utils.Constants; +import org.onap.so.aaisimulator.utils.TestConstants; +import org.onap.so.aaisimulator.utils.TestRestTemplateService; +import org.onap.so.aaisimulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class ProjectControllerTest extends AbstractSpringBootTest { + + private static final String PROJECT_NAME_VALUE = "PROJECT_NAME_VALUE"; + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplateService testRestTemplateService; + + @Autowired + private ProjectCacheServiceProvider cacheServiceProvider; + + @Autowired + private CustomerCacheServiceProvider customerCacheServiceProvider; + + @After + public void after() { + cacheServiceProvider.clearAll(); + customerCacheServiceProvider.clearAll(); + } + + @Test + public void test_putProject_successfullyAddedToCache() throws Exception { + final String url = getUrl(TestConstants.PROJECT_URL, PROJECT_NAME_VALUE); + final ResponseEntity<Void> actual = + testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity<Project> actualResponse = testRestTemplateService.invokeHttpGet(url, Project.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final Project actualProject = actualResponse.getBody(); + assertEquals(PROJECT_NAME_VALUE, actualProject.getProjectName()); + assertNotNull(actualProject.getResourceVersion()); + + } + + @Test + public void test_putProjectRelationShip_successfullyAddedToCache() throws Exception { + addCustomerAndServiceInstance(); + + final String url = getUrl(TestConstants.PROJECT_URL, PROJECT_NAME_VALUE); + final ResponseEntity<Void> actual = + testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class); + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final String projectRelationshipUrl = + getUrl(TestConstants.PROJECT_URL, PROJECT_NAME_VALUE, RELATIONSHIP_LIST_RELATIONSHIP_URL); + + final ResponseEntity<Void> putResponse = testRestTemplateService.invokeHttpPut(projectRelationshipUrl, + TestUtils.getBusinessProjectRelationship(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode()); + + final ResponseEntity<Project> actualResponse = testRestTemplateService.invokeHttpGet(url, Project.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final Project actualProject = actualResponse.getBody(); + assertEquals(PROJECT_NAME_VALUE, actualProject.getProjectName()); + assertNotNull(actualProject.getRelationshipList()); + assertFalse(actualProject.getRelationshipList().getRelationship().isEmpty()); + assertNotNull(actualProject.getRelationshipList().getRelationship().get(0)); + + final Relationship actualRelationship = actualProject.getRelationshipList().getRelationship().get(0); + final List<RelationshipData> relationshipDataList = actualRelationship.getRelationshipData(); + assertEquals(Constants.USES, actualRelationship.getRelationshipLabel()); + + assertFalse(relationshipDataList.isEmpty()); + assertEquals(3, relationshipDataList.size()); + + final RelationshipData globalRelationshipData = + getRelationshipData(relationshipDataList, Constants.CUSTOMER_GLOBAL_CUSTOMER_ID); + assertNotNull(globalRelationshipData); + assertEquals(GLOBAL_CUSTOMER_ID, globalRelationshipData.getRelationshipValue()); + + final RelationshipData serviceSubscriptionRelationshipData = + getRelationshipData(relationshipDataList, Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE); + assertNotNull(serviceSubscriptionRelationshipData); + assertEquals(SERVICE_TYPE, serviceSubscriptionRelationshipData.getRelationshipValue()); + + final RelationshipData serviceInstanceRelationshipData = + getRelationshipData(relationshipDataList, Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID); + assertNotNull(serviceInstanceRelationshipData); + assertEquals(SERVICE_INSTANCE_ID, serviceInstanceRelationshipData.getRelationshipValue()); + + final Optional<ServiceInstance> optional = + customerCacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID); + assertTrue(optional.isPresent()); + + final ServiceInstance serviceInstance = optional.get(); + + assertNotNull(serviceInstance.getRelationshipList()); + final List<Relationship> serviceRelationshipList = serviceInstance.getRelationshipList().getRelationship(); + assertFalse(serviceRelationshipList.isEmpty()); + assertEquals(1, serviceRelationshipList.size()); + final Relationship relationship = serviceRelationshipList.get(0); + assertEquals(Constants.USES, relationship.getRelationshipLabel()); + assertEquals(TestConstants.PROJECT_URL + PROJECT_NAME_VALUE, relationship.getRelatedLink()); + + + final List<RelationshipData> serviceRelationshipDataList = serviceRelationshipList.get(0).getRelationshipData(); + assertFalse(serviceRelationshipDataList.isEmpty()); + assertEquals(1, serviceRelationshipDataList.size()); + + final RelationshipData projectRelationshipData = + getRelationshipData(serviceRelationshipDataList, Constants.PROJECT_PROJECT_NAME); + assertNotNull(projectRelationshipData); + assertEquals(PROJECT_NAME_VALUE, projectRelationshipData.getRelationshipValue()); + + } + + @Test + public void test_getProjectCount_correctResult() throws Exception { + final String url = getUrl(TestConstants.PROJECT_URL, PROJECT_NAME_VALUE); + final ResponseEntity<Void> actual = + testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity<Results> actualResponse = + testRestTemplateService.invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=count", Results.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final Results result = actualResponse.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(Constants.PROJECT)); + } + + + private void addCustomerAndServiceInstance() throws Exception, IOException { + final ResponseEntity<Void> customerResponse = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class); + assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode()); + + final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL); + final ResponseEntity<Void> serviceInstanceResponse = + testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); + + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java new file mode 100755 index 00000000..92036e83 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java @@ -0,0 +1,80 @@ +/*- + * ============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.aaisimulator.controller.configuration; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLSession; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContexts; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Profile("test") +@Configuration +public class TestRestTemplateConfigration { + + private static final Logger LOGGER = LoggerFactory.getLogger(TestRestTemplateConfigration.class); + + @Bean + public TestRestTemplate testRestTemplate() throws Exception { + final TestRestTemplate testRestTemplate = new TestRestTemplate(); + ((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRestTemplate().getRequestFactory()) + .setHttpClient(httpClient()); + return testRestTemplate; + + } + + @Bean + public RestTemplate restTemplate() throws Exception { + final RestTemplate restTemplate = new RestTemplate(); + restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient())); + return restTemplate; + } + + private CloseableHttpClient httpClient() throws Exception { + final TrustStrategy acceptingTrustStrategy = (cert, authType) -> true; + + final SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory( + SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build(), new HostnameVerifier() { + @Override + public boolean verify(final String hostname, final SSLSession session) { + LOGGER.warn("Skiping hostname verification ... "); + return true; + } + + }); + + return HttpClients.custom().setSSLSocketFactory(csf).build(); + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java new file mode 100755 index 00000000..85ceeef3 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java @@ -0,0 +1,118 @@ +/*- + * ============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.aaisimulator.utils; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class TestConstants { + + public static final String BASE_URL_V17 = "/aai/v17"; + + public static final String SERVICE_INSTANCES_URL = "/service-instances"; + + public static final String SERVICE_NAME = "ServiceTest"; + + public static final String SERVICE_INSTANCE_ID = "ccece8fe-13da-456a-baf6-41b3a4a2bc2b"; + + public static final String SERVICE_INSTANCE_URL = + SERVICE_INSTANCES_URL + "/service-instance/" + SERVICE_INSTANCE_ID; + + public static final String SERVICE_TYPE = "vCPE"; + + public static final String SERVICE_SUBSCRIPTIONS_URL = + "/service-subscriptions/service-subscription/" + SERVICE_TYPE; + + public static final String GLOBAL_CUSTOMER_ID = "DemoCustomer"; + + public static final String CUSTOMERS_URL = BASE_URL_V17 + "/business/customers/customer/" + GLOBAL_CUSTOMER_ID; + + public static final String VNF_ID = "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701"; + + public static final String GENERIC_VNF_NAME = "EsyVnfInstantiationTest2"; + + public static final String GENERIC_VNF_URL = BASE_URL_V17 + "/network/generic-vnfs/generic-vnf/"; + + public static final String GENERIC_VNFS_URL = "/generic-vnfs"; + + public static final String RELATED_TO_URL = "/related-to" + GENERIC_VNFS_URL; + + public static final String PLATFORM_NAME = "PLATFORM_APP_ID_1"; + + public static final String LINE_OF_BUSINESS_NAME = "LINE_OF_BUSINESS_1"; + + public static final String CLOUD_OWNER_NAME = "CloudOwner"; + + public static final String CLOUD_REGION_NAME = "PnfSwUCloudRegion"; + + public static final String TENANT_ID = "693c7729b2364a26a3ca602e6f66187d"; + + public static final String TENANTS_TENANT = "/tenants/tenant/"; + + public static final String ESR_VNFM_URL = BASE_URL_V17 + "/external-system/esr-vnfm-list/esr-vnfm/"; + + public static final String EXTERNAL_SYSTEM_ESR_VNFM_LIST_URL = BASE_URL_V17 + "/external-system/esr-vnfm-list"; + + public static final String ESR_VNFM_ID = "c5e99cee-1996-4606-b697-838d51d4e1a3"; + + public static final String ESR_VIM_ID = "PnfSwUVimId"; + + public static final String ESR_SYSTEM_INFO_LIST_URL = "/esr-system-info-list"; + + public static final String ESR_SYSTEM_INFO_ID = "5c067098-f2e3-40f7-a7ba-155e7c61e916"; + + public static final String ESR_SYSTEM_TYPE = "VNFM"; + + public static final String ESR_PASSWORD = "123456"; + + public static final String ESR_USERNAME = "vnfmadapter"; + + public static final String ESR_SERVICE_URL = "https://so-vnfm-simulator.onap:9095/vnflcm/v1"; + + public static final String ESR_VENDOR = "EST"; + + public static final String ESR_TYEP = "simulator"; + + public static final String SYSTEM_NAME = "vnfmSimulator"; + + public static final String VSERVER_URL = "/vservers/vserver/"; + + public static final String VSERVER_NAME = "CsitVServer"; + + public static final String VSERVER_ID = "f84fdb9b-ad7c-49db-a08f-e443b4cbd033"; + + public static final String OWNING_ENTITY_URL = BASE_URL_V17 + "/business/owning-entities/owning-entity/"; + + public static final String LINES_OF_BUSINESS_URL = BASE_URL_V17 + "/business/lines-of-business/line-of-business/"; + + public static final String PLATFORMS_URL = BASE_URL_V17 + "/business/platforms/platform/"; + + public static final String CLOUD_REGIONS = BASE_URL_V17 + "/cloud-infrastructure/cloud-regions/cloud-region/"; + + public static final String GENERIC_VNFS_URL_1 = BASE_URL_V17 + "/network/generic-vnfs"; + + public static final String NODES_URL = BASE_URL_V17 + "/nodes"; + + public static final String PROJECT_URL = BASE_URL_V17 + "/business/projects/project/"; + + private TestConstants() {} + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java new file mode 100755 index 00000000..e49e6d49 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java @@ -0,0 +1,79 @@ +/*- + * ============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.aaisimulator.utils; + +import org.onap.so.simulator.model.UserCredentials; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ + +@Service +public class TestRestTemplateService { + + @Autowired + private TestRestTemplate restTemplate; + + @Autowired + private UserCredentials userCredentials; + + + public <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) { + return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), clazz); + } + + public <T> ResponseEntity<T> invokeHttpPut(final String url, final Object obj, final Class<T> clazz) { + final HttpEntity<?> httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, clazz); + } + + public <T> ResponseEntity<T> invokeHttpDelete(final String url, final Class<T> clazz) { + final HttpEntity<?> request = new HttpEntity<>(getHttpHeaders()); + return restTemplate.exchange(url, HttpMethod.DELETE, request, clazz); + } + + public <T> ResponseEntity<T> invokeHttpPost(final String url, final Object obj, final Class<T> clazz) { + final HttpEntity<?> httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.POST, httpEntity, clazz); + } + + public <T> ResponseEntity<T> invokeHttpPost(final HttpHeaders headers, final String url, final Object obj, + final Class<T> clazz) { + final HttpEntity<Object> entity = new HttpEntity<>(obj, headers); + return restTemplate.exchange(url, HttpMethod.POST, entity, clazz); + } + + private HttpEntity<?> getHttpEntity(final Object obj) { + return new HttpEntity<>(obj, getHttpHeaders()); + } + + public HttpHeaders getHttpHeaders() { + return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); + } + +} diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java new file mode 100755 index 00000000..55eb0ef5 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java @@ -0,0 +1,186 @@ +/*- + * ============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.aaisimulator.utils; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Base64; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.web.util.UriComponentsBuilder; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class TestUtils { + + private static final String PASSWORD = "aai.onap.org:demo123456!"; + + 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 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 <T> T getObjectFromFile(final File file, final Class<T> clazz) throws Exception { + final ObjectMapper mapper = new ObjectMapper(); + mapper.registerModule(new JaxbAnnotationModule()); + + return mapper.readValue(file, clazz); + } + + public static String getBasicAuth(final String username) { + return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); + } + + public static String getBaseUrl(final int port) { + return "https://localhost:" + port; + } + + public static String getCustomer() throws Exception, IOException { + return getJsonString("test-data/business-customer.json"); + } + + public static String getServiceSubscription() throws IOException { + return getJsonString("test-data/service-subscription.json"); + } + + public static String getServiceInstance() throws IOException { + return getJsonString("test-data/service-instance.json"); + } + + public static String getGenericVnf() throws IOException { + return getJsonString("test-data/generic-vnf.json"); + } + + public static String getPnf() throws IOException { + return getJsonString("test-data/pnf.json"); + } + + public static String getRelationShip() throws IOException { + return getJsonString("test-data/relation-ship.json"); + } + + public static String getPlatformRelatedLink() throws IOException { + return getJsonString("test-data/platform-related-link.json"); + } + + public static String getLineOfBusinessRelatedLink() throws IOException { + return getJsonString("test-data/line-of-business-related-link.json"); + } + + public static String getPlatform() throws IOException { + return getJsonString("test-data/platform.json"); + } + + public static String getGenericVnfRelationShip() throws IOException { + return getJsonString("test-data/generic-vnf-relationship.json"); + } + + public static String getLineOfBusiness() throws IOException { + return getJsonString("test-data/line-of-business.json"); + } + + public static String getBusinessProject() throws IOException { + return getJsonString("test-data/business-project.json"); + } + + public static String getBusinessProjectRelationship() throws IOException { + return getJsonString("test-data/business-project-relation-ship.json"); + } + + public static String getOwningEntityRelationship() throws IOException { + return getJsonString("test-data/owning-entity-relation-ship.json"); + } + + public static String getOwningEntity() throws IOException { + return getJsonString("test-data/owning-entity.json"); + } + + public static String getOrchStatuUpdateServiceInstance() throws IOException { + return getJsonString("test-data/service-instance-orch-status-update.json"); + } + + public static String getRelationShipJsonObject() throws IOException { + return getJsonString("test-data/service-Instance-relationShip.json"); + } + + public static String getCloudRegion() throws IOException { + return getJsonString("test-data/cloud-region.json"); + } + + public static String getTenant() throws IOException { + return getJsonString("test-data/tenant.json"); + } + + public static String getCloudRegionRelatedLink() throws IOException { + return getJsonString("test-data/cloud-region-related-link.json"); + } + + public static String getGenericVnfRelatedLink() throws IOException { + return getJsonString("test-data/generic-vnf-related-link.json"); + } + + public static String getTenantRelationShip() throws IOException { + return getJsonString("test-data/tenant-relationship.json"); + } + + public static String getGenericVnfOrchStatuUpdate() throws IOException { + return getJsonString("test-data/generic-vnf-orch-status-update.json"); + } + + public static String getEsrVnfm() throws IOException { + return getJsonString("test-data/esr-vnfm.json"); + } + + public static String getEsrSystemInfo() throws IOException { + return getJsonString("test-data/esr-system-info.json"); + } + + public static String getVserver() throws IOException { + return getJsonString("test-data/vServer.json"); + } + + + public static String getUrl(final int port, final String... urls) { + final UriComponentsBuilder baseUri = UriComponentsBuilder.fromUriString("https://localhost:" + port); + for (final String url : urls) { + baseUri.path(url); + } + return baseUri.toUriString(); + } + + private TestUtils() {} + +} |