Last active
May 25, 2024 10:19
-
-
Save dacr/c18e2d4ca7a99c4723bec37f1a418afc to your computer and use it in GitHub Desktop.
Drools official examples unit tests, it list all example knowledge base names / published by https://github.com/dacr/code-examples-manager #b78111c6-3b11-423c-b07c-4a392657a3f2/c6ebae80244905e899414498c6798b6a105c8072
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 official examples unit tests, it list all example knowledge base names | |
// keywords : scala, drools, mvel, ai, knowledgebase, scalatest, @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 : b78111c6-3b11-423c-b07c-4a392657a3f2 | |
// created-on : 2019-10-14T16:50:57+02:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "fr.janalyse::drools-scripting:1.0.16" | |
//> using dep "org.scalatest::scalatest:3.2.10" | |
//> using dep "org.drools:drools-examples:7.54.0.Final" | |
// --------------------- | |
import fr.janalyse.droolscripting._, org.scalatest._, flatspec._, matchers._, OptionValues._ | |
import org.kie.api._ | |
import scala.jdk.CollectionConverters._ | |
object OfficialExamples extends AnyFlatSpec with should.Matchers { | |
override def suiteName: String = "OfficialExamples" | |
val kServices = KieServices.Factory.get | |
val kContainer = kServices.getKieClasspathContainer() | |
// ------------------------------------------------------------------ | |
"Drools" should "be able to list all its available knowledge base examples" in { | |
val names = kContainer.getKieBaseNames | |
names.size should be >(0) | |
names.asScala.foreach{name => info(s"Found KieBaseName: $name")} | |
} | |
// ------------------------------------------------------------------ | |
it should "be able to run its FireKB" in { | |
val engine = kContainer.getKieBase("FireKB") | |
val session = engine.newKieSession() | |
try { | |
import org.drools.examples.fire._ | |
session.insert(new Fire(new Room("123"))) | |
session.fireAllRules() | |
} finally { session.dispose() } | |
} | |
} | |
OfficialExamples.execute() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment