List<String> firedRules = new ArrayList<String>();
StatefulKnowledgeSession ksession = this.createKSession("/rules/AgendaGroupRules.drl", firedRules);
Playlist playlist = new Playlist("Good playlist");
ksession.setGlobal("index", new AtomicInteger(1));
ksession.insert(playlist);
ksession.insert(createThrillerSong());
ksession.insert(createAdagioSong());
ksession.insert(createTheFinalCountdownSong());
ksession.fireAllRules();
//No rules were fired because the MAIN agenda-group is empty. We
//need to manually set the focus in an agenda-group.
Assert.assertTrue(firedRules.isEmpty());
Assert.assertTrue(playlist.isEmpty());
Assert.assertFalse(playlist.isPlaying());
//This way we set the focus in an agenda-group
ksession.getAgenda().getAgendaGroup("Create Playlist").setFocus();
ksession.fireAllRules();
//3 rules x 3 songs = 9 + "Playlist ready" + "Play playlist" = 11
Assert.assertEquals(11,firedRules.size());
//The salience of the rules guarantees the excecution order
Assert.assertTrue(firedRules.get(0).equals("Classify Songs"));
Assert.assertTrue(firedRules.get(1).equals("Classify Songs"));
Assert.assertTrue(firedRules.get(2).equals("Classify Songs"));
Assert.assertTrue(firedRules.get(3).equals("Number Songs"));
Assert.assertTrue(firedRules.get(4).equals("Number Songs"));
Assert.assertTrue(firedRules.get(5).equals("Number Songs"));
Assert.assertTrue(firedRules.get(6).equals("Fill playlist"));
Assert.assertTrue(firedRules.get(7).equals("Fill playlist"));
Assert.assertTrue(firedRules.get(8).equals("Fill playlist"));
Assert.assertTrue(firedRules.get(9).equals("Playlist ready"));
Assert.assertTrue(firedRules.get(10).equals("Play playlist"));
Assert.assertEquals(3, playlist.getSongs().size());
Assert.assertTrue(playlist.isPlaying());
ksession.dispose();
}