diff options
Diffstat (limited to 'plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller')
8 files changed, 743 insertions, 0 deletions
diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AaiSimulatorControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AaiSimulatorControllerTest.java new file mode 100755 index 00000000..af9b2367 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aaisimulator.utils.Constants; +import org.onap.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/aaisimulator/controller/AbstractSpringBootTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/AbstractSpringBootTest.java new file mode 100755 index 00000000..4f2eab27 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/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.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.aaisimulator.utils.TestRestTemplateService; +import org.onap.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/aaisimulator/controller/BusinessControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/BusinessControllerTest.java new file mode 100755 index 00000000..9bab789d --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/BusinessControllerTest.java @@ -0,0 +1,109 @@ +/*- + * ============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.aaisimulator.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.onap.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; +import static org.onap.aaisimulator.utils.TestConstants.CUSTOMER_BASE_URL; +import static org.onap.aaisimulator.utils.TestConstants.SVC_INSTANCE_CUSTOMER_ID; +import static org.onap.aaisimulator.utils.TestConstants.SVC_INSTANCE_CUSTOMER_NAME; +import static org.onap.aaisimulator.utils.TestConstants.SVC_INSTANCE_URL; +import static org.onap.aaisimulator.utils.TestConstants.SVC_SUBSCRIPTIONS_URL; +import static org.onap.aaisimulator.utils.TestUtils.getSvcInstance; + +import java.io.IOException; +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aaisimulator.service.providers.CustomerCacheServiceProvider; +import org.onap.aaisimulator.utils.Constants; +import org.onap.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; + +public class BusinessControllerTest extends AbstractSpringBootTest { + + @Autowired + private CustomerCacheServiceProvider cacheServiceProvider; + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + + @Test + public void test_getSvcInstance_usingServiceInstanceId_fromCache() throws Exception { + final String url = getUrl(CUSTOMER_BASE_URL, SVC_SUBSCRIPTIONS_URL, SVC_INSTANCE_URL); + + final ResponseEntity<Void> responseEntity = testRestTemplateService + .invokeHttpPut(url, getSvcInstance(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final ResponseEntity<ServiceInstance> actual = testRestTemplateService + .invokeHttpGet(url, ServiceInstance.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceInstance actualServiceInstance = actual.getBody(); + + assertEquals(SVC_INSTANCE_CUSTOMER_NAME, actualServiceInstance.getServiceInstanceName()); + assertEquals(SVC_INSTANCE_CUSTOMER_ID, actualServiceInstance.getServiceInstanceId()); + } + + @Test + public void test_postForServiceInstanceId_fromCache() throws Exception { + addServiceInstnceToCache(); + 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 svcInstanceUrl = getUrl(CUSTOMER_BASE_URL, SVC_SUBSCRIPTIONS_URL, SVC_INSTANCE_URL); + final ResponseEntity<Void> postServiceInstanceResponse = testRestTemplateService + .invokeHttpPost(httpHeaders, svcInstanceUrl, TestUtils.getSvcInstance(), Void.class); + + assertEquals(HttpStatus.ACCEPTED, postServiceInstanceResponse.getStatusCode()); + + final ResponseEntity<ServiceInstance> response = + testRestTemplateService.invokeHttpGet(svcInstanceUrl, ServiceInstance.class); + assertEquals(HttpStatus.OK, response.getStatusCode()); + + assertTrue(response.hasBody()); + + final ServiceInstance actualServiceInstance = response.getBody(); + + assertEquals(SVC_INSTANCE_CUSTOMER_NAME, actualServiceInstance.getServiceInstanceName()); + assertEquals(SVC_INSTANCE_CUSTOMER_ID, actualServiceInstance.getServiceInstanceId()); + + } + + private void addServiceInstnceToCache() throws Exception, IOException { + final ResponseEntity<Void> serviceInstanceResponse = + testRestTemplateService.invokeHttpPut(getUrl(CUSTOMER_BASE_URL, SVC_SUBSCRIPTIONS_URL, SVC_INSTANCE_URL), + TestUtils.getSvcInstance(), Void.class); + assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode()); + } +}
\ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/LinesOfBusinessControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/LinesOfBusinessControllerTest.java new file mode 100755 index 00000000..0b6cfb50 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/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.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.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME; +import static org.onap.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.aaisimulator.models.Format; +import org.onap.aaisimulator.models.Results; +import org.onap.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider; +import org.onap.aaisimulator.utils.Constants; +import org.onap.aaisimulator.utils.TestConstants; +import org.onap.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/aaisimulator/controller/PlatformControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PlatformControllerTest.java new file mode 100755 index 00000000..00c66388 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/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.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.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL; +import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL; +import static org.onap.aaisimulator.utils.TestConstants.PLATFORM_NAME; +import static org.onap.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.aaisimulator.models.Format; +import org.onap.aaisimulator.models.Results; +import org.onap.aaisimulator.service.providers.PlatformCacheServiceProvider; +import org.onap.aaisimulator.utils.Constants; +import org.onap.aaisimulator.utils.TestConstants; +import org.onap.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/aaisimulator/controller/PnfsControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/PnfsControllerTest.java new file mode 100755 index 00000000..440c66d6 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/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.aaisimulator.controller; + +import org.junit.After; +import org.junit.Test; +import org.onap.aai.domain.yang.v15.Pnf; +import org.onap.aaisimulator.service.providers.PnfCacheServiceProvider; +import org.onap.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/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java new file mode 100644 index 00000000..d0e652bd --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/ServiceDesignAndCreationControllerTest.java @@ -0,0 +1,67 @@ +/*- + * ============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.aaisimulator.controller; + +import org.junit.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.aaisimulator.utils.TestConstants.SERVICE_DESIGN_AND_CREATION_URL; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, + properties = "SERVICE_DESIGN_AND_CREATION_RESPONSES_LOCATION=./src/test/resources/test-data/service-design-and-creation-responses") +public class ServiceDesignAndCreationControllerTest extends AbstractSpringBootTest{ + + @Test + public void should_reply_sample_modelvers_response() { + final String url = getUrl(SERVICE_DESIGN_AND_CREATION_URL, + "/models/model/a51e2bef-961c-496f-b235-b4540400e885/model-vers"); + ResponseEntity<String> actual = testRestTemplateService.invokeHttpGet(url, String.class); + String expectedXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + + "<model-vers xmlns=\"http://org.onap.aai.inventory/v11\">\n" + + " <model-ver>\n" + + " <model-version-id>c0818142-324d-4a8c-8065-45a61df247a5</model-version-id>\n" + + " <model-name>EricService</model-name>\n" + + " <model-version>1.0</model-version>\n" + + " <model-description>blah</model-description>\n" + + " <resource-version>1594657102313</resource-version>\n" + + " </model-ver>\n" + + " <model-ver>\n" + + " <model-version-id>4442dfc1-0d2d-46b4-b0bc-a2ac10448269</model-version-id>\n" + + " <model-name>EricService</model-name>\n" + + " <model-version>2.0</model-version>\n" + + " <model-description>blahhhh</model-description>\n" + + " <resource-version>1594707742646</resource-version>\n" + + " </model-ver>\n" + + "</model-vers>"; + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + MediaType contentType = actual.getHeaders().getContentType(); + assertNotNull(contentType); + assertTrue(contentType.isCompatibleWith(MediaType.APPLICATION_XML)); + assertEquals(expectedXml, actual.getBody()); + } +}
\ No newline at end of file diff --git a/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/configuration/TestRestTemplateConfigration.java b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/aaisimulator/controller/configuration/TestRestTemplateConfigration.java new file mode 100755 index 00000000..2e50d3d7 --- /dev/null +++ b/plans/usecases-pnf-sw-upgrade/pnf-sw-upgrade/sorch/simulator/aai-simulator/src/test/java/org/onap/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.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(); + } + +} |