Last active
October 6, 2024 10:54
-
-
Save dacr/741b276cdfe3019b4f153d31c1e0cc85 to your computer and use it in GitHub Desktop.
Drools ammonite case class support ? / published by https://github.com/dacr/code-examples-manager #17497a70-de09-4646-84ce-a492fb4b4582/8104ac841bf8e3b758a4302baecafe7b0e6ea8ff
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 ammonite case class support ? | |
// keywords : scala, drools, mvel, scalatest, ai, case-classes | |
// 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 : 17497a70-de09-4646-84ce-a492fb4b4582 | |
// created-on : 2018-09-12T21:11:39+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 namespace1 { | |
object namespace2 { | |
case class DummyA(name: String, value: Int) | |
} | |
} | |
case class DummyB(name:String, value:Int) | |
object DroolsWithScalaCaseClassesTest extends AnyFlatSpec with should.Matchers { | |
override val suiteName = "DroolsWithScalaCaseClassesTest" | |
"drools" should "manage right regular case classes, but unfortunately not those created from ammonite or scala-cli" in { | |
val dummyAType = new namespace1.namespace2.DummyA("truc", 42).getClass.getName | |
val dummyBType = new DummyB("truc", 42).getClass.getName | |
val Array(dummyAPackage, dummyAClassName) = dummyAType.split("[.](?=[^.]*$)", 2) | |
val Array(dummyBPackage, dummyBClassName) = dummyBType.split("[.](?=[^.]*$)", 2) | |
val drl = | |
s"""package testdrools | |
| | |
|import $dummyAType | |
| | |
|rule "hello dummy" | |
|when | |
| $dummyAClassName($$name:name) | |
|then | |
| System.out.println("HELLO "+$$name); | |
|end | |
| | |
|""".stripMargin | |
println(drl) | |
val engine = DroolsEngine(drl) | |
engine.fireAllRules() | |
engine.dispose() | |
} | |
} | |
DroolsWithScalaCaseClassesTest.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment