Skip to content

Commit

Permalink
add test to verify workflow with auditDelegateMonitor flag null
Browse files Browse the repository at this point in the history
Signed-off-by: Surya Sashank Nistala <[email protected]>
  • Loading branch information
eirsep committed Jul 10, 2023
1 parent eaa7914 commit 1ef5f15
Showing 1 changed file with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.opensearch.common.io.stream.BytesStreamOutput
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.commons.alerting.model.CompositeInput
import org.opensearch.commons.alerting.model.IntervalSchedule
import org.opensearch.commons.alerting.model.Workflow
import org.opensearch.commons.alerting.randomDelegate
import org.opensearch.commons.alerting.randomUser
import org.opensearch.commons.alerting.randomWorkflow
import org.opensearch.rest.RestStatus
import java.time.Instant
import java.time.temporal.ChronoUnit

class GetWorkflowResponseTests {

@Test
fun testGetWorkflowRequest() {
fun testGetWorkflowResponse() {
val workflow = randomWorkflow(auditDelegateMonitorAlerts = false)
val response = GetWorkflowResponse(
id = "id", version = 1, seqNo = 1, primaryTerm = 1, status = RestStatus.OK, workflow = workflow
Expand All @@ -24,4 +31,35 @@ class GetWorkflowResponseTests {
Assertions.assertEquals(workflow.name, newRes.workflow!!.name)
Assertions.assertEquals(workflow.owner, newRes.workflow!!.owner)
}

@Test
fun testGetWorkflowResponseWhereAuditDelegateMonitorAlertsFlagIsNotSet() {
val workflow = Workflow(
id = "",
version = Workflow.NO_VERSION,
name = "test",
enabled = true,
schemaVersion = 2,
schedule = IntervalSchedule(1, ChronoUnit.MINUTES),
lastUpdateTime = Instant.now(),
enabledTime = Instant.now(),
workflowType = Workflow.WorkflowType.COMPOSITE,
user = randomUser(),
inputs = listOf(CompositeInput(org.opensearch.commons.alerting.model.Sequence(listOf(randomDelegate())))),
owner = "",
triggers = listOf()
)
val response = GetWorkflowResponse(
id = "id", version = 1, seqNo = 1, primaryTerm = 1, status = RestStatus.OK, workflow = workflow
)
val out = BytesStreamOutput()
response.writeTo(out)
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes)
val newRes = GetWorkflowResponse(sin)
Assertions.assertEquals("id", newRes.id)
Assertions.assertTrue(newRes.workflow!!.auditDelegateMonitorAlerts!!)
Assertions.assertEquals(workflow.name, newRes.workflow!!.name)
Assertions.assertEquals(workflow.owner, newRes.workflow!!.owner)
Assertions.assertEquals(workflow.auditDelegateMonitorAlerts, newRes.workflow!!.auditDelegateMonitorAlerts)
}
}

0 comments on commit 1ef5f15

Please sign in to comment.