@@ -2,6 +2,7 @@ package streams.utils
22
33import org.junit.Test
44import streams.events.Constraint
5+ import streams.events.RelKeyStrategy
56import streams.events.StreamsConstraintType
67import streams.utils.SchemaUtils.getNodeKeys
78import kotlin.test.assertEquals
@@ -47,6 +48,31 @@ class SchemaUtilsTest {
4748 assertEquals(expectedKeys, actualKeys)
4849 }
4950
51+ @Test
52+ fun `getNodeKeys should return all keys when RelKeyStrategy is ALL` () {
53+
54+ val pair1 = " LabelX" to setOf (" foo" , " aaa" )
55+ val pair2 = " LabelB" to setOf (" bar" , " foo" )
56+ val pair3 = " LabelC" to setOf (" baz" , " bar" )
57+ val pair4 = " LabelB" to setOf (" bar" , " bez" )
58+ val pair5 = " LabelA" to setOf (" bar" , " baa" , " xcv" )
59+ val pair6 = " LabelC" to setOf (" aaa" , " baa" , " xcz" )
60+ val pair7 = " LabelA" to setOf (" foo" , " aac" )
61+ val pair8 = " LabelA" to setOf (" foo" , " aab" )
62+ val props = listOf (pair1, pair2, pair3, pair4, pair5, pair6, pair7, pair8)
63+
64+ // we shuffle the constraints to ensure that the result doesn't depend from the ordering
65+ val constraints = props.map {
66+ Constraint (label = it.first, properties = it.second, type = StreamsConstraintType .UNIQUE )
67+ }.shuffled()
68+
69+ val propertyKeys = setOf (" prop" , " prop2" , " foo" , " bar" , " baz" , " bez" , " aaa" , " aab" , " baa" , " aac" , " xcz" , " xcv" )
70+ val actualKeys = getNodeKeys(props.map { it.first }, propertyKeys, constraints, RelKeyStrategy .ALL )
71+ val expectedKeys = setOf (" aaa" , " aab" , " aac" , " baa" , " bar" , " baz" , " bez" , " foo" , " xcv" , " xcz" )
72+
73+ assertEquals(expectedKeys, actualKeys)
74+ }
75+
5076 @Test
5177 fun `getNodeKeys should return the key sorted properly (with one label)` () {
5278 // the method getNodeKeys should select the constraint with lowest properties
@@ -70,6 +96,27 @@ class SchemaUtilsTest {
7096 assertEquals(expectedKeys, actualKeys)
7197 }
7298
99+ @Test
100+ fun `getNodeKeys should return all keys when RelKeyStrategy is ALL (with one label)` () {
101+
102+ val pair1 = " LabelA" to setOf (" foo" , " bar" )
103+ val pair2 = " LabelA" to setOf (" bar" , " foo" )
104+ val pair3 = " LabelA" to setOf (" baz" , " bar" )
105+ val pair4 = " LabelA" to setOf (" bar" , " bez" )
106+ val props = listOf (pair1, pair2, pair3, pair4)
107+
108+ // we shuffle the constraints to ensure that the result doesn't depend from the ordering
109+ val constraints = props.map {
110+ Constraint (label = it.first, properties = it.second, type = StreamsConstraintType .UNIQUE )
111+ }.shuffled()
112+
113+ val propertyKeys = setOf (" prop" , " foo" , " bar" , " baz" , " bez" )
114+ val actualKeys = getNodeKeys(listOf (" LabelA" ), propertyKeys, constraints, RelKeyStrategy .ALL )
115+ val expectedKeys = setOf (" bar" , " baz" , " bez" , " foo" )
116+
117+ assertEquals(expectedKeys, actualKeys)
118+ }
119+
73120 @Test
74121 fun `getNodeKeys should return empty in case it didn't match anything` () {
75122 val props = mapOf (" LabelA" to setOf (" foo" , " bar" ),
0 commit comments