-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
293 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/test/kotlin/com/featurevisor/sdk/serializers/ConditionSerializerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
package com.featurevisor.sdk.serializers | ||
|
||
import com.featurevisor.types.Condition | ||
import com.featurevisor.types.ConditionValue | ||
import com.featurevisor.types.Operator | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.types.shouldBeTypeOf | ||
import kotlinx.serialization.decodeFromString | ||
import kotlinx.serialization.json.Json | ||
import org.junit.jupiter.api.Test | ||
|
||
class ConditionSerializerTest { | ||
|
||
@Test | ||
fun `decode PLAIN condition`() { | ||
val element = """ | ||
{ | ||
"attribute": "version", | ||
"operator": "equals", | ||
"value": "1.2.3" | ||
} | ||
""".trimIndent() | ||
|
||
val condition = Json.decodeFromString<Condition>(element) | ||
|
||
condition.shouldBeTypeOf<Condition.Plain>() | ||
condition.attributeKey shouldBe "version" | ||
condition.operator shouldBe Operator.EQUALS | ||
condition.value shouldBe ConditionValue.StringValue("1.2.3") | ||
} | ||
|
||
@Test | ||
fun `decode AND condition`() { | ||
val element = """ | ||
{ | ||
"and": [{ | ||
"attribute": "version", | ||
"operator": "equals", | ||
"value": "1.2.3" | ||
}, { | ||
"attribute": "age", | ||
"operator": "greaterThanOrEqual", | ||
"value": "18" | ||
}] | ||
} | ||
""".trimIndent() | ||
|
||
val condition = Json.decodeFromString<Condition>(element) | ||
|
||
condition.shouldBeTypeOf<Condition.And>() | ||
(condition.and[0] as Condition.Plain).run { | ||
attributeKey shouldBe "version" | ||
operator shouldBe Operator.EQUALS | ||
value shouldBe ConditionValue.StringValue("1.2.3") | ||
} | ||
(condition.and[1] as Condition.Plain).run { | ||
attributeKey shouldBe "age" | ||
operator shouldBe Operator.GREATER_THAN_OR_EQUAL | ||
value shouldBe ConditionValue.IntValue(18) | ||
} | ||
} | ||
|
||
@Test | ||
fun `decode OR condition`() { | ||
val element = """ | ||
{ | ||
"or": [{ | ||
"attribute": "version", | ||
"operator": "equals", | ||
"value": "1.2.3" | ||
}, { | ||
"attribute": "age", | ||
"operator": "greaterThanOrEqual", | ||
"value": "18" | ||
}] | ||
} | ||
""".trimIndent() | ||
|
||
val condition = Json.decodeFromString<Condition>(element) | ||
|
||
condition.shouldBeTypeOf<Condition.Or>() | ||
(condition.or[0] as Condition.Plain).run { | ||
attributeKey shouldBe "version" | ||
operator shouldBe Operator.EQUALS | ||
value shouldBe ConditionValue.StringValue("1.2.3") | ||
} | ||
(condition.or[1] as Condition.Plain).run { | ||
attributeKey shouldBe "age" | ||
operator shouldBe Operator.GREATER_THAN_OR_EQUAL | ||
value shouldBe ConditionValue.IntValue(18) | ||
} | ||
} | ||
|
||
@Test | ||
fun `decode NOT condition`() { | ||
val element = """ | ||
{ | ||
"not": [{ | ||
"attribute": "version", | ||
"operator": "equals", | ||
"value": "1.2.3" | ||
}] | ||
} | ||
""".trimIndent() | ||
|
||
val condition = Json.decodeFromString<Condition>(element) | ||
|
||
condition.shouldBeTypeOf<Condition.Not>() | ||
(condition.not[0] as Condition.Plain).run { | ||
attributeKey shouldBe "version" | ||
operator shouldBe Operator.EQUALS | ||
value shouldBe ConditionValue.StringValue("1.2.3") | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/test/kotlin/com/featurevisor/sdk/serializers/ConditionValueTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.featurevisor.sdk.serializers | ||
|
||
import com.featurevisor.types.ConditionValue | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.types.shouldBeTypeOf | ||
import kotlinx.serialization.json.Json | ||
import org.junit.jupiter.api.Test | ||
import kotlinx.serialization.decodeFromString | ||
|
||
class ConditionValueTest { | ||
|
||
@Test | ||
fun `decode int value with correct type`() { | ||
val element = """ | ||
1 | ||
""".trimIndent() | ||
|
||
val result = Json.decodeFromString<ConditionValue>(element) | ||
|
||
result.shouldBeTypeOf<ConditionValue.IntValue>() | ||
result.value shouldBe 1 | ||
} | ||
|
||
@Test | ||
fun `decode boolean value with correct type`() { | ||
val element = """ | ||
true | ||
""".trimIndent() | ||
|
||
val result = Json.decodeFromString<ConditionValue>(element) | ||
|
||
result.shouldBeTypeOf<ConditionValue.BooleanValue>() | ||
result.value shouldBe true | ||
} | ||
|
||
@Test | ||
fun `decode double value with correct type`() { | ||
val element = """ | ||
1.2 | ||
""".trimIndent() | ||
|
||
val result = Json.decodeFromString<ConditionValue>(element) | ||
|
||
result.shouldBeTypeOf<ConditionValue.DoubleValue>() | ||
result.value shouldBe 1.2 | ||
} | ||
|
||
@Test | ||
fun `decode string value with correct type`() { | ||
val element = """ | ||
test | ||
""".trimIndent() | ||
|
||
val result = Json.decodeFromString<ConditionValue>(element) | ||
|
||
result.shouldBeTypeOf<ConditionValue.StringValue>() | ||
result.value shouldBe "test" | ||
} | ||
|
||
@Test | ||
fun `decode array value with correct type`() { | ||
val element = """ | ||
[ "test1", "test2"] | ||
""".trimIndent() | ||
|
||
val result = Json.decodeFromString<ConditionValue>(element) | ||
|
||
result.shouldBeTypeOf<ConditionValue.ArrayValue>() | ||
result.values[0] shouldBe "test1" | ||
result.values[1] shouldBe "test2" | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
src/test/kotlin/com/featurevisor/sdk/serializers/GroupSegmentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.featurevisor.sdk.serializers | ||
|
||
import com.featurevisor.types.GroupSegment | ||
import io.kotest.matchers.shouldBe | ||
import io.kotest.matchers.types.shouldBeTypeOf | ||
import kotlinx.serialization.decodeFromString | ||
import kotlinx.serialization.json.Json | ||
import org.junit.jupiter.api.Test | ||
|
||
class GroupSegmentTest { | ||
|
||
@Test | ||
fun `decode PLAIN segment`() { | ||
val element = """ | ||
testSegment | ||
""".trimIndent() | ||
|
||
val groupSegment = Json.decodeFromString<GroupSegment>(element) | ||
|
||
groupSegment.shouldBeTypeOf<GroupSegment.Plain>() | ||
groupSegment.segment shouldBe "testSegment" | ||
} | ||
|
||
@Test | ||
fun `decode AND group segment`() { | ||
val element = """ | ||
{ | ||
"and": ["testSegment1", "testSegment2"] | ||
} | ||
""".trimIndent() | ||
|
||
val groupSegment = Json.decodeFromString<GroupSegment>(element) | ||
|
||
groupSegment.shouldBeTypeOf<GroupSegment.And>() | ||
groupSegment.segment.and[0] shouldBe GroupSegment.Plain("testSegment1") | ||
groupSegment.segment.and[1] shouldBe GroupSegment.Plain("testSegment2") | ||
} | ||
|
||
@Test | ||
fun `decode OR group segment`() { | ||
val element = """ | ||
{ | ||
"or": ["testSegment1", "testSegment2"] | ||
} | ||
""".trimIndent() | ||
|
||
val groupSegment = Json.decodeFromString<GroupSegment>(element) | ||
|
||
groupSegment.shouldBeTypeOf<GroupSegment.Or>() | ||
groupSegment.segment.or[0] shouldBe GroupSegment.Plain("testSegment1") | ||
groupSegment.segment.or[1] shouldBe GroupSegment.Plain("testSegment2") | ||
} | ||
|
||
@Test | ||
fun `decode NOT group segment`() { | ||
val element = """ | ||
{ | ||
"not": ["testSegment1", "testSegment2"] | ||
} | ||
""".trimIndent() | ||
|
||
val groupSegment = Json.decodeFromString<GroupSegment>(element) | ||
|
||
groupSegment.shouldBeTypeOf<GroupSegment.Not>() | ||
groupSegment.segment.not[0] shouldBe GroupSegment.Plain("testSegment1") | ||
groupSegment.segment.not[1] shouldBe GroupSegment.Plain("testSegment2") | ||
} | ||
} |