From dbc11b045bf1da0ee81be9c1b46ebac2fd2b26ce Mon Sep 17 00:00:00 2001 From: Enrico Date: Thu, 14 Dec 2023 14:05:31 +0100 Subject: [PATCH] Move tests to common --- build.gradle.kts | 6 +- .../org/hisp/dhis/rules/ConstantsValueTest.kt | 0 .../dhis/rules/ProgramRuleVariableTest.kt | 51 ++--- .../dhis/rules/RuleEngineEffectTypesTest.kt | 0 .../hisp/dhis/rules/RuleEngineFunctionTest.kt | 2 +- .../rules/RuleEngineGetDescriptionTest.kt | 64 +++--- .../org/hisp/dhis/rules/RuleEngineTest.kt | 9 +- .../hisp/dhis/rules/RuleEngineTestUtils.kt | 0 .../dhis/rules/RuleEngineValueTypesTest.kt | 0 .../dhis/rules/RuleEngineVariableNameTest.kt | 40 ++-- .../dhis/rules/RuleVariableValueAssert.kt | 10 +- .../hisp/dhis/rules/RuleVariableValueTest.kt | 0 .../hisp/dhis/rules/VariableValueTypeTest.kt | 0 .../dhis/rules/models/CalculatedValueTest.kt | 40 ++-- .../dhis/rules/models/RuleDataValueTest.kt | 2 +- .../dhis/rules/models/RuleEnrollmentTest.kt | 15 +- .../hisp/dhis/rules/models/RuleEventTest.kt | 6 +- .../org/hisp/dhis/rules/models/RuleTest.kt | 3 +- .../rules/models/RuleVariableAttributeTest.kt | 2 +- .../models/RuleVariableCurrentEventTest.kt | 0 .../models/RuleVariableNewestEventTest.kt | 0 .../RuleVariableNewestStageEventTest.kt | 0 .../models/RuleVariablePreviousEventTest.kt | 0 .../RuleVariableValueMapBuilderTest.kt | 207 +++++++++--------- 24 files changed, 228 insertions(+), 229 deletions(-) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/ConstantsValueTest.kt (100%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt (78%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt (100%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt (99%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt (85%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt (78%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/RuleEngineTestUtils.kt (100%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/RuleEngineValueTypesTest.kt (100%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt (93%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/RuleVariableValueAssert.kt (66%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/RuleVariableValueTest.kt (100%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/VariableValueTypeTest.kt (100%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt (82%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/RuleDataValueTest.kt (90%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt (63%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt (89%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/RuleTest.kt (83%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/RuleVariableAttributeTest.kt (80%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/RuleVariableCurrentEventTest.kt (100%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestEventTest.kt (100%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestStageEventTest.kt (100%) rename src/{jvmTest => commonTest}/kotlin/org/hisp/dhis/rules/models/RuleVariablePreviousEventTest.kt (100%) rename src/{jvmTest/kotlin/org/hisp/dhis/rules => commonTest/kotlin/org/hisp/dhis/rules/models}/RuleVariableValueMapBuilderTest.kt (77%) diff --git a/build.gradle.kts b/build.gradle.kts index ac4645ef..63d1aeef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -59,11 +59,7 @@ kotlin { } } val jvmMain by getting - val jvmTest by getting { - dependencies { - implementation("io.mockk:mockk:1.13.8") - } - } + val jvmTest by getting val jsMain by getting val jsTest by getting val nativeMain by getting diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/ConstantsValueTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/ConstantsValueTest.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/ConstantsValueTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/ConstantsValueTest.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt similarity index 78% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt index e5e1e685..13b2e5fe 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/ProgramRuleVariableTest.kt @@ -37,7 +37,7 @@ class ProgramRuleVariableTest { fun testCurrentDateProgramVariableIsAssigned() { val rule = getRule("V{current_date}") val ruleEffects = callEnrollmentRuleEngine(rule) - assertProgramRuleVariableAssignment(ruleEffects, rule, org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.CURRENT_DATE.toString()) + assertProgramRuleVariableAssignment(ruleEffects, rule, CURRENT_DATE.toString()) } @Test @@ -45,7 +45,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{due_date}") val ruleEffects = callEventRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.DUE_DATE_STRING + DUE_DATE_STRING ) } @@ -61,7 +61,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{enrollment_date}") val ruleEffects = callEnrollmentRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ENROLLMENT_DATE_STRING + ENROLLMENT_DATE_STRING ) } @@ -70,7 +70,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{enrollment_id}") val ruleEffects = callEnrollmentRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ENROLLMENT_ID + ENROLLMENT_ID ) } @@ -78,7 +78,7 @@ class ProgramRuleVariableTest { fun testEnrollmentStatusProgramVariableIsAssigned() { val rule = getRule("V{enrollment_status}") val ruleEffects = callEnrollmentRuleEngine(rule) - assertProgramRuleVariableAssignment(ruleEffects, rule, org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ENROLLMENT_STATUS.name) + assertProgramRuleVariableAssignment(ruleEffects, rule, ENROLLMENT_STATUS.name) } @Test @@ -100,7 +100,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{event_date}") val ruleEffects = callEventRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.EVENT_DATE_STRING + EVENT_DATE_STRING ) } @@ -109,7 +109,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{event_id}") val ruleEffects = callEventRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.EVENT_ID + EVENT_ID ) } @@ -117,7 +117,7 @@ class ProgramRuleVariableTest { fun testEventStatusProgramVariableIsAssigned() { val rule = getRule("V{event_status}") val ruleEffects = callEventRuleEngine(rule) - assertProgramRuleVariableAssignment(ruleEffects, rule, org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.RULE_EVENT_STATUS.name) + assertProgramRuleVariableAssignment(ruleEffects, rule, RULE_EVENT_STATUS.name) } @Test @@ -125,7 +125,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{incident_date}") val ruleEffects = callEventRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.INCIDENT_DATE_STRING + INCIDENT_DATE_STRING ) } @@ -134,7 +134,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{org_unit}") val ruleEffects = callEnrollmentRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ORGANISATION_UNIT + ORGANISATION_UNIT ) } @@ -143,7 +143,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{orgunit_code}") val ruleEffects = callEventRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ORGANISATION_UNIT_CODE + ORGANISATION_UNIT_CODE ) } @@ -152,7 +152,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{program_name}") val ruleEffects = callEnrollmentRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.PROGRAM_NAME + PROGRAM_NAME ) } @@ -161,7 +161,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{program_stage_id}") val ruleEffects = callEventRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.PROGRAM_STAGE + PROGRAM_STAGE ) } @@ -170,7 +170,7 @@ class ProgramRuleVariableTest { val rule = getRule("V{program_stage_name}") val ruleEffects = callEventRuleEngine(rule) assertProgramRuleVariableAssignment(ruleEffects, rule, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.PROGRAM_STAGE_NAME + PROGRAM_STAGE_NAME ) } @@ -216,31 +216,32 @@ class ProgramRuleVariableTest { private val enrollment: org.hisp.dhis.rules.models.RuleEnrollment get() = org.hisp.dhis.rules.models.RuleEnrollment( - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ENROLLMENT_ID, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.PROGRAM_NAME, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.INCIDENT_DATE, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ENROLLMENT_DATE, + ENROLLMENT_ID, + PROGRAM_NAME, + INCIDENT_DATE, + ENROLLMENT_DATE, org.hisp.dhis.rules.models.RuleEnrollment.Status.ACTIVE, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ORGANISATION_UNIT, - org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ORGANISATION_UNIT_CODE, + ORGANISATION_UNIT, + ORGANISATION_UNIT_CODE, listOf(org.hisp.dhis.rules.models.RuleAttributeValue("test_attribute", "test_value")) ) private fun getRuleEngine(rules: List): RuleEngine { - return RuleEngine(RuleEngineContext(rules, listOf(), emptyMap(), emptyMap()), + return RuleEngine( + RuleEngineContext(rules, listOf(), emptyMap(), emptyMap()), emptyList(), null, TriggerEnvironment.SERVER) } companion object { private val CURRENT_DATE = LocalDate.Companion.currentDate() private const val DUE_DATE_STRING = "2020-06-01" - private val DUE_DATE = LocalDate.parse(org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.DUE_DATE_STRING) + private val DUE_DATE = LocalDate.parse(DUE_DATE_STRING) private const val ENROLLMENT_DATE_STRING = "2019-01-01" - private val ENROLLMENT_DATE = LocalDate.parse(org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.ENROLLMENT_DATE_STRING) + private val ENROLLMENT_DATE = LocalDate.parse(ENROLLMENT_DATE_STRING) private const val EVENT_DATE_STRING = "2019-02-02" - private val EVENT_DATE = LocalDate.parse(org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.EVENT_DATE_STRING) + private val EVENT_DATE = LocalDate.parse(EVENT_DATE_STRING) private const val INCIDENT_DATE_STRING = "2020-01-01" - private val INCIDENT_DATE = LocalDate.parse(org.hisp.dhis.rules.ProgramRuleVariableTest.Companion.INCIDENT_DATE_STRING) + private val INCIDENT_DATE = LocalDate.parse(INCIDENT_DATE_STRING) private const val PROGRAM_STAGE = "program stage" private const val PROGRAM_STAGE_NAME = "program stage name" private val RULE_EVENT_STATUS = RuleEvent.Status.ACTIVE diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineEffectTypesTest.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt similarity index 99% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt index 65d9bca5..3645b066 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineFunctionTest.kt @@ -2628,6 +2628,6 @@ class RuleEngineFunctionTest { companion object { private const val DATE_PATTERN = "yyyy-MM-dd" private const val USE_CODE_FOR_OPTION_SET = true - private const val USE_NAME_FOR_OPTION_SET = !org.hisp.dhis.rules.RuleEngineFunctionTest.Companion.USE_CODE_FOR_OPTION_SET + private const val USE_NAME_FOR_OPTION_SET = !USE_CODE_FOR_OPTION_SET } } diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt similarity index 85% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt index 01a20a9c..2b6a86ea 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineGetDescriptionTest.kt @@ -34,47 +34,47 @@ import kotlin.test.* * @author Zubair Asghar */ class RuleEngineGetDescriptionTest { - private var itemStore: MutableMap = HashMap() + private var itemStore: MutableMap = HashMap() private val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, "", "") @BeforeTest fun setUp() { itemStore = HashMap() - val var_1 = org.hisp.dhis.rules.DataItem( - org.hisp.dhis.rules.RuleEngineGetDescriptionTest.Companion.test_var_one, - org.hisp.dhis.rules.ItemValueType.TEXT + val var_1 = DataItem( + test_var_one, + ItemValueType.TEXT ) - val var_2 = org.hisp.dhis.rules.DataItem( - org.hisp.dhis.rules.RuleEngineGetDescriptionTest.Companion.test_var_two, - org.hisp.dhis.rules.ItemValueType.TEXT + val var_2 = DataItem( + test_var_two, + ItemValueType.TEXT ) - val var_8 = org.hisp.dhis.rules.DataItem( - org.hisp.dhis.rules.RuleEngineGetDescriptionTest.Companion.test_var_three, - org.hisp.dhis.rules.ItemValueType.TEXT + val var_8 = DataItem( + test_var_three, + ItemValueType.TEXT ) - val var_3 = org.hisp.dhis.rules.DataItem( - org.hisp.dhis.rules.RuleEngineGetDescriptionTest.Companion.test_var_date_one, - org.hisp.dhis.rules.ItemValueType.DATE + val var_3 = DataItem( + test_var_date_one, + ItemValueType.DATE ) - val var_4 = org.hisp.dhis.rules.DataItem( - org.hisp.dhis.rules.RuleEngineGetDescriptionTest.Companion.test_var_date_two, - org.hisp.dhis.rules.ItemValueType.DATE + val var_4 = DataItem( + test_var_date_two, + ItemValueType.DATE ) - val var_5 = org.hisp.dhis.rules.DataItem( - org.hisp.dhis.rules.RuleEngineGetDescriptionTest.Companion.completionDate, - org.hisp.dhis.rules.ItemValueType.DATE + val var_5 = DataItem( + completionDate, + ItemValueType.DATE ) - val var_6 = org.hisp.dhis.rules.DataItem( - org.hisp.dhis.rules.RuleEngineGetDescriptionTest.Companion.constant, - org.hisp.dhis.rules.ItemValueType.TEXT + val var_6 = DataItem( + constant, + ItemValueType.TEXT ) - val var_7 = org.hisp.dhis.rules.DataItem( - org.hisp.dhis.rules.RuleEngineGetDescriptionTest.Companion.currentDate, - org.hisp.dhis.rules.ItemValueType.DATE + val var_7 = DataItem( + currentDate, + ItemValueType.DATE ) - val var_9 = org.hisp.dhis.rules.DataItem( - org.hisp.dhis.rules.RuleEngineGetDescriptionTest.Companion.test_var_number, - org.hisp.dhis.rules.ItemValueType.NUMBER + val var_9 = DataItem( + test_var_number, + ItemValueType.NUMBER ) itemStore["test_var_one"] = var_1 itemStore["test_var_two"] = var_2 @@ -293,9 +293,11 @@ class RuleEngineGetDescriptionTest { assertTrue(result.exception is org.hisp.dhis.rules.models.RuleEngineValidationException) } - private fun getRuleEngineForDescription(itemStore: Map): RuleEngine { - return RuleEngine(RuleEngineContext(emptyList(), emptyList(), emptyMap(), - emptyMap(), RuleEngineIntent.DESCRIPTION, itemStore)) + private fun getRuleEngineForDescription(itemStore: Map): RuleEngine { + return RuleEngine( + RuleEngineContext(emptyList(), emptyList(), emptyMap(), + emptyMap(), RuleEngineIntent.DESCRIPTION, itemStore) + ) } companion object { diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt similarity index 78% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt index d57507e2..5e3e1cf9 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineTest.kt @@ -1,18 +1,17 @@ package org.hisp.dhis.rules -import io.mockk.mockk import kotlinx.datetime.LocalDate import org.hisp.dhis.rules.models.Rule import org.hisp.dhis.rules.models.RuleEvent -import org.hisp.dhis.rules.models.RuleVariable import kotlin.test.Test +import kotlin.test.assertFailsWith internal class RuleEngineTest { private val ruleEngineContext: RuleEngineContext = RuleEngineContext( - listOf(Rule("true", listOf())),listOf(mockk())) + listOf(Rule("true", listOf())),listOf()) - @Test(expected = IllegalStateException::class) + @Test fun evaluateShouldThrowIfEventIsAlreadyInContext() { val ruleEvent = RuleEvent( "test_event", @@ -29,6 +28,6 @@ internal class RuleEngineTest { val ruleEvents: MutableList = ArrayList() ruleEvents.add(ruleEvent) val ruleEngine = RuleEngine(ruleEngineContext, ruleEvents) - ruleEngine.evaluate(ruleEvent) + assertFailsWith(IllegalStateException::class) { ruleEngine.evaluate(ruleEvent) } } } diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineTestUtils.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineTestUtils.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineTestUtils.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineTestUtils.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineValueTypesTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineValueTypesTest.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineValueTypesTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineValueTypesTest.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt similarity index 93% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt index aa2f05dd..c88ca867 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleEngineVariableNameTest.kt @@ -10,43 +10,43 @@ class RuleEngineVariableNameTest { fun evaluateD2Round() { val ruleAction1: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID01 + "})" + "test_action_content", "d2:round(#{" + UID01 + "})" ) val ruleAction2: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.VARIABLE_NAME + "})" + "test_action_content", "d2:round(#{" + VARIABLE_NAME + "})" ) val ruleAction3: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID0 + "})" + "test_action_content", "d2:round(#{" + UID0 + "})" ) val ruleAction4: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID0WILD + "})" + "test_action_content", "d2:round(#{" + UID0WILD + "})" ) val ruleAction5: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID01WILD + "})" + "test_action_content", "d2:round(#{" + UID01WILD + "})" ) val ruleAction6: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID012 + "})" + "test_action_content", "d2:round(#{" + UID012 + "})" ) val ruleAction7: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID0WILD2 + "})" + "test_action_content", "d2:round(#{" + UID0WILD2 + "})" ) val ruleAction8: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(A{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID0 + "})" + "test_action_content", "d2:round(A{" + UID0 + "})" ) val ruleAction9: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(A{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID01 + "})" + "test_action_content", "d2:round(A{" + UID01 + "})" ) val ruleAction10: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:round(A{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.VARIABLE_NAME + "})" + "test_action_content", "d2:round(A{" + VARIABLE_NAME + "})" ) val ruleVariable1: RuleVariable = RuleVariableNewestEvent( UID01, true, ArrayList(), "test_data_element1", RuleValueType.NUMERIC @@ -186,7 +186,7 @@ class RuleEngineVariableNameTest { fun evaluateHasValueFunctionMustReturnTrueIfVariableIsComposedUIDs() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:hasValue(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID01 + "})" + "test_action_content", "d2:hasValue(#{" + UID01 + "})" ) val ruleVariable: RuleVariable = RuleVariableCurrentEvent( UID01, true, ArrayList(), "test_data_element", RuleValueType.TEXT @@ -219,7 +219,7 @@ class RuleEngineVariableNameTest { fun evaluateHasValueFunctionMustReturnTrueIfVariableIsVariableName() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:hasValue(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.VARIABLE_NAME + "})" + "test_action_content", "d2:hasValue(#{" + VARIABLE_NAME + "})" ) val ruleVariable: RuleVariable = RuleVariableCurrentEvent( VARIABLE_NAME, true, ArrayList(), "test_data_element", RuleValueType.TEXT @@ -252,7 +252,7 @@ class RuleEngineVariableNameTest { fun evaluateD2CountIfValueIsVariableName() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:countIfValue(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.VARIABLE_NAME + "}, 'condition')" + "test_action_content", "d2:countIfValue(#{" + VARIABLE_NAME + "}, 'condition')" ) val ruleVariableOne: RuleVariable = RuleVariableNewestEvent( VARIABLE_NAME, true, ArrayList(), "test_data_element_one", RuleValueType.TEXT @@ -326,7 +326,7 @@ class RuleEngineVariableNameTest { fun evaluateD2CountIfValueIsComposedUid() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:countIfValue(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID01 + "}, 'condition')" + "test_action_content", "d2:countIfValue(#{" + UID01 + "}, 'condition')" ) val ruleVariableOne: RuleVariable = RuleVariableNewestEvent( UID01, true, ArrayList(), "test_data_element_one", RuleValueType.TEXT @@ -400,7 +400,7 @@ class RuleEngineVariableNameTest { fun evaluateD2CountIfVariableName() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:count(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.VARIABLE_NAME + "})" + "test_action_content", "d2:count(#{" + VARIABLE_NAME + "})" ) val ruleVariableOne: RuleVariable = RuleVariableNewestEvent( VARIABLE_NAME, true, ArrayList(), "test_data_element_one", RuleValueType.TEXT @@ -496,7 +496,7 @@ class RuleEngineVariableNameTest { fun evaluateD2CountIfVariableNameIfComposedUid() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:count(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID01 + "})" + "test_action_content", "d2:count(#{" + UID01 + "})" ) val ruleVariableOne: RuleVariable = RuleVariableNewestEvent( UID01, true, ArrayList(), "test_data_element_one", RuleValueType.TEXT @@ -589,7 +589,7 @@ class RuleEngineVariableNameTest { fun evaluateD2CountIfZeroPosIfVariableName() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:countIfZeroPos(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.VARIABLE_NAME + "})" + "test_action_content", "d2:countIfZeroPos(#{" + VARIABLE_NAME + "})" ) val ruleVariableOne: RuleVariable = RuleVariableNewestEvent( VARIABLE_NAME, true, ArrayList(), "test_data_element_one", RuleValueType.NUMERIC @@ -664,7 +664,7 @@ class RuleEngineVariableNameTest { fun evaluateD2CountIfZeroPosIfComposedUid() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:countIfZeroPos(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID01 + "})" + "test_action_content", "d2:countIfZeroPos(#{" + UID01 + "})" ) val ruleVariableOne: RuleVariable = RuleVariableNewestEvent( UID01, true, ArrayList(), "test_data_element_one", RuleValueType.NUMERIC @@ -945,7 +945,7 @@ class RuleEngineVariableNameTest { fun testMinValueIfVariableName() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:minValue(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.VARIABLE_NAME + "})" + "test_action_content", "d2:minValue(#{" + VARIABLE_NAME + "})" ) val ruleVariableOne: RuleVariable = RuleVariableNewestEvent( VARIABLE_NAME, true, ArrayList(), "test_data_element_one", RuleValueType.NUMERIC @@ -1044,7 +1044,7 @@ class RuleEngineVariableNameTest { fun testMinValueIfComposedUid() { val ruleAction: org.hisp.dhis.rules.models.RuleAction = RuleActionText.createForFeedback( RuleActionText.Type.DISPLAYTEXT, - "test_action_content", "d2:minValue(#{" + org.hisp.dhis.rules.RuleEngineVariableNameTest.Companion.UID01 + "})" + "test_action_content", "d2:minValue(#{" + UID01 + "})" ) val ruleVariableOne: RuleVariable = RuleVariableNewestEvent( UID01, true, ArrayList(), "test_data_element_one", RuleValueType.NUMERIC diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleVariableValueAssert.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleVariableValueAssert.kt similarity index 66% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleVariableValueAssert.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/RuleVariableValueAssert.kt index b4cec679..a1103f38 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleVariableValueAssert.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleVariableValueAssert.kt @@ -3,12 +3,12 @@ package org.hisp.dhis.rules import kotlin.test.assertEquals internal class RuleVariableValueAssert private constructor(private val variableValue: RuleVariableValue) { - fun hasValue(value: String?): org.hisp.dhis.rules.RuleVariableValueAssert { + fun hasValue(value: String?): RuleVariableValueAssert { assertEquals(value, variableValue.value) return this } - fun hasCandidates(vararg candidates: String?): org.hisp.dhis.rules.RuleVariableValueAssert { + fun hasCandidates(vararg candidates: String?): RuleVariableValueAssert { assertEquals(candidates.size, variableValue.candidates.size) for (index in candidates.indices) { assertEquals(candidates[index], variableValue.candidates.get(index)) @@ -16,14 +16,14 @@ internal class RuleVariableValueAssert private constructor(private val variableV return this } - fun isTypeOf( valueType: org.hisp.dhis.rules.models.RuleValueType?): org.hisp.dhis.rules.RuleVariableValueAssert { + fun isTypeOf( valueType: org.hisp.dhis.rules.models.RuleValueType?): RuleVariableValueAssert { assertEquals(valueType, variableValue.type) return this } companion object { - fun assertThatVariable(variableValue: RuleVariableValue): org.hisp.dhis.rules.RuleVariableValueAssert { - return org.hisp.dhis.rules.RuleVariableValueAssert(variableValue) + fun assertThatVariable(variableValue: RuleVariableValue): RuleVariableValueAssert { + return RuleVariableValueAssert(variableValue) } } } diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleVariableValueTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/RuleVariableValueTest.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleVariableValueTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/RuleVariableValueTest.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/VariableValueTypeTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/VariableValueTypeTest.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/VariableValueTypeTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/VariableValueTypeTest.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt similarity index 82% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt index 53c7f892..4645d268 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/CalculatedValueTest.kt @@ -36,15 +36,15 @@ import kotlin.test.assertEquals */ class CalculatedValueTest { @Test - fun evaluateTenThousandRulesTest() { - val i = 10000 + fun evaluateOneThousandRulesTest() { + val i = 1000 val ruleEngine = getRuleEngine(createRules(i)) - val enrollment = org.hisp.dhis.rules.models.RuleEnrollment( + val enrollment = RuleEnrollment( "test_enrollment", "test_program", - LocalDate.Companion.currentDate(), - LocalDate.Companion.currentDate(), - org.hisp.dhis.rules.models.RuleEnrollment.Status.ACTIVE, + LocalDate.currentDate(), + LocalDate.currentDate(), + RuleEnrollment.Status.ACTIVE, "test_ou", "test_ou_code", listOf() @@ -71,21 +71,21 @@ class CalculatedValueTest { @Test fun sendMessageMustGetValueFromAssignAction() { - val assignAction: org.hisp.dhis.rules.models.RuleAction = RuleActionAssign.create("#{test_calculated_value}", "2+2", null) + val assignAction: RuleAction = RuleActionAssign.create("#{test_calculated_value}", "2+2", null) val rule = Rule("true", listOf(assignAction), "test_program_rule1") - val sendMessageAction: org.hisp.dhis.rules.models.RuleAction = + val sendMessageAction: RuleAction = RuleActionSendMessage("test_notification", "4") val rule2 = Rule( "#{test_calculated_value}==4", listOf(sendMessageAction), "test_program_rule2" ) - val enrollment = org.hisp.dhis.rules.models.RuleEnrollment( + val enrollment = RuleEnrollment( "test_enrollment", "test_program", - LocalDate.Companion.currentDate(), - LocalDate.Companion.currentDate(), - org.hisp.dhis.rules.models.RuleEnrollment.Status.ACTIVE, + LocalDate.currentDate(), + LocalDate.currentDate(), + RuleEnrollment.Status.ACTIVE, "test_ou", "test_ou_code", listOf() @@ -114,9 +114,9 @@ class CalculatedValueTest { private fun createRules(i: Int): List { val rules: MutableList = ArrayList() - val assignAction: org.hisp.dhis.rules.models.RuleAction = RuleActionAssign.create("#{test_calculated_value}", "2+2", null) + val assignAction: RuleAction = RuleActionAssign.create("#{test_calculated_value}", "2+2", null) val rule = Rule("true", listOf(assignAction), "test_program_rule1") - val sendMessageAction: org.hisp.dhis.rules.models.RuleAction = + val sendMessageAction: RuleAction = RuleActionSendMessage("test_notification", "4") val rule2 = Rule( "#{test_calculated_value}==4", @@ -132,21 +132,21 @@ class CalculatedValueTest { @Test fun sendMessageMustGetValueFromAssignActionInSingleExecution() { - val assignAction: org.hisp.dhis.rules.models.RuleAction = RuleActionAssign.create("#{test_calculated_value}", "2+2", null) + val assignAction: RuleAction = RuleActionAssign.create("#{test_calculated_value}", "2+2", null) val rule = Rule("true", listOf(assignAction), "test_program_rule1", "") - val sendMessageAction: org.hisp.dhis.rules.models.RuleAction = + val sendMessageAction: RuleAction = RuleActionSendMessage("test_notification", "4.0") val rule2 = Rule( "#{test_calculated_value}==4.0", listOf(sendMessageAction), "test_program_rule2", "" ) val ruleEngine = getRuleEngine(listOf(rule, rule2)) - val enrollment = org.hisp.dhis.rules.models.RuleEnrollment( + val enrollment = RuleEnrollment( "test_enrollment", "test_program", - LocalDate.Companion.currentDate(), - LocalDate.Companion.currentDate(), - org.hisp.dhis.rules.models.RuleEnrollment.Status.ACTIVE, + LocalDate.currentDate(), + LocalDate.currentDate(), + RuleEnrollment.Status.ACTIVE, "test_ou", "test_ou_code", listOf() diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleDataValueTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleDataValueTest.kt similarity index 90% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleDataValueTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleDataValueTest.kt index 2ec2bee5..f902925e 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleDataValueTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleDataValueTest.kt @@ -9,7 +9,7 @@ class RuleDataValueTest { @Test fun createShouldPropagateValuesCorrectly() { val eventDate = LocalDate.Companion.currentDate() - val ruleDataValue = org.hisp.dhis.rules.models.RuleDataValue( + val ruleDataValue = RuleDataValue( eventDate, "test_program_stage_uid", "test_dataelement", "test_value" ) diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt similarity index 63% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt index 8bb5f3d7..93856569 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEnrollmentTest.kt @@ -1,6 +1,5 @@ package org.hisp.dhis.rules.models -import io.mockk.mockk import kotlinx.datetime.LocalDate import org.hisp.dhis.rules.currentDate import kotlin.test.Test @@ -9,23 +8,23 @@ import kotlin.test.assertEquals class RuleEnrollmentTest { @Test fun createShouldPropagatePropertiesCorrectly() { - val ruleAttributeValueOne = mockk() - val ruleAttributeValueTwo = mockk() - val ruleAttributeValueThree = mockk() + val ruleAttributeValueOne = RuleAttributeValue("attr1", "value1") + val ruleAttributeValueTwo = RuleAttributeValue("attr2", "value2") + val ruleAttributeValueThree = RuleAttributeValue("attr3", "value3") val incidentDate = LocalDate.Companion.currentDate() val enrollmentDate = LocalDate.Companion.currentDate() - val ruleEnrollment = org.hisp.dhis.rules.models.RuleEnrollment( + val ruleEnrollment = RuleEnrollment( "test_enrollment", "", - incidentDate, enrollmentDate, org.hisp.dhis.rules.models.RuleEnrollment.Status.ACTIVE, "", "", + incidentDate, enrollmentDate, RuleEnrollment.Status.ACTIVE, "", "", listOf(ruleAttributeValueOne, ruleAttributeValueTwo, ruleAttributeValueThree) ) assertEquals("test_enrollment", ruleEnrollment.enrollment) assertEquals(incidentDate, ruleEnrollment.incidentDate) assertEquals(enrollmentDate, ruleEnrollment.enrollmentDate) - assertEquals(org.hisp.dhis.rules.models.RuleEnrollment.Status.ACTIVE, ruleEnrollment.status) + assertEquals(RuleEnrollment.Status.ACTIVE, ruleEnrollment.status) assertEquals(3, ruleEnrollment.attributeValues.size) assertEquals(ruleAttributeValueOne, ruleEnrollment.attributeValues[0]) assertEquals(ruleAttributeValueTwo, ruleEnrollment.attributeValues[1]) assertEquals(ruleAttributeValueThree, ruleEnrollment.attributeValues[2]) } -} +} \ No newline at end of file diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt similarity index 89% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt index 0cd0ddc3..d4ed2850 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleEventTest.kt @@ -1,17 +1,15 @@ package org.hisp.dhis.rules.models -import io.mockk.mockk import kotlinx.datetime.LocalDate import org.hisp.dhis.rules.currentDate -import kotlin.collections.ArrayList import kotlin.test.Test import kotlin.test.assertEquals class RuleEventTest { @Test fun createShouldPropagateValuesCorrectly() { - val ruleDataValue = mockk() - val ruleDataValues: MutableList = ArrayList() + val ruleDataValue = RuleDataValue(LocalDate.currentDate(), "programStage", "dataElement", "value") + val ruleDataValues: MutableList = ArrayList() ruleDataValues.add(ruleDataValue) val eventDate = LocalDate.Companion.currentDate() val dueDate = LocalDate.Companion.currentDate() diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleTest.kt similarity index 83% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleTest.kt index aa3a302b..74c15100 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleTest.kt @@ -1,13 +1,12 @@ package org.hisp.dhis.rules.models -import io.mockk.mockk import kotlin.test.Test import kotlin.test.assertEquals class RuleTest { @Test fun createShouldPropagatePropertiesCorrectly() { - val ruleAction: org.hisp.dhis.rules.models.RuleAction = mockk() + val ruleAction: RuleAction = RuleActionError("data") val (condition, actions, uid, _, programStage, priority) = Rule( "test_condition", listOf(ruleAction), diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariableAttributeTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableAttributeTest.kt similarity index 80% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariableAttributeTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableAttributeTest.kt index 6c9da74b..bf0102e6 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariableAttributeTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableAttributeTest.kt @@ -11,6 +11,6 @@ class RuleVariableAttributeTest { ) assertEquals("test_variable", ruleVariableAttribute.name) assertEquals("test_attribute", ruleVariableAttribute.trackedEntityAttribute) - assertEquals(org.hisp.dhis.rules.models.RuleValueType.NUMERIC, ruleVariableAttribute.trackedEntityAttributeType) + assertEquals(RuleValueType.NUMERIC, ruleVariableAttribute.trackedEntityAttributeType) } } diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariableCurrentEventTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableCurrentEventTest.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariableCurrentEventTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableCurrentEventTest.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestEventTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestEventTest.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestEventTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestEventTest.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestStageEventTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestStageEventTest.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestStageEventTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableNewestStageEventTest.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariablePreviousEventTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariablePreviousEventTest.kt similarity index 100% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/models/RuleVariablePreviousEventTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariablePreviousEventTest.kt diff --git a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleVariableValueMapBuilderTest.kt b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt similarity index 77% rename from src/jvmTest/kotlin/org/hisp/dhis/rules/RuleVariableValueMapBuilderTest.kt rename to src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt index 852d2f83..26b38fd1 100644 --- a/src/jvmTest/kotlin/org/hisp/dhis/rules/RuleVariableValueMapBuilderTest.kt +++ b/src/commonTest/kotlin/org/hisp/dhis/rules/models/RuleVariableValueMapBuilderTest.kt @@ -1,12 +1,14 @@ -package org.hisp.dhis.rules +package org.hisp.dhis.rules.models import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.LocalDate import kotlinx.datetime.minus -import org.hisp.dhis.rules.models.* -import kotlin.collections.ArrayList +import org.hisp.dhis.rules.RuleVariableValueAssert +import org.hisp.dhis.rules.RuleVariableValueMapBuilder +import org.hisp.dhis.rules.currentDate import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFailsWith import kotlin.test.assertNull class RuleVariableValueMapBuilderTest { @@ -52,7 +54,7 @@ class RuleVariableValueMapBuilderTest { .ruleEvents( listOf(contextEventOne)) .triggerEnvironment(TriggerEnvironment.SERVER) .build() - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue(null) + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue(null) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT) } @@ -130,30 +132,30 @@ class RuleVariableValueMapBuilderTest { .triggerEnvironment(TriggerEnvironment.SERVER) .build() assertEquals(valueMap.size.toLong(), 13) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( LocalDate.Companion.currentDate().toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(LocalDate.Companion.currentDate().toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!).hasValue( eventDate.toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(eventDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_status"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["event_status"]!!) .hasValue(RuleEvent.Status.ACTIVE.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(RuleEvent.Status.ACTIVE.toString()) // event count variable should respect current event - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("3") + RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("3") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("3") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid") + RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_event_uid") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!).hasValue( dueDate.toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(dueDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue("test_value_one") + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue("test_value_one") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_value_one") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!).hasValue("test_value_two") + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!).hasValue("test_value_two") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_value_two") } @@ -238,24 +240,24 @@ class RuleVariableValueMapBuilderTest { .triggerEnvironment(TriggerEnvironment.SERVER) .build() assertEquals(valueMap.size.toLong(), 12) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( LocalDate.Companion.currentDate().toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(LocalDate.Companion.currentDate().toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!) .hasValue(currentEventDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(currentEventDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("3") + RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("3") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("3") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_current") + RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_current") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_event_uid_current") assertNull(valueMap["due_date"]) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue("test_value_one_newest") + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue("test_value_one_newest") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates( "test_value_one_newest", "test_value_one_current", "test_value_one_oldest" ) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!).hasValue("test_value_two_newest") + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!).hasValue("test_value_two_newest") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates( "test_value_two_newest", "test_value_two_current", "test_value_two_oldest" @@ -327,28 +329,28 @@ class RuleVariableValueMapBuilderTest { .ruleEvents( listOf(firstRuleEvent, secondRuleEvent)) .build() assertEquals(13, valueMap.size.toLong()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( LocalDate.Companion.currentDate().toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(LocalDate.Companion.currentDate().toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!) .hasValue(dateEventCurrent.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(dateEventCurrent.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("3") + RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("3") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("3") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_current") + RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_current") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_event_uid_current") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!) .hasValue(dateEventDueCurrent.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(dateEventDueCurrent.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!) .hasValue("test_value_dataelement_one_current") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates( "test_value_dataelement_one_current", "test_value_dataelement_one_second", "test_value_dataelement_one_first" ) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!) .hasValue("test_value_dataelement_two_current") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates( "test_value_dataelement_two_current", @@ -417,21 +419,21 @@ class RuleVariableValueMapBuilderTest { .triggerEnvironment(TriggerEnvironment.SERVER) .build() assertEquals(12, valueMap.size.toLong()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( LocalDate.Companion.currentDate().toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(LocalDate.Companion.currentDate().toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!) .hasValue(dateEventCurrent.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(dateEventCurrent.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("4") + RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("4") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("4") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_current") + RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_current") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_event_uid_current") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!) .hasValue(dateEventDueCurrent.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(dateEventDueCurrent.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable"]!!).hasValue("test_value_one") + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable"]!!).hasValue("test_value_one") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_value_one", "test_value_current") } @@ -467,23 +469,23 @@ class RuleVariableValueMapBuilderTest { .ruleEvents( listOf(ruleEventOne)) .build() assertEquals(12, valueMap.size.toLong()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( LocalDate.Companion.currentDate().toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(LocalDate.Companion.currentDate().toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!).hasValue( dateEventTwo.toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(dateEventTwo.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("2") + RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("2") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("2") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_two") + RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_two") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_event_uid_two") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!).hasValue( dateEventTwo.toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(dateEventTwo.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable"]!!).hasValue(null) + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable"]!!).hasValue(null) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates() } @@ -547,21 +549,21 @@ class RuleVariableValueMapBuilderTest { .ruleEvents( listOf(ruleEventOne, ruleEventTwo, ruleEventThree)) .build() assertEquals(12, valueMap.size.toLong()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( LocalDate.Companion.currentDate().toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(LocalDate.Companion.currentDate().toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!) .hasValue(dateEventCurrent.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(dateEventCurrent.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("4") + RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("4") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("4") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_current") + RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid_current") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_event_uid_current") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!) .hasValue(dateEventCurrent.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(dateEventCurrent.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable"]!!).hasValue("test_value_two") + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable"]!!).hasValue("test_value_two") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT) .hasCandidates("test_value_three", "test_value_current", "test_value_two", "test_value_one") } @@ -632,40 +634,40 @@ class RuleVariableValueMapBuilderTest { .ruleEvents( listOf(contextEvent)) .build() assertEquals(20, valueMap.size.toLong()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue( LocalDate.Companion.currentDate().toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(LocalDate.Companion.currentDate().toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["event_date"]!!).hasValue( eventDate.toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(eventDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("2") + RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("2") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("2") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid") + RuleVariableValueAssert.assertThatVariable(valueMap["event_id"]!!).hasValue("test_event_uid") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_event_uid") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!).hasValue( + RuleVariableValueAssert.assertThatVariable(valueMap["due_date"]!!).hasValue( eventDate.toString() ) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(eventDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_status"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_status"]!!) .hasValue(org.hisp.dhis.rules.models.RuleEnrollment.Status.ACTIVE.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(org.hisp.dhis.rules.models.RuleEnrollment.Status.ACTIVE.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(enrollmentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_id"]!!).hasValue("test_enrollment") + RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_id"]!!).hasValue("test_enrollment") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_enrollment") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["incident_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["incident_date"]!!) .hasValue(enrollmentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(enrollmentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["tei_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(valueMap["tei_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue("test_attribute_value_one") + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue("test_attribute_value_one") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_attribute_value_one") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!).hasValue("test_attribute_value_two") + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!).hasValue("test_attribute_value_two") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_attribute_value_two") } @@ -724,25 +726,25 @@ class RuleVariableValueMapBuilderTest { .triggerEnvironment(TriggerEnvironment.SERVER) .build() assertEquals(15, valueMap.size.toLong()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue(currentDate.toString()) + RuleVariableValueAssert.assertThatVariable(valueMap["current_date"]!!).hasValue(currentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(currentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("2") + RuleVariableValueAssert.assertThatVariable(valueMap["event_count"]!!).hasValue("2") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("2") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(enrollmentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_id"]!!).hasValue("test_enrollment") + RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_id"]!!).hasValue("test_enrollment") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_enrollment") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(valueMap["enrollment_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["incident_date"]!!) + RuleVariableValueAssert.assertThatVariable(valueMap["incident_date"]!!) .hasValue(incidentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(incidentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["tei_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(valueMap["tei_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue("test_attribute_value_one") + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_one"]!!).hasValue("test_attribute_value_one") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("test_attribute_value_one") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!).isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT) + RuleVariableValueAssert.assertThatVariable(valueMap["test_variable_two"]!!).isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT) .hasValue("test_attribute_value_two").hasCandidates("test_attribute_value_two") } @@ -812,91 +814,91 @@ class RuleVariableValueMapBuilderTest { val eventTwoValueMap = eventMap[ruleEventTwo] // Enrollment - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(enrollmentValueMap!!["current_date"]!!).hasValue(currentDate.toString()) + RuleVariableValueAssert.assertThatVariable(enrollmentValueMap!!["current_date"]!!).hasValue(currentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(currentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["event_count"]!!).hasValue("2") + RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["event_count"]!!).hasValue("2") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("2") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["enrollment_date"]!!) + RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(enrollmentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["enrollment_id"]!!).hasValue("test_enrollment") + RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["enrollment_id"]!!).hasValue("test_enrollment") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_enrollment") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["enrollment_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["enrollment_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["incident_date"]!!) + RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["incident_date"]!!) .hasValue(incidentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(incidentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["tei_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["tei_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["test_variable_one"]!!) + RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["test_variable_one"]!!) .hasValue("test_attribute_value_one") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("test_attribute_value_one") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["test_variable_two"]!!) + RuleVariableValueAssert.assertThatVariable(enrollmentValueMap["test_variable_two"]!!) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT) .hasValue("test_attribute_value_two").hasCandidates("test_attribute_value_two") // Event one - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap!!["current_date"]!!).hasValue(currentDate.toString()) + RuleVariableValueAssert.assertThatVariable(eventOneValueMap!!["current_date"]!!).hasValue(currentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(currentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["event_count"]!!).hasValue("2") + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["event_count"]!!).hasValue("2") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("2") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["enrollment_date"]!!) + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(enrollmentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["enrollment_id"]!!).hasValue("test_enrollment") + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["enrollment_id"]!!).hasValue("test_enrollment") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_enrollment") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["enrollment_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["enrollment_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["incident_date"]!!) + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["incident_date"]!!) .hasValue(incidentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(incidentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["tei_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["tei_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["test_variable_one"]!!) + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["test_variable_one"]!!) .hasValue("test_attribute_value_one") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("test_attribute_value_one") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["test_variable_two"]!!).isTypeOf( + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["test_variable_two"]!!).isTypeOf( org.hisp.dhis.rules.models.RuleValueType.TEXT) .hasValue("test_attribute_value_two").hasCandidates("test_attribute_value_two") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["event_date"]!!) + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["event_date"]!!) .hasValue(eventOneDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(eventOneDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventOneValueMap["due_date"]!!) + RuleVariableValueAssert.assertThatVariable(eventOneValueMap["due_date"]!!) .hasValue(eventOneDueDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(eventOneDueDate.toString()) // Event two - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap!!["current_date"]!!).hasValue(currentDate.toString()) + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap!!["current_date"]!!).hasValue(currentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(currentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["event_count"]!!).hasValue("2") + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["event_count"]!!).hasValue("2") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("2") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["enrollment_date"]!!) + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["enrollment_date"]!!) .hasValue(enrollmentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(enrollmentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["enrollment_id"]!!).hasValue("test_enrollment") + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["enrollment_id"]!!).hasValue("test_enrollment") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates("test_enrollment") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["enrollment_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["enrollment_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["incident_date"]!!) + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["incident_date"]!!) .hasValue(incidentDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(incidentDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["tei_count"]!!).hasValue("1") + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["tei_count"]!!).hasValue("1") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("1") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["test_variable_one"]!!) + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["test_variable_one"]!!) .hasValue("test_attribute_value_one") .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.NUMERIC).hasCandidates("test_attribute_value_one") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["test_variable_two"]!!).isTypeOf( + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["test_variable_two"]!!).isTypeOf( org.hisp.dhis.rules.models.RuleValueType.TEXT) .hasValue("test_attribute_value_two").hasCandidates("test_attribute_value_two") - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["event_date"]!!) + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["event_date"]!!) .hasValue(eventTwoDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(eventTwoDate.toString()) - org.hisp.dhis.rules.RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["due_date"]!!) + RuleVariableValueAssert.assertThatVariable(eventTwoValueMap["due_date"]!!) .hasValue(eventTwoDueDate.toString()) .isTypeOf(org.hisp.dhis.rules.models.RuleValueType.TEXT).hasCandidates(eventTwoDueDate.toString()) } - @Test(expected = IllegalStateException::class) + @Test fun buildShouldThrowOnDuplicateEvent() { val ruleEvent = RuleEvent( "test_event_two", @@ -910,9 +912,12 @@ class RuleVariableValueMapBuilderTest { null, ArrayList() ) - RuleVariableValueMapBuilder.target(ruleEvent) - .ruleVariables(ArrayList()) - .ruleEvents( listOf(ruleEvent)) - .build() + assertFailsWith(IllegalStateException::class) + { + RuleVariableValueMapBuilder.target(ruleEvent) + .ruleVariables(ArrayList()) + .ruleEvents(listOf(ruleEvent)) + .build() + } } }