imports.add( "org.junit.Assert.assertThat" );
imports.add( "org.hamcrest.CoreMatchers.is" );
imports.add( "org.hamcrest.CoreMatchers.equalTo" );
imports.add( "org.hamcrest.CoreMatchers.allOf" );
ReflectiveMatcherFactory rf = new ReflectiveMatcherFactory( imports );
String str = "package org.drools.simulation.test\n" +
"import " + Person.class.getName() + "\n" +
"rule updateAge no-loop when $p : Person() then modify( $p ) { setAge( $p.getAge() + 10 ) }; end\n";
ReleaseId releaseId = createKJar( "org.test.KBase1", str );
// @formatter:off
f.newKieSession( releaseId, "org.test.KBase1.KSession1" )
.insert( new Person( "yoda", 150 ) ).set( "y" )
.fireAllRules()
// show testing inside of ksession execution
.test( "y.name == 'yoda'" )
.test( "y.age == 160" )
// test hamcrest
.test( rf.assertThat( "y.name",
matcher( "equalTo",
"'yoda'" ) ) )
.test( rf.assertThat( "y.name, equalTo('yoda')" ) )
.test( rf.assertThat( "y.age",
matcher( "equalTo",
"160" ) ) )
.test( rf.assertThat( "y.age, equalTo(160)" ) )
// @ FIXME commented out until hamsandwich works in the build
// // test hamsandwich
// .test( rf.assertThat( "y", matcher( "allOf", matcher("name", matcher( "equalTo", "'yoda'" ) ),
// matcher("age", matcher( "equalTo", "160" ) )
// )) )
.end()
// show complex testing after the ksession has finished
.test( "y.name == 'yoda'" )
.test( "y.age == 160" )
// test hamcrest
.test( rf.assertThat( "y.name",
matcher( "equalTo",
"'yoda'" ) ) )
.test( rf.assertThat( "y.age",
matcher( "equalTo",
"160" ) ) )
.runSimulation();
// @ FIXME commented out until hamsandwich works in the build