summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test
diff options
context:
space:
mode:
authorlukegleeson <luke.gleeson@est.tech>2021-08-30 10:24:30 +0100
committerlukegleeson <luke.gleeson@est.tech>2021-09-03 09:42:02 +0100
commit008abaee59bb542d5a60e89fa7f4231cecf7bdf5 (patch)
tree9e0c3468fc62827cf15841fd0813aa5141299f29 /cps-ri/src/test
parent0af60de4fbb3a3e6c828e179c667b173b1539b62 (diff)
Ensure Leaf value retains Integer type
BUG GSON.fromJson() is unable to parse numerical values and defaults values to Doubles Added a datatype conversion which forces Double values which can be Integers to being Integers Issue-ID: CPS-591 Signed-off-by: lukegleeson <luke.gleeson@est.tech> Change-Id: I72d54ad06823a8755ee407f39104f3edf9a8cc75
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy28
1 files changed, 27 insertions, 1 deletions
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
index 5ed3ae3e8c..9fcd550bd1 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
@@ -19,6 +19,7 @@
package org.onap.cps.spi.impl
import org.hibernate.StaleStateException
+import org.onap.cps.spi.FetchDescendantsOption
import org.onap.cps.spi.entities.FragmentEntity
import org.onap.cps.spi.exceptions.ConcurrencyException
import org.onap.cps.spi.model.DataNodeBuilder
@@ -68,5 +69,30 @@ class CpsDataPersistenceServiceSpec extends Specification {
assert concurrencyException.getDetails().contains(parentXpath)
}
-
+ def 'Retrieving a data node with a property JSON value of #scenario'() {
+ given: 'a fragment with a property JSON value of #scenario'
+ mockFragmentRepository.getByDataspaceAndAnchorAndXpath(_, _, _) >> {
+ new FragmentEntity(childFragments: Collections.emptySet(),
+ attributes: "{\"some attribute\": ${dataString}}")
+ }
+ when: 'getting the data node represented by this fragment'
+ def dataNode = objectUnderTest.getDataNode('my-dataspace', 'my-anchor',
+ 'parent-01', FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS)
+ then: 'the leaf is of the correct value and data type'
+ def attributeValue = dataNode.leaves.get('some attribute')
+ assert attributeValue == expectedValue
+ assert attributeValue.class == expectedDataClass
+ where: 'the following Data Type is passed'
+ scenario | dataString || expectedValue | expectedDataClass
+ 'just numbers' | '15174' || 15174 | Integer
+ 'number with dot' | '15174.32' || 15174.32 | Double
+ 'number with 0 value after dot' | '15174.0' || 15174.0 | Double
+ 'number with 0 value before dot' | '0.32' || 0.32 | Double
+ 'number higher than max int' | '2147483648' || 2147483648 | Long
+ 'just text' | '"Test"' || 'Test' | String
+ 'number with exponent' | '1.2345e5' || 1.2345e5 | Double
+ 'number higher than max int with dot' | '123456789101112.0' || 123456789101112.0 | Double
+ 'text and numbers' | '"String = \'1234\'"' || "String = '1234'" | String
+ 'number as String' | '"12345"' || '12345' | String
+ }
}