Merge "Query CmHandles using CPS path"
[cps.git] / cps-service / src / test / groovy / org / onap / cps / utils / CmHandleQueryRestParametersValidatorSpec.groovy
index 645829b..d5dcb7f 100644 (file)
 package org.onap.cps.utils
 
 import org.onap.cps.spi.exceptions.DataValidationException
-import org.onap.cps.spi.model.CmHandleQueryParameters
+import org.onap.cps.spi.model.CmHandleQueryServiceParameters
 import org.onap.cps.spi.model.ConditionProperties
 import spock.lang.Specification
 
 class CmHandleQueryRestParametersValidatorSpec extends Specification {
     def 'CM Handle Query validation: empty query.'() {
         given: 'a cm handle query'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
         when: 'validator is invoked'
             CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters(cmHandleQueryParameters)
         then: 'data validation exception is not thrown'
@@ -37,7 +37,7 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification {
 
     def 'CM Handle Query validation: normal query.'() {
         given: 'a cm handle query'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def condition = new ConditionProperties()
             condition.conditionName = 'hasAllProperties'
             condition.conditionParameters = [[key1:'value1'],[key2:'value2']]
@@ -50,7 +50,7 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification {
 
     def 'CM Handle Query validation: #scenario.'() {
         given: 'a cm handle query'
-            def cmHandleQueryParameters = new CmHandleQueryParameters()
+            def cmHandleQueryParameters = new CmHandleQueryServiceParameters()
             def condition = new ConditionProperties()
             condition.conditionName = conditionName
             condition.conditionParameters = conditionParameters
@@ -88,4 +88,29 @@ class CmHandleQueryRestParametersValidatorSpec extends Specification {
             'invalid value' | [moduleName: '']
             'invalid name'  | [wrongName: 'value']
     }
+
+    def 'Validate CmHandle where an exception is thrown due to #scenario.'() {
+        when: 'the validator is called on a cps path condition property'
+            CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties(conditionProperty)
+        then: 'a data validation exception is thrown'
+            def e = thrown(DataValidationException)
+        and: 'exception message matches the expected message'
+            e.details.contains(exceptionMessage)
+        where:
+            scenario                              | conditionProperty                               || exceptionMessage
+            'more than one condition is supplied' | ['cpsPath':'some-path', 'cpsPath2':'some-path'] || 'Only one condition property is allowed for the CPS path query.'
+            'cpsPath key not supplied'            | ['wrong-key':'some-path']                       || 'Wrong CPS path condition property. - expecting "cpsPath" as the condition property.'
+            'cpsPath not supplied'                | ['cpsPath':'']                                  || 'Wrong CPS path. - please supply a valid CPS path.'
+    }
+
+    def 'Validate CmHandle where #scenario.'() {
+        when: 'the validator is called on a cps path condition property'
+            def result = CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties(['cpsPath':cpsPath])
+        then: 'the expected boolean value is returned'
+            result == expectedBoolean
+        where:
+            scenario                                       | cpsPath                                                || expectedBoolean
+            'cpsPath is valid'                             | '/some/valid/path'                                     || true
+            'cpsPath attempts to query private properties' | "//additional-properties[@some-property='some-value']" || false
+    }
 }