@Test
public void testRuleFlowGroupActivation() throws Exception {
Scenario scenario = new Scenario();
Fixture[] given = new Fixture[]{new FactData( "Coolness",
"c",
ls( new FieldData( "num",
"42" ),
new FieldData( "name",
"mic" ) ),
false )
};
scenario.getFixtures().addAll( Arrays.asList( given ) );
ExecutionTrace executionTrace = new ExecutionTrace();
scenario.getRules().add( "rule1" );
scenario.setInclusive( true );
scenario.getFixtures().add( executionTrace );
Expectation[] assertions = new Expectation[2];
assertions[0] = new VerifyFact( "c",
ls( new VerifyField( "num",
"42",
"==" ) ) );
assertions[1] = new VerifyRuleFired( "rule1",
1,
null );
scenario.getFixtures().addAll( Arrays.asList( assertions ) );
WorkingMemory workingMemory = getWorkingMemory( "rule_flow_actication.drl" );
ClassLoader classLoader = ((InternalRuleBase) workingMemory.getRuleBase()).getRootClassLoader();
HashSet<String> imports = new HashSet<String>();
imports.add( "foo.bar.*" );
TypeResolver resolver = new ClassTypeResolver( imports,
classLoader );
Class< ? > coolnessClass = classLoader.loadClass( "foo.bar.Coolness" );
assertNotNull( coolnessClass );
ClassLoader cl_ = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader( classLoader );
//resolver will need to have generated beans in it - possibly using a composite classloader from the package,
//including whatever CL has the generated beans...
ScenarioRunner scenarioRunner = new ScenarioRunner( scenario,
resolver,
(InternalWorkingMemory) workingMemory );
assertEquals( 0,
executionTrace.getNumberOfRulesFired().intValue() );
assertSame( scenarioRunner.getScenario(),
scenario );
assertFalse( scenario.wasSuccessful() );
// Activate rule flow
scenario.getFixtures().clear();
given = new Fixture[]{new FactData( "Coolness",
"c",
ls( new FieldData( "num",
"42" ),
new FieldData( "name",
"mic" ) ),
false ), new ActivateRuleFlowGroup( "asdf" )};
workingMemory.clearAgenda();
scenario.getFixtures().addAll( Arrays.asList( given ) );
scenario.getFixtures().add( executionTrace );