From abee011cb9437bf50e21a559c3d0176d2abbf011 Mon Sep 17 00:00:00 2001 From: leventecsanyi Date: Wed, 19 Oct 2022 11:52:44 +0200 Subject: Improve code coverage - Fixed and refactored unit test to get over the 97% coverage baseline. - Removed unused exception. Issue-ID: CPS-475 Change-Id: I6dbcba58b880a584f6d9346e2aca6c763e5d2081 Signed-off-by: leventecsanyi --- .../CmHandleQueryRestParametersValidatorSpec.groovy | 5 +++++ .../org/onap/cps/utils/JsonObjectMapperSpec.groovy | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'cps-service/src/test/groovy/org') diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy index d5dcb7fc5..c40ffa9a3 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/CmHandleQueryRestParametersValidatorSpec.groovy @@ -103,6 +103,11 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification { 'cpsPath not supplied' | ['cpsPath':''] || 'Wrong CPS path. - please supply a valid CPS path.' } + def 'No conditions.'() { + expect: 'no conditions always returns true' + CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties([:]) == true + } + def 'Validate CmHandle where #scenario.'() { when: 'the validator is called on a cps path condition property' def result = CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties(['cpsPath':cpsPath]) diff --git a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy index 461014418..e205a19ee 100644 --- a/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/utils/JsonObjectMapperSpec.groovy @@ -20,7 +20,7 @@ package org.onap.cps.utils - +import com.fasterxml.jackson.core.JsonProcessingException import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.SerializationFeature import groovy.json.JsonSlurper @@ -44,6 +44,19 @@ class JsonObjectMapperSpec extends Specification { assert contentMap.'test:bookstore'.'bookstore-name' == 'Chapters' } + def 'Map a structured object to json String error.'() { + given: 'some object' + def object = new Object() + and: 'the Object mapper throws an exception' + spiedObjectMapper.writeValueAsString(object) >> { throw new JsonProcessingException('Sample problem'){} } + when: 'attempting to convert the object to a string' + jsonObjectMapper.asJsonString(object); + then: 'a Data Validation Exception is thrown' + def thrown = thrown(DataValidationException) + and: 'the details containing the original error message' + assert thrown.details == 'Sample problem' + } + def 'Map a structurally compatible object to class object of specific class type T.'() { given: 'a map object model' def contentMap = new JsonSlurper().parseText(TestUtils.getResourceFileContent('bookstore.json')) @@ -61,7 +74,7 @@ class JsonObjectMapperSpec extends Specification { given: 'Unstructured json string' def content = '{ "nest": { "birds": "bird"] } }' when: 'mapping json string to given class type' - def contentMap = jsonObjectMapper.convertJsonString(content, Map); + jsonObjectMapper.convertJsonString(content, Map); then: 'an exception is thrown' thrown(DataValidationException) } -- cgit 1.2.3-korg