-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Joanne Wang <[email protected]>
- Loading branch information
1 parent
a400d30
commit 7163092
Showing
19 changed files
with
416 additions
and
13 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
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
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
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
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
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
54 changes: 54 additions & 0 deletions
54
src/test/kotlin/org/opensearch/commons/alerting/model/BucketLevelTriggerTests.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,54 @@ | ||
package org.opensearch.commons.alerting.model | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.opensearch.commons.alerting.model.BucketLevelTrigger.Companion.CONDITION_FIELD | ||
import org.opensearch.commons.alerting.model.BucketLevelTrigger.Companion.LANG_FIELD | ||
import org.opensearch.commons.alerting.model.BucketLevelTrigger.Companion.PARENT_BUCKET_PATH | ||
import org.opensearch.commons.alerting.model.BucketLevelTrigger.Companion.SCRIPT_FIELD | ||
import org.opensearch.commons.alerting.model.BucketLevelTrigger.Companion.SOURCE_FIELD | ||
import org.opensearch.commons.alerting.model.Trigger.Companion.ACTIONS_FIELD | ||
import org.opensearch.commons.alerting.model.Trigger.Companion.ID_FIELD | ||
import org.opensearch.commons.alerting.model.Trigger.Companion.NAME_FIELD | ||
import org.opensearch.commons.alerting.model.Trigger.Companion.SEVERITY_FIELD | ||
import org.opensearch.commons.alerting.randomBucketLevelTrigger | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
|
||
class BucketLevelTriggerTests { | ||
|
||
@Test | ||
fun `test BucketLevelTrigger asTemplateArgs`() { | ||
val trigger = randomBucketLevelTrigger() | ||
|
||
val templateArgs = trigger.asTemplateArg() | ||
|
||
assertEquals(trigger.id, templateArgs[ID_FIELD], "Template arg field 'id' doesn't match") | ||
assertEquals(trigger.name, templateArgs[NAME_FIELD], "Template arg field 'name' doesn't match") | ||
assertEquals(trigger.severity, templateArgs[SEVERITY_FIELD], "Template arg field 'severity' doesn't match") | ||
val actions = templateArgs[ACTIONS_FIELD] as List<*> | ||
assertEquals( | ||
trigger.actions.size, | ||
actions.size, | ||
"Template arg field 'actions' doesn't match" | ||
) | ||
assertEquals( | ||
trigger.getParentBucketPath(), | ||
templateArgs[PARENT_BUCKET_PATH], | ||
"Template arg field 'parentBucketPath' doesn't match" | ||
) | ||
val condition = templateArgs[CONDITION_FIELD] as? Map<*, *> | ||
assertNotNull(condition, "Template arg field 'condition' is empty") | ||
val script = condition[SCRIPT_FIELD] as? Map<*, *> | ||
assertNotNull(script, "Template arg field 'condition.script' is empty") | ||
assertEquals( | ||
trigger.bucketSelector.script.idOrCode, | ||
script[SOURCE_FIELD], | ||
"Template arg field 'script.source' doesn't match" | ||
) | ||
assertEquals( | ||
trigger.bucketSelector.script.lang, | ||
script[LANG_FIELD], | ||
"Template arg field 'script.lang' doesn't match" | ||
) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/kotlin/org/opensearch/commons/alerting/model/DocumentLevelTriggerTests.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,48 @@ | ||
package org.opensearch.commons.alerting.model | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.opensearch.commons.alerting.model.DocumentLevelTrigger.Companion.CONDITION_FIELD | ||
import org.opensearch.commons.alerting.model.DocumentLevelTrigger.Companion.LANG_FIELD | ||
import org.opensearch.commons.alerting.model.DocumentLevelTrigger.Companion.SCRIPT_FIELD | ||
import org.opensearch.commons.alerting.model.DocumentLevelTrigger.Companion.SOURCE_FIELD | ||
import org.opensearch.commons.alerting.model.Trigger.Companion.ACTIONS_FIELD | ||
import org.opensearch.commons.alerting.model.Trigger.Companion.ID_FIELD | ||
import org.opensearch.commons.alerting.model.Trigger.Companion.NAME_FIELD | ||
import org.opensearch.commons.alerting.model.Trigger.Companion.SEVERITY_FIELD | ||
import org.opensearch.commons.alerting.randomDocumentLevelTrigger | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
|
||
class DocumentLevelTriggerTests { | ||
|
||
@Test | ||
fun `test DocumentLevelTrigger asTemplateArgs`() { | ||
val trigger = randomDocumentLevelTrigger() | ||
|
||
val templateArgs = trigger.asTemplateArg() | ||
|
||
assertEquals(trigger.id, templateArgs[ID_FIELD], "Template arg field 'id' doesn't match") | ||
assertEquals(trigger.name, templateArgs[NAME_FIELD], "Template arg field 'name' doesn't match") | ||
assertEquals(trigger.severity, templateArgs[SEVERITY_FIELD], "Template arg field 'severity' doesn't match") | ||
val actions = templateArgs[ACTIONS_FIELD] as List<*> | ||
assertEquals( | ||
trigger.actions.size, | ||
actions.size, | ||
"Template arg field 'actions' doesn't match" | ||
) | ||
val condition = templateArgs[CONDITION_FIELD] as? Map<*, *> | ||
assertNotNull(condition, "Template arg field 'condition' is empty") | ||
val script = condition[SCRIPT_FIELD] as? Map<*, *> | ||
assertNotNull(script, "Template arg field 'condition.script' is empty") | ||
assertEquals( | ||
trigger.condition.idOrCode, | ||
script[SOURCE_FIELD], | ||
"Template arg field 'script.source' doesn't match" | ||
) | ||
assertEquals( | ||
trigger.condition.lang, | ||
script[LANG_FIELD], | ||
"Template arg field 'script.lang' doesn't match" | ||
) | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/test/kotlin/org/opensearch/commons/alerting/model/MonitorsTests.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,49 @@ | ||
package org.opensearch.commons.alerting.model | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.opensearch.commons.alerting.randomQueryLevelMonitor | ||
import org.opensearch.commons.alerting.util.IndexUtils | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNotNull | ||
|
||
class MonitorsTests { | ||
|
||
@Test | ||
fun `test monitor asTemplateArgs`() { | ||
val monitor = randomQueryLevelMonitor(enabled = true) | ||
|
||
val templateArgs = monitor.asTemplateArg() | ||
|
||
assertEquals(monitor.id, templateArgs[IndexUtils._ID], "Template arg field 'id' doesn't match") | ||
assertEquals( | ||
monitor.version, | ||
templateArgs[IndexUtils._VERSION], | ||
"Template arg field 'version' doesn't match" | ||
) | ||
assertEquals(monitor.name, templateArgs[Monitor.NAME_FIELD], "Template arg field 'name' doesn't match") | ||
assertEquals( | ||
monitor.enabled, | ||
templateArgs[Monitor.ENABLED_FIELD], | ||
"Template arg field 'enabled' doesn't match" | ||
) | ||
assertEquals( | ||
monitor.monitorType.toString(), | ||
templateArgs[Monitor.MONITOR_TYPE_FIELD], | ||
"Template arg field 'monitoryType' doesn't match" | ||
) | ||
assertEquals( | ||
monitor.enabledTime?.toEpochMilli(), | ||
templateArgs[Monitor.ENABLED_TIME_FIELD], | ||
"Template arg field 'enabledTime' doesn't match" | ||
) | ||
assertEquals( | ||
monitor.lastUpdateTime.toEpochMilli(), | ||
templateArgs[Monitor.LAST_UPDATE_TIME_FIELD], | ||
"Template arg field 'lastUpdateTime' doesn't match" | ||
) | ||
assertNotNull(templateArgs[Monitor.SCHEDULE_FIELD], "Template arg field 'schedule' not set") | ||
val inputs = templateArgs[Monitor.INPUTS_FIELD] as? List<*> | ||
assertNotNull(inputs, "Template arg field 'inputs' not set") | ||
assertEquals(1, inputs.size, "Template arg field 'inputs' is not populated") | ||
} | ||
} |
Oops, something went wrong.