diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2019-07-31 14:30:55 +0000 |
---|---|---|
committer | Waqas Ikram <waqas.ikram@est.tech> | 2019-07-31 14:31:34 +0000 |
commit | bf6e301bdedc4285cdd05826e29bdcbd68f8a699 (patch) | |
tree | 861616d982431272cd1b6d70485d89bd4f0fe5eb /plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test | |
parent | 50e113e064e31aed7435ac814e4776b72f842c8f (diff) |
Adding owning-entity endpoint
Change-Id: I2d0e05bc8563d86be38440dcbed7b2abcfe6411c
Issue-ID: SO-1953
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test')
8 files changed, 273 insertions, 1 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java index 283a2a20..ed9a129d 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java @@ -23,6 +23,7 @@ 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.aai.simulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; import static org.onap.so.aai.simulator.utils.TestConstants.CUSTOMERS_URL; import static org.onap.so.aai.simulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCES_URL; @@ -72,6 +73,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @Configuration public class BusinessControllerTest { + private static final String FIREWALL_SERVICE_TTYPE = "Firewall"; + + private static final String ORCHESTRATION_STATUS = "Active"; + @LocalServerPort private int port; @@ -287,10 +292,76 @@ public class BusinessControllerTest { } + @Test + public void test_PathSericeInstance_usingServiceInstanceId_OrchStatusChangedInCache() throws Exception { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final ResponseEntity<Void> serviceInstancePutResponse = invokeHttpPut(url, getServiceInstance()); + assertEquals(HttpStatus.ACCEPTED, serviceInstancePutResponse.getStatusCode()); + + final HttpHeaders httpHeaders = getHttpHeaders(); + httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString()); + + final HttpEntity<?> orchStatuUpdateServiceInstance = + getHttpEntity(getOrchStatuUpdateServiceInstance(), httpHeaders); + + final ResponseEntity<Void> orchStatuUpdateServiceInstanceResponse = + invokeHttpPost(orchStatuUpdateServiceInstance, url, getOrchStatuUpdateServiceInstance()); + + assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode()); + + + final ResponseEntity<ServiceInstance> actual = + restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), 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 = + getCustomerEndPointUrl() + "/service-subscriptions/service-subscription/" + FIREWALL_SERVICE_TTYPE; + + final ResponseEntity<Void> customerPutResponse = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + assertEquals(HttpStatus.ACCEPTED, customerPutResponse.getStatusCode()); + + final ResponseEntity<Void> serviceSubscriptionPutResponse = + invokeHttpPut(serviceSubscriptionurl, getServiceSubscription()); + assertEquals(HttpStatus.ACCEPTED, serviceSubscriptionPutResponse.getStatusCode()); + + final ResponseEntity<ServiceSubscription> actual = restTemplate.exchange(serviceSubscriptionurl, HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), ServiceSubscription.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceSubscription actualServiceSubscription = actual.getBody(); + assertEquals(FIREWALL_SERVICE_TTYPE, actualServiceSubscription.getServiceType()); + + } + private String getCustomer() throws Exception, IOException { return getJsonString("test-data/business-customer.json"); } + private String getServiceSubscription() throws Exception, IOException { + return getJsonString("test-data/service-subscription.json"); + } + + private String getCustomerEndPointUrl() { return TestUtils.getBaseUrl(port) + CUSTOMERS_URL; } @@ -300,10 +371,18 @@ public class BusinessControllerTest { return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); } + private ResponseEntity<Void> invokeHttpPost(final HttpEntity<?> httpEntity, final String url, final Object obj) { + return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Void.class); + } + private HttpEntity<?> getHttpEntity(final Object obj) { return new HttpEntity<>(obj, getHttpHeaders()); } + private HttpEntity<?> getHttpEntity(final Object obj, final HttpHeaders headers) { + return new HttpEntity<>(obj, headers); + } + private HttpHeaders getHttpHeaders() { return TestUtils.getHttpHeaders(username); } @@ -312,4 +391,8 @@ public class BusinessControllerTest { return getJsonString("test-data/service-instance.json"); } + private String getOrchStatuUpdateServiceInstance() throws Exception, IOException { + return getJsonString("test-data/service-instance-orch-status-update.json"); + } + } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java new file mode 100644 index 00000000..bbb2cad7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java @@ -0,0 +1,172 @@ +/*- + * ============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.aai.simulator.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.aai.simulator.utils.TestConstants.RELATIONSHIP_URL; +import static org.onap.so.aai.simulator.utils.TestUtils.getFile; +import static org.onap.so.aai.simulator.utils.TestUtils.getHttpHeaders; +import static org.onap.so.aai.simulator.utils.TestUtils.getJsonString; +import java.io.IOException; +import java.nio.file.Files; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.domain.yang.OwningEntity; +import org.onap.so.aai.simulator.models.Format; +import org.onap.so.aai.simulator.models.Result; +import org.onap.so.aai.simulator.service.providers.OwnEntityCacheServiceProvider; +import org.onap.so.aai.simulator.utils.Constants; +import org.onap.so.aai.simulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +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.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +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 OwningEntityControllerTest { + private static final String OWNING_ENTITY_JSON_FILE = "test-data/owning-entity.json"; + + private static final String OWN_ENTITY_ID_VALUE = "oe_1"; + private static final String OWN_ENTITY_NAME_VALUE = "oe_2"; + + private static final String OWNING_ENTITY_RELATION_SHIP_JSON_FILE = "test-data/owning-entity-relation-ship.json"; + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Value("${spring.security.username}") + private String username; + + @Autowired + private OwnEntityCacheServiceProvider cacheServiceProvider; + + @After + public void after() { + cacheServiceProvider.clearAll(); + } + + @Test + public void test_putOwningEntity_successfullyAddedToCache() throws Exception { + final String url = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE; + final String body = new String(Files.readAllBytes(getFile(OWNING_ENTITY_JSON_FILE).toPath())); + final ResponseEntity<Void> actual = invokeHttpPut(url, body); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity<OwningEntity> actualResponse = 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 = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE; + final String body = new String(Files.readAllBytes(getFile(OWNING_ENTITY_JSON_FILE).toPath())); + final ResponseEntity<Void> actual = invokeHttpPut(url, body); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity<Result> actualResponse = + invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Result.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final Result 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 { + final String url = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE; + final ResponseEntity<Void> actual = invokeHttpPut(url, getJsonString(OWNING_ENTITY_JSON_FILE)); + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final String owningEntityRelationshipUrl = url + RELATIONSHIP_URL; + + final ResponseEntity<Void> putResponse = invokeHttpPut(owningEntityRelationshipUrl, getRelationship()); + + assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode()); + + final ResponseEntity<OwningEntity> actualResponse = 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)); + + } + + private String getRelationship() throws IOException { + return TestUtils.getJsonString(OWNING_ENTITY_RELATION_SHIP_JSON_FILE); + } + + private <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) { + return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); + } + + private ResponseEntity<Void> invokeHttpPut(final String url, final Object obj) { + final HttpEntity<?> httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); + } + + private HttpEntity<?> getHttpEntity(final Object obj) { + return new HttpEntity<>(obj, getHttpHeaders(username)); + } + + private String getOwningEntityEndPointUrl() { + return TestUtils.getBaseUrl(port) + Constants.OWNING_ENTITY_URL; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java index b198e356..dbe70ce8 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java @@ -143,7 +143,7 @@ public class ProjectControllerTest { final Result result = actualResponse.getBody(); assertNotNull(result.getValues()); assertFalse(result.getValues().isEmpty()); - assertEquals(1, result.getValues().get(0).get(PROJECT_NAME_VALUE)); + assertEquals(1, result.getValues().get(0).get(Constants.PROJECT)); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java index 0bdf7a79..f57c946d 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java @@ -43,6 +43,8 @@ public class TestConstants { public static final String CUSTOMERS_URL = Constants.CUSTOMER_URL + GLOBAL_CUSTOMER_ID; + public static final String RELATIONSHIP_URL = "/relationship-list/relationship"; + private TestConstants() {} } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity-relation-ship.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity-relation-ship.json new file mode 100644 index 00000000..1c419476 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity-relation-ship.json @@ -0,0 +1,3 @@ +{ + "related-link": "/business/customers/customer/NordixDemoCustomer/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/ccece8fe-13da-456a-baf6-41b3a4a2bc2b" +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity.json new file mode 100644 index 00000000..7248d41d --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity.json @@ -0,0 +1,4 @@ +{ + "owning-entity-id": "oe_1", + "owning-entity-name": "oe_2" +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-instance-orch-status-update.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-instance-orch-status-update.json new file mode 100644 index 00000000..5cd566a6 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-instance-orch-status-update.json @@ -0,0 +1,5 @@ +{ + "service-instance-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b", + "service-instance-name": "ServiceTest", + "orchestration-status": "Active" +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-subscription.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-subscription.json new file mode 100644 index 00000000..e1b4f4f4 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-subscription.json @@ -0,0 +1,3 @@ +{ + "service-type": "Firewall" +} |