From 32b63e325892a9d8fad881a601095971d1e84fbe Mon Sep 17 00:00:00 2001 From: seanbeirne Date: Thu, 30 Mar 2023 19:16:28 +0100 Subject: 500 Error Response on NCMP ID-Searches Testing Issue-ID: CPS-1563 Signed-off-by: seanbeirne Change-Id: Idc393e90d31b369095bc2b122537e17a4464a364 --- .../NetworkCmProxyInventoryControllerSpec.groovy | 44 +++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy index 88f496a18..300026d34 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021-2022 Bell Canada - * Modifications Copyright (C) 2021-2022 Nordix Foundation + * Modifications Copyright (C) 2021-2023 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -129,6 +129,48 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { 'populates response' | ['cmHandle1', 'cmHandle2'] } + def 'CmHandle search endpoint test #scenario with blank cmHandleQueryParameters.'() { + given: 'a query object' + def cmHandleQueryParameters = "{}" + and: 'the mapper service returns a converted object' + ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters + and: 'the service returns the desired results' + mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> serviceMockResponse + when: 'post request is performed & search is called with the given request parameters' + def response = mvc.perform( + post("$ncmpBasePathV1/ch/searches") + .contentType(MediaType.APPLICATION_JSON) + .content(cmHandleQueryParameters) + ).andReturn().response + then: 'response status is OK' + assert response.status == HttpStatus.OK.value() + and: 'the response data matches the service response.' + jsonObjectMapper.convertJsonString(response.getContentAsString(), List) == serviceMockResponse + where: 'the service respond with' + scenario | serviceMockResponse + 'empty response' | [] + 'populates response' | ['cmHandle1', 'cmHandle2'] + } + + def 'CmHandle search endpoint Error Handling.'() { + given: 'the mapper service returns a converted object' + ncmpRestInputMapper.toCmHandleQueryServiceParameters(_) >> cmHandleQueryServiceParameters + and: 'the service returns the desired results' + mockNetworkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters) >> [] + when: 'post request is performed & search is called with the given request parameters' + def response = mvc.perform( + post("$ncmpBasePathV1/ch/searches") + .contentType(MediaType.APPLICATION_JSON) + .content(cmHandleQueryParameters) + ).andReturn().response + then: 'response status is BAD_REQUEST' + assert response.status == HttpStatus.BAD_REQUEST.value() + where: 'the cmHandleQueryParameters are' + scenario | cmHandleQueryParameters + 'empty string' | "" + 'non-json string' | "this is a test" + } + def 'DMI Registration: All cm-handles operations processed successfully.'() { given: 'a dmi plugin registration' def dmiRegistrationRequest = '{}' -- cgit 1.2.3-korg