I would like to create a dynamic data structure from a DecisionTable or similar.
For what I can tell only staticly typed datastructure is possible as follows:
wiki code:
|should I buy milk|
|cash in wallet|credit card|broke?|
|0 |0 |yes |
The columns must map to the fixture by setter: setCashInWallet(int cash) and setCreditcard(int credit).
What i like to do is something more flexible where each column is populated to a list:
List<Map<String, Object>> decisionTable = new ArrayList<Map<String, Object>>();
Map<String, Object> row = new HashMap<String, Object>();
In the setup of the test I specify the target object, ex: com.domain.MoneyIHave. In the fixture I will convert the data structure via reflection to instances of this.
The api for adding facts (data structure) to the drools session is loose coupled.
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
for( Object fact : facts ) { //<----- loose baby!
ksession.insert( fact );
}
ksession.fireAllRules();
ksession.dispose();
If this is possible I can create a couple fixtures that is immune to data structure changes. These fixtures could handle almost all scenarios.
But I can´t find any example of this.
Tnx in avance.