diff options
Diffstat (limited to 'plans/usecases/pnf-sw-upgrade/so/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils')
3 files changed, 383 insertions, 0 deletions
diff --git a/plans/usecases/pnf-sw-upgrade/so/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java b/plans/usecases/pnf-sw-upgrade/so/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/so/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/so/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestRestTemplateService.java b/plans/usecases/pnf-sw-upgrade/so/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/so/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/so/simulator/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java b/plans/usecases/pnf-sw-upgrade/so/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/so/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() {} + +} |