Drools rules loop knowledge base / published by https://github.com/dacr/code-examples-manager #6b3ee4ec-6f57-4587-b0ea-1be4118b5a2f/6e053dca54cea9f277fd2dfe8e970e63c2864008
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
// summary : Drools rules loop knowledge base | |
// keywords : scala, drools, mvel, scalatest, ai, knowledgebase, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 6b3ee4ec-6f57-4587-b0ea-1be4118b5a2f | |
// created-on : 2019-10-04T09:15:21+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.3.0" | |
//> using dep "fr.janalyse::drools-scripting:1.1.0" | |
//> using dep "org.scalatest::scalatest:3.2.16" | |
// --------------------- | |
import fr.janalyse.droolscripting._, org.scalatest._, flatspec._, matchers._, OptionValues._ | |
object KbTest extends AnyFlatSpec with should.Matchers { | |
val drl = | |
"""package test | |
| | |
|declare That | |
| count:int | |
|end | |
| | |
|rule "init" when then insert(new That(0)); end | |
| | |
|rule "count" | |
|when | |
| //$that:That($count:count) | |
| $that:That($count:count , count < 100) | |
|then | |
| modify($that) { | |
| setCount($count+1) | |
| } | |
|end | |
|""".stripMargin | |
"test KB" should "work" in { | |
val engine = DroolsEngine(drl) | |
engine.fireAllRules() | |
engine.getModelFirstInstanceAttribute("test.That", "count").value.asInstanceOf[Int] shouldBe 100 | |
} | |
} | |
KbTest.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment