1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.framework;
17
18 import static junit.framework.Assert.assertNotNull;
19
20 import java.util.ArrayList;
21 import java.util.Arrays;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.List;
25 import java.util.Map;
26
27 import org.junit.Test;
28 import org.kuali.rice.krms.api.engine.EngineResults;
29 import org.kuali.rice.krms.api.engine.ExecutionOptions;
30 import org.kuali.rice.krms.api.engine.ExecutionFlag;
31 import org.kuali.rice.krms.api.engine.Facts;
32 import org.kuali.rice.krms.api.engine.SelectionCriteria;
33 import org.kuali.rice.krms.api.engine.Term;
34 import org.kuali.rice.krms.api.engine.TermResolver;
35 import org.kuali.rice.krms.api.repository.LogicalOperator;
36 import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
37 import org.kuali.rice.krms.framework.engine.Agenda;
38 import org.kuali.rice.krms.framework.engine.BasicAgenda;
39 import org.kuali.rice.krms.framework.engine.BasicAgendaTree;
40 import org.kuali.rice.krms.framework.engine.BasicAgendaTreeEntry;
41 import org.kuali.rice.krms.framework.engine.BasicContext;
42 import org.kuali.rice.krms.framework.engine.BasicRule;
43 import org.kuali.rice.krms.framework.engine.ComparableTermBasedProposition;
44 import org.kuali.rice.krms.framework.engine.CompoundProposition;
45 import org.kuali.rice.krms.framework.engine.Context;
46 import org.kuali.rice.krms.framework.engine.ContextProvider;
47 import org.kuali.rice.krms.framework.engine.Proposition;
48 import org.kuali.rice.krms.framework.engine.ProviderBasedEngine;
49 import org.kuali.rice.krms.framework.engine.ResultLogger;
50 import org.kuali.rice.krms.framework.engine.Rule;
51 import org.kuali.rice.krms.framework.engine.expression.ComparisonOperator;
52
53 public class KRMSTest {
54 private static final ResultLogger LOG = ResultLogger.getInstance();
55
56 @Test
57 public void compoundPropositionTest() {
58
59 Proposition prop1 = new ComparableTermBasedProposition(ComparisonOperator.GREATER_THAN, totalCostTerm, Integer.valueOf(1));
60 Proposition prop2 = new ComparableTermBasedProposition(ComparisonOperator.LESS_THAN, totalCostTerm, Integer.valueOf(1000));
61 Proposition prop3 = new ComparableTermBasedProposition(ComparisonOperator.GREATER_THAN, totalCostTerm, Integer.valueOf(1000));
62 CompoundProposition compoundProp1 = new CompoundProposition(LogicalOperator.AND, Arrays.asList(prop1, prop2, prop3));
63
64 Rule rule = new BasicRule("InBetween",compoundProp1, null);
65
66 BasicAgendaTree agendaTree = new BasicAgendaTree(new BasicAgendaTreeEntry(rule));
67 Agenda agenda = new BasicAgenda(Collections.singletonMap(AgendaDefinition.Constants.EVENT, "test"), agendaTree);
68
69 Map<String, String> contextQualifiers = new HashMap<String, String>();
70 contextQualifiers.put("docTypeName", "Proposal");
71
72 List<TermResolver<?>> testResolvers = new ArrayList<TermResolver<?>>();
73 testResolvers.add(testResolver);
74
75 Context context = new BasicContext(Arrays.asList(agenda), testResolvers);
76 ContextProvider contextProvider = new ManualContextProvider(context);
77
78 SelectionCriteria selectionCriteria = SelectionCriteria.createCriteria(null, contextQualifiers,
79 Collections.singletonMap(AgendaDefinition.Constants.EVENT, "test"));
80
81 ProviderBasedEngine engine = new ProviderBasedEngine();
82 engine.setContextProvider(contextProvider);
83
84
85 ExecutionOptions executionOptions = new ExecutionOptions().setFlag(ExecutionFlag.LOG_EXECUTION, true);
86
87 EngineResults results = engine.execute(selectionCriteria, Facts.EMPTY_FACTS, executionOptions);
88 assertNotNull(results);
89 }
90
91
92 private static final Term totalCostTerm = new Term("totalCost");
93
94 private static final TermResolver<Integer> testResolver = new TermResolverMock<Integer>(totalCostTerm.getName(), 1);
95 }