Last active
October 6, 2024 10:54
-
-
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/b6af0e1058eb4b26f0c78763d9de267e0d08a7f5
This file contains hidden or 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.5.1" | |
//> using dep "fr.janalyse::drools-scripting:1.2.0" | |
//> using dep "org.scalatest::scalatest:3.2.19" | |
// --------------------- | |
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