Commit bc52b6a7 authored by Pratim Chaudhuri's avatar Pratim Chaudhuri

f| introduced support for empty rule set in command validation trait

parent 880f1e9f
Pipeline #51923018 passed with stages
in 19 minutes and 27 seconds
......@@ -2,9 +2,7 @@ image: openjdk:11
stages:
- compile
- unit_functional_test
- integration_functional_test
- test_coverage
- qa_functional
- code_quality_analysis
- publish_artifact
- publish_gitlab_pages
......@@ -55,16 +53,16 @@ compile:
script:
- sbt clean compile
unit_functional_testing:
stage: unit_functional_test
Unit Functional Testing:
stage: qa_functional
before_script:
script:
- sbt test
dependencies:
- compile
test_coverage:
stage: test_coverage
Test Coverage:
stage: qa_functional
before_script:
script:
- sbt clean coverage test coverageReport
......@@ -100,7 +98,7 @@ pages:
- public/
expire_in: 1 days
dependencies:
- test_coverage
- Test Coverage
only:
- development
......@@ -115,7 +113,7 @@ publish_artifact_to_gitlab:
when: on_success
expire_in: 1 days
dependencies:
- test_coverage
- Test Coverage
only:
- /^(release-\d+(\.\d+)|(feature|bugfix|security|hotfix)\/[[:alnum:]](-|[[:alnum:]])*)$/
- development
......@@ -128,6 +126,6 @@ publish_artifact_to_maven:
script:
- sbt publish
dependencies:
- test_coverage
- Test Coverage
only:
- development
......@@ -184,7 +184,7 @@ abstract class CommandHandlerActor[Cmd <: Command](commandClass: Class[Cmd],
}
case msg: CommandValidationInitiated =>
log.debug("Stage 2 : Technical validation initiated, and event received is [{}]", msg)
log.debug("Stage 3 : Business validation initiated, and event received is [{}]", msg)
case unknown =>
handleUnrecognizedMessage("Stage 3", unknown)
......
......@@ -96,12 +96,14 @@ trait CommandValidation[Cmd <: Command] extends PersistentActor
def processDomainCommand: Receive = {
case ValidateCommand(command: Cmd) =>
val commandValidationRequested = CommandValidationInitiated(commandValidationId, domainProcessingStage, command)
persist(commandValidationRequested) {
_ =>
commandState = Some(command)
evaluateRules(rules)
context.parent ! commandValidationRequested
context.become(processRuleWorkerEvents)
persist(commandValidationRequested) { _ =>
commandState = Some(command)
rules match {
case Nil => self ! GetCommandValidationStatus(context.parent)
case _ => evaluateRules (rules)
}
context.parent ! commandValidationRequested
context.become(processRuleWorkerEvents)
}
case GetCommandValidationStatus(observer) =>
......
......@@ -105,7 +105,6 @@ class CommandHandlerActorTest extends TestKit(ActorSystem(classOf[CommandHandler
assert(stage == DomainProcessingStage.Received)
assert(result.errors.head.code == classOf[UnsupportedOperation].getSimpleName)
}
}
it must "accept only ONE command, and reject additional commands send" in {
......@@ -134,6 +133,25 @@ class CommandHandlerActorTest extends TestKit(ActorSystem(classOf[CommandHandler
case CommandReceived(TestCommand(id, _)) =>
assert(id == cmd.id)
}
bot.expectMsgPF() {
case TechnicalValidationSuccessful(id) =>
assert(id == cmd.id)
}
}
it must "respond with technical validation success event, when technical validation rule set is empty" in {
val bot = TestProbe("CommandShooter")
val cmd = TestCommand()
val handler = bot.childActorOf(TestCommandHandler.props(cmd.id, Nil, someFailingRules))
bot.send(handler, CommandHandlerActor.Commands.ProcessCommand(cmd, Some(bot.ref)))
bot.expectMsgPF() {
case CommandReceived(TestCommand(id, _)) =>
assert(id == cmd.id)
}
bot.expectMsgPF() {
case TechnicalValidationSuccessful(id) =>
assert(id == cmd.id)
}
}
it must "respond with command processing failed event, when technical validation fails" in {
......@@ -171,6 +189,25 @@ class CommandHandlerActorTest extends TestKit(ActorSystem(classOf[CommandHandler
}
}
it must "respond with business validation success event, when rule sets for both technical and business validation are empty" in {
val bot = TestProbe("CommandShooter")
val cmd = TestCommand()
val handler = bot.childActorOf(TestCommandHandler.props(cmd.id, Nil, Nil))
bot.send(handler, CommandHandlerActor.Commands.ProcessCommand(cmd, Some(bot.ref)))
bot.expectMsgPF() {
case CommandReceived(TestCommand(id, _)) =>
assert(id == cmd.id)
}
bot.expectMsgPF() {
case TechnicalValidationSuccessful(id) =>
assert(id == cmd.id)
}
bot.expectMsgPF() {
case BusinessValidationSuccessful(id) =>
assert(id == cmd.id)
}
}
it must "respond with command processing failed event, when business validation fails" in {
val bot = TestProbe("CommandShooter")
val cmd = TestCommand()
......
......@@ -65,4 +65,34 @@ class BusinessDomainCommandValidationTest
}
}
}
it must "return validation result as Passed, when the rule set is empty" in {
val parent = TestProbe()
val cmd = TestCommand()
val valId = cmd.id
val businessDomainCommandValidation = parent.childActorOf(Props(
new TBusinessCommandValidation(
valId,
Nil)))
val validationCompleted = ValidationCompleted(
valId.value,
DomainProcessingStage.BusinessValidation,
cmd,
Passed
)
parent.send(businessDomainCommandValidation, ValidateCommand(cmd))
parent.expectMsg(CommandValidationInitiated(valId.value, DomainProcessingStage.BusinessValidation, cmd))
parent.ignoreMsg({
case ValidationInProgress(_, DomainProcessingStage.BusinessValidation, _, _) => true
})
within(5 seconds) {
expectNoMessage
parent.expectMsgPF(3 seconds) {
case completed: ValidationCompleted => assert(validationCompleted == completed)
case unknown => fail(s"Did not receive neither ValidationInProgress or Completed, instead [${unknown}]")
}
}
}
}
......@@ -113,8 +113,36 @@ class CommandValidationTest
technicalDomainCommandValidation ! PoisonPill
}
it must
"return validation result as Passed, when every rule has passed" in {
it must "return validation result as Passed, when rule set is empty" in {
val parent = TestProbe("ValidationPassed")
val cmd = TestCommand(id = CommandUuid())
val techValId = cmd.id.value
val technicalDomainCommandValidation = parent.childActorOf(Props(
new TestCommandValidation(
techValId,
Nil)))
val validationCompleted = ValidationCompleted(
techValId,
DomainProcessingStage.TechnicalValidation,
cmd,
Passed
)
parent.send(technicalDomainCommandValidation, ValidateCommand(cmd))
parent.expectMsg(5 seconds,
CommandValidationInitiated(techValId, DomainProcessingStage.TechnicalValidation, cmd))
parent.ignoreMsg({
case ValidationInProgress(_, DomainProcessingStage.BusinessValidation, _, _) => true
})
parent.send(technicalDomainCommandValidation, GetCommandValidationStatus(parent.ref))
within(5 seconds) {
expectNoMessage
parent.expectMsg(validationCompleted)
}
}
it must "return validation result as Passed, when every rule has passed" in {
val parent = TestProbe("ValidationPassed")
val cmd = TestCommand(id = CommandUuid())
val techValId = cmd.id.value
......
......@@ -59,4 +59,28 @@ class TechnicalDomainCommandValidationTest
parent.expectMsg(validationCompleted)
}
}
it must "return validation result as Passed, when rule set is empty" in {
val parent = TestProbe()
val cmd = TestCommand()
val techValId = cmd.id
val technicalDomainCommandValidation = parent.childActorOf(Props(
new TTechnicalCommandValidation(
techValId,
Nil)))
val validationCompleted = ValidationCompleted(
techValId.value,
DomainProcessingStage.TechnicalValidation,
cmd,
Passed
)
parent.send(technicalDomainCommandValidation, ValidateCommand(cmd))
parent.expectMsg(CommandValidationInitiated(techValId.value, DomainProcessingStage.TechnicalValidation, cmd))
parent.ignoreMsg({
case ValidationInProgress(_, DomainProcessingStage.BusinessValidation, _, _) => true
})
within(10 seconds) {
expectNoMessage
parent.expectMsg(validationCompleted)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment