diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2020-09-09 09:41:54 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2020-09-09 10:04:06 +0100 |
commit | 1ac8b983b335076709b74d9f7d9768c188ee1891 (patch) | |
tree | a30ed33c7dc73002d6d0fca3fa8e4ce9cad322e7 /so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test | |
parent | 36982a7db770806b0a3e12d07686b4e3a72a0871 (diff) |
Adding NS instantiation
Change-Id: I06a8e1c9bfeb82f5fc61604030ec62bd17193e90
Issue-ID: SO-2868
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test')
2 files changed, 41 insertions, 10 deletions
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java index 4ff74eaaa1..81c4e8fd68 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java @@ -69,11 +69,16 @@ import com.google.gson.Gson; @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") public class NsLifecycleManagementControllerTest { + private static final String EXPECTED_BASE_URL = + "http://so-etsi-nfvo-ns-lcm.onap:9095/so/so-etsi-nfvo-ns-lcm/v1/api/nslcm/v1"; + private static final String RANDOM_NS_LCM_OP_OCC_ID = UUID.randomUUID().toString(); private static final String RANDOM_NS_INST_ID = UUID.randomUUID().toString(); private static final String SERVICE_TYPE = "NetworkService"; private static final String GLOBAL_CUSTOMER_ID = UUID.randomUUID().toString(); - private static final String EXPECTED_LOCATION_URL = "http://etsi-so-ns-lcm-manager-service:9095" - + "/so/so-etsi-nfvo-ns-lcm/v1/" + "api/nslcm/v1/ns_instances/" + RANDOM_NS_INST_ID; + private static final String EXPECTED_CREATE_REQ_LOCATION_URL = + EXPECTED_BASE_URL + "/ns_instances/" + RANDOM_NS_INST_ID; + private static final String EXPECTED_INSTANTIATE_REQ_LOCATION_URL = + EXPECTED_BASE_URL + "/ns_lcm_op_occs/" + RANDOM_NS_LCM_OP_OCC_ID; @LocalServerPort private int port; @@ -115,7 +120,7 @@ public class NsLifecycleManagementControllerTest { assertTrue(httpHeaders.containsKey(HttpHeaders.LOCATION)); final List<String> actual = httpHeaders.get(HttpHeaders.LOCATION); assertEquals(1, actual.size()); - assertEquals(EXPECTED_LOCATION_URL, actual.get(0)); + assertEquals(EXPECTED_CREATE_REQ_LOCATION_URL, actual.get(0)); } @Test @@ -177,11 +182,39 @@ public class NsLifecycleManagementControllerTest { @Test public void testInstantiateNs_ValidInstantiateNsRequest() { - final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString() + "/instantiate"; - final HttpEntity<?> request = new HttpEntity<>(getInstantiateNsRequest()); + + final InstantiateNsRequest instantiateNsRequest = getInstantiateNsRequest(); + when(mockedJobExecutorService.runInstantiateNsJob(eq(RANDOM_NS_INST_ID), eq(instantiateNsRequest))) + .thenReturn(RANDOM_NS_LCM_OP_OCC_ID); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + RANDOM_NS_INST_ID + "/instantiate"; + final HttpEntity<?> request = new HttpEntity<>(instantiateNsRequest); final ResponseEntity<Void> responseEntity = testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, Void.class); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final HttpHeaders httpHeaders = responseEntity.getHeaders(); + assertTrue(httpHeaders.containsKey(HttpHeaders.LOCATION)); + final List<String> actual = httpHeaders.get(HttpHeaders.LOCATION); + assertEquals(1, actual.size()); + assertEquals(EXPECTED_INSTANTIATE_REQ_LOCATION_URL, actual.get(0)); + } + + @Test + public void testInstantiateNs_instantiateNsRequest_nsRequestProcessingExceptionThrown_returnInlineResponse400() { + final String message = "Unable to process request"; + final InstantiateNsRequest instantiateNsRequest = getInstantiateNsRequest(); + when(mockedJobExecutorService.runInstantiateNsJob(eq(RANDOM_NS_INST_ID), eq(instantiateNsRequest))) + .thenThrow(new NsRequestProcessingException(message, new InlineResponse400().detail(message))); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + RANDOM_NS_INST_ID + "/instantiate"; + final HttpEntity<?> request = new HttpEntity<>(instantiateNsRequest); + final ResponseEntity<InlineResponse400> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, InlineResponse400.class); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); } @Test diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml index 6c8a7997af..44acda20a4 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml @@ -26,7 +26,7 @@ spring: nfvo: jdbcUrl: jdbc:h2:mem:NFVO;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS NFVO; driver-class-name: org.h2.Driver - pool-name: ns-lcm-bpmn-pool + pool-name: ns-lcm-nfvo-pool registerMbeans: true jpa: hibernate: @@ -36,6 +36,4 @@ logging: org.reflections.Reflections: ERROR etsi-catalog-manager: base: - endpoint: http://modeling-etsicatalog.onap:8806/api -etsi-so-ns-lcm-manager: - endpoint: http://etsi-so-ns-lcm-manager-service:9095
\ No newline at end of file + endpoint: http://modeling-etsicatalog.onap:8806/api
\ No newline at end of file |