Last active
June 24, 2023 16:26
-
-
Save dacr/89405b045a9ef691706235b474a9a11d to your computer and use it in GitHub Desktop.
Drools Hello world revisited / published by https://github.com/dacr/code-examples-manager #ceb03394-2537-43f5-96c4-85f702e68ac6/918057ce426ebf563402c44a7534ca8c5a0d9930
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 Hello world revisited | |
// keywords : scala, drools, mvel, scalatest, ai, helloworld, @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 : ceb03394-2537-43f5-96c4-85f702e68ac6 | |
// execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' | |
// created-on : 2019-10-01T09:16:40+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 HelloTest extends AnyFlatSpec with should.Matchers { | |
"Drools" should "say hello" in { | |
val drl = | |
"""package test | |
| | |
|declare Someone | |
| name:String | |
|end | |
| | |
|declare Message | |
| message:String | |
|end | |
| | |
|rule "hello" when | |
| Someone($name:name) | |
|then | |
| insert(new Message("HELLO "+$name)); | |
|end | |
|""".stripMargin | |
val engine = DroolsEngine(drl) | |
engine.insertJson("""{"name":"John"}""","test.Someone") | |
engine.fireAllRules() | |
val msgOption = engine.getModelFirstInstanceAttribute("test.Message", "message") | |
msgOption.value shouldBe "HELLO John" | |
} | |
} | |
HelloTest.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment