Last active
July 31, 2020 10:22
-
-
Save lucamolteni/a5614aa95b8afd90d57ebf9bebc543f5 to your computer and use it in GitHub Desktop.
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
public static class Measurement { | |
private String id; | |
private String val; | |
public Measurement(String id, String val) { | |
this.id = id; | |
this.val = val; | |
} | |
public String getId() { | |
return id; | |
} | |
public void setId(String id) { | |
this.id = id; | |
} | |
public String getVal() { | |
return val; | |
} | |
public void setVal(String val) { | |
this.val = val; | |
} | |
} | |
@Test | |
public void testVariableAccessors() { | |
// DROOLS-5548 | |
String str = | |
"package com.sample" + | |
"global java.util.Set controlSet;\n" + | |
"import " + Measurement.class.getCanonicalName() + ";\n" + | |
"" + | |
"declare A\n" + | |
" x: String\n" + | |
"end\n" + | |
"" + | |
"declare B\n" + | |
" a: A\n" + | |
"end\n" + | |
"" + | |
"function String dummyFunction(B b) {\n" + | |
" return \"test\";\n" + | |
"}\n" + | |
"\n" + | |
"rule \"will execute per each Measurement having ID color\"\n" + | |
"no-loop\n" + | |
"when\n" + | |
" Measurement( id == \"color\", $colorVal : val )\n" + | |
" $b: B()\n" + | |
" $val: String() from dummyFunction($b.a)\n" + | |
"then\n" + | |
" controlSet.add($colorVal);\n" + | |
"end"; | |
KieSession ksession = getKieSession( str ); | |
ksession.insert(new Measurement("color", "red")); | |
ksession.fireAllRules(); | |
Collection<Result> results = getObjectsIntoList(ksession, Result.class ); | |
assertEquals( 1, results.size() ); | |
assertEquals( "test", results.iterator().next().getValue() ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment