View Javadoc

1   package org.rice.krms.test;
2   
3   import static junit.framework.Assert.assertTrue;
4   import static junit.framework.Assert.assertEquals;
5   
6   import java.util.ArrayList;
7   import java.util.Collections;
8   import java.util.Date;
9   import java.util.HashMap;
10  import java.util.List;
11  import java.util.Map;
12  
13  import org.junit.Before;
14  import org.junit.Test;
15  import org.kuali.rice.kew.util.PerformanceLogger;
16  import org.kuali.rice.krms.api.engine.EngineResults;
17  import org.kuali.rice.krms.api.engine.ExecutionFlag;
18  import org.kuali.rice.krms.api.engine.ExecutionOptions;
19  import org.kuali.rice.krms.api.engine.ResultEvent;
20  import org.kuali.rice.krms.api.engine.SelectionCriteria;
21  import org.kuali.rice.krms.api.engine.Term;
22  import org.kuali.rice.krms.api.engine.TermSpecification;
23  import org.kuali.rice.krms.api.repository.RuleRepositoryService;
24  import org.kuali.rice.krms.api.repository.action.ActionDefinition;
25  import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
26  import org.kuali.rice.krms.api.repository.agenda.AgendaItem;
27  import org.kuali.rice.krms.api.repository.context.ContextDefinition;
28  import org.kuali.rice.krms.api.repository.proposition.PropositionDefinition;
29  import org.kuali.rice.krms.api.repository.proposition.PropositionParameter;
30  import org.kuali.rice.krms.api.repository.proposition.PropositionParameterType;
31  import org.kuali.rice.krms.api.repository.proposition.PropositionType;
32  import org.kuali.rice.krms.api.repository.rule.RuleDefinition;
33  import org.kuali.rice.krms.api.repository.term.TermDefinition;
34  import org.kuali.rice.krms.api.repository.term.TermParameterDefinition;
35  import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
36  import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
37  import org.kuali.rice.krms.api.repository.type.KrmsAttributeDefinition;
38  import org.kuali.rice.krms.api.repository.type.KrmsTypeAttribute;
39  import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
40  import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
41  import org.kuali.rice.krms.framework.engine.ProviderBasedEngine;
42  import org.kuali.rice.krms.framework.engine.ResultLogger;
43  import org.kuali.rice.krms.framework.engine.result.EngineResultListener;
44  import org.kuali.rice.krms.framework.engine.result.Log4jResultListener;
45  import org.kuali.rice.krms.impl.provider.repository.CompoundPropositionTypeService;
46  import org.kuali.rice.krms.impl.provider.repository.RepositoryToEngineTranslator;
47  import org.kuali.rice.krms.impl.provider.repository.RepositoryToEngineTranslatorImpl;
48  import org.kuali.rice.krms.impl.provider.repository.RuleRepositoryContextProvider;
49  import org.kuali.rice.krms.impl.provider.repository.SimplePropositionTypeService;
50  import org.kuali.rice.krms.impl.repository.ActionBoService;
51  import org.kuali.rice.krms.impl.repository.ActionBoServiceImpl;
52  import org.kuali.rice.krms.impl.repository.AgendaBoService;
53  import org.kuali.rice.krms.impl.repository.AgendaBoServiceImpl;
54  import org.kuali.rice.krms.impl.repository.ContextAttributeBo;
55  import org.kuali.rice.krms.impl.repository.ContextBoService;
56  import org.kuali.rice.krms.impl.repository.ContextBoServiceImpl;
57  import org.kuali.rice.krms.impl.repository.KrmsAttributeDefinitionService;
58  import org.kuali.rice.krms.impl.repository.KrmsAttributeDefinitionServiceImpl;
59  import org.kuali.rice.krms.impl.repository.KrmsTypeBoServiceImpl;
60  import org.kuali.rice.krms.impl.repository.PropositionBoService;
61  import org.kuali.rice.krms.impl.repository.PropositionBoServiceImpl;
62  import org.kuali.rice.krms.impl.repository.RuleBoService;
63  import org.kuali.rice.krms.impl.repository.RuleBoServiceImpl;
64  import org.kuali.rice.krms.impl.repository.RuleRepositoryServiceImpl;
65  import org.kuali.rice.krms.impl.repository.TermBoService;
66  import org.kuali.rice.krms.impl.repository.TermBoServiceImpl;
67  import org.kuali.rice.krms.impl.type.KrmsTypeResolverImpl;
68  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
69  import org.kuali.rice.test.BaselineTestCase.Mode;
70  import org.springframework.transaction.annotation.Transactional;
71  
72  @BaselineMode(Mode.CLEAR_DB)
73  public class RepositoryCreateAndExecuteIntegrationTest extends AbstractBoTest {
74  
75      // Services needed for creation:
76  	private TermBoService termBoService;
77  	private ContextBoService contextRepository;
78      private KrmsTypeRepositoryService krmsTypeRepository;
79  
80      private PropositionBoService propositionBoService;
81      private RuleBoService ruleBoService;
82      private AgendaBoService agendaBoService;
83      private ActionBoService actionBoService;
84      private KrmsAttributeDefinitionService krmsAttributeDefinitionService;
85  
86      // Services needed for execution:
87      // already have TermBoService above, need that for execution too
88      private RuleRepositoryService ruleRepositoryService;
89  
90      private RuleRepositoryContextProvider contextProvider;
91      private ProviderBasedEngine engine;
92      private RepositoryToEngineTranslator repositoryToEngineTranslator;
93  
94  	@Before
95  	public void setup() {
96  		super.setup();
97  
98  		// wire up BO services for creation
99  
100 		termBoService = new TermBoServiceImpl();
101 		((TermBoServiceImpl)termBoService).setBusinessObjectService(getBoService());
102 
103 		contextRepository = new ContextBoServiceImpl();
104 		((ContextBoServiceImpl)contextRepository).setBusinessObjectService(getBoService());
105 
106 		krmsTypeRepository = new KrmsTypeBoServiceImpl();
107 		((KrmsTypeBoServiceImpl)krmsTypeRepository).setBusinessObjectService(getBoService());
108 
109 		propositionBoService = new PropositionBoServiceImpl();
110 		((PropositionBoServiceImpl)propositionBoService).setBusinessObjectService(getBoService());
111 
112         ruleBoService = new RuleBoServiceImpl();
113         ((RuleBoServiceImpl)ruleBoService).setBusinessObjectService(getBoService());
114 
115         agendaBoService = new AgendaBoServiceImpl();
116         ((AgendaBoServiceImpl)agendaBoService).setBusinessObjectService(getBoService());
117 
118         actionBoService = new ActionBoServiceImpl();
119         ((ActionBoServiceImpl)actionBoService).setBusinessObjectService(getBoService());
120 
121         krmsAttributeDefinitionService = new KrmsAttributeDefinitionServiceImpl();
122         ((KrmsAttributeDefinitionServiceImpl)krmsAttributeDefinitionService).setBusinessObjectService(getBoService());
123 
124 
125         // wire up services needed for execution
126 
127         // Already have termBoService from above, we'll need this for execution too
128 
129         ruleRepositoryService = new RuleRepositoryServiceImpl();
130         ((RuleRepositoryServiceImpl)ruleRepositoryService).setBusinessObjectService(getBoService());
131 
132         repositoryToEngineTranslator = new RepositoryToEngineTranslatorImpl();
133 
134         KrmsTypeResolverImpl typeResolver = new KrmsTypeResolverImpl();
135         typeResolver.setTypeRepositoryService(krmsTypeRepository);
136 
137         CompoundPropositionTypeService compoundPropositionTypeService = new CompoundPropositionTypeService();
138 
139         // Circular Dependency:
140         // CompoundPropositionTypeService -> RepositoryToEngineTranslatorImpl ->
141         // KrmsTypeResolverImpl -> CompoundPropositionTypeService
142         compoundPropositionTypeService.setTranslator(repositoryToEngineTranslator);
143 
144         SimplePropositionTypeService simplePropositionTypeService = new SimplePropositionTypeService();
145         simplePropositionTypeService.setTypeResolver(typeResolver);
146         simplePropositionTypeService.setTermBoService(termBoService);
147 
148         // TODO: custom functions too.
149         simplePropositionTypeService.setFunctionRepositoryService(null);
150 
151         typeResolver.setDefaultCompoundPropositionTypeService(compoundPropositionTypeService);
152         typeResolver.setDefaultSimplePropositionTypeService(simplePropositionTypeService);
153 
154         ((RepositoryToEngineTranslatorImpl)repositoryToEngineTranslator).setTermBoService(termBoService);
155         ((RepositoryToEngineTranslatorImpl)repositoryToEngineTranslator).setRuleRepositoryService(ruleRepositoryService);
156         ((RepositoryToEngineTranslatorImpl)repositoryToEngineTranslator).setTypeRepositoryService(krmsTypeRepository);
157         ((RepositoryToEngineTranslatorImpl)repositoryToEngineTranslator).setTypeResolver(typeResolver);
158 
159         contextProvider = new RuleRepositoryContextProvider();
160         contextProvider.setRuleRepositoryService(ruleRepositoryService);
161         contextProvider.setRepositoryToEngineTranslator(repositoryToEngineTranslator);
162 
163         engine = new ProviderBasedEngine();
164         engine.setContextProvider(contextProvider);
165 
166 	}
167 
168     private ContextDefinition createContextDefinition(String nameSpace) {
169         // Attribute Defn for context;
170         KrmsAttributeDefinition.Builder contextTypeAttributeDefnBuilder = KrmsAttributeDefinition.Builder.create(null, "Context1Qualifier", nameSpace);
171         contextTypeAttributeDefnBuilder.setLabel("Context 1 Qualifier");
172         KrmsAttributeDefinition contextTypeAttributeDefinition = krmsAttributeDefinitionService.createAttributeDefinition(contextTypeAttributeDefnBuilder.build());
173 
174         // Attr for context;
175         KrmsTypeAttribute.Builder krmsTypeAttrBuilder = KrmsTypeAttribute.Builder.create(null, null, contextTypeAttributeDefinition.getId(), 1);
176 
177         // KrmsType for context
178         KrmsTypeDefinition.Builder krmsContextTypeDefnBuilder = KrmsTypeDefinition.Builder.create(null, "KrmsTestContextType", nameSpace);
179         krmsContextTypeDefnBuilder.setAttributes(Collections.singletonList(krmsTypeAttrBuilder));
180         KrmsTypeDefinition krmsContextTypeDefinition = krmsContextTypeDefnBuilder.build();
181         krmsContextTypeDefinition = krmsTypeRepository.createKrmsType(krmsContextTypeDefinition);
182 
183         // Context
184         ContextDefinition.Builder contextBuilder = ContextDefinition.Builder.create(nameSpace, "Context1");
185         contextBuilder.setTypeId(krmsContextTypeDefinition.getId());
186         ContextDefinition contextDefinition = contextBuilder.build();
187         contextDefinition = contextRepository.createContext(contextDefinition);
188 
189         // Context Attribute
190         // TODO: do this fur eel
191         ContextAttributeBo contextAttribute = new ContextAttributeBo();
192         contextAttribute.setAttributeDefinitionId(contextTypeAttributeDefinition.getId());
193         contextAttribute.setContextId(contextDefinition.getId());
194         contextAttribute.setValue("BLAH");
195         getBoService().save(contextAttribute);
196 
197         return contextDefinition;
198     }
199 
200     private void createAgendaDefinition(ContextDefinition contextDefinition, String eventName, String nameSpace ) {
201         KrmsTypeDefinition krmsGenericTypeDefinition = createKrmsGenericTypeDefinition(nameSpace);
202 
203         AgendaDefinition agendaDef =
204             AgendaDefinition.Builder.create(null, "testAgenda", nameSpace, krmsGenericTypeDefinition.getId(), contextDefinition.getId()).build();
205         agendaDef = agendaBoService.createAgenda(agendaDef);
206 
207         AgendaItem.Builder agendaItemBuilder1 = AgendaItem.Builder.create(null, agendaDef.getId());
208         agendaItemBuilder1.setRuleId(createRuleDefinition1(contextDefinition, nameSpace).getId());
209 
210         AgendaItem agendaItem1 = agendaBoService.createAgendaItem(agendaItemBuilder1.build());
211 
212         AgendaDefinition.Builder agendaDefBuilder1 = AgendaDefinition.Builder.create(agendaDef);
213         agendaDefBuilder1.setAttributes(Collections.singletonMap("Event", eventName));
214         agendaDefBuilder1.setFirstItemId(agendaItem1.getId());
215         agendaDef = agendaDefBuilder1.build();
216 
217         agendaBoService.updateAgenda(agendaDef);
218     }
219 
220     private KrmsTypeDefinition createKrmsCampusTypeDefinition(String nameSpace) {
221 	    // KrmsType for campus svc
222         KrmsTypeDefinition.Builder krmsCampusTypeDefnBuilder = KrmsTypeDefinition.Builder.create(null, "CAMPUS", nameSpace);
223         KrmsTypeDefinition krmsCampusTypeDefinition = krmsTypeRepository.createKrmsType(krmsCampusTypeDefnBuilder.build());
224         return krmsCampusTypeDefinition;
225     }
226 
227     private KrmsTypeDefinition createKrmsActionTypeDefinition(String nameSpace) {
228         KrmsTypeDefinition.Builder krmsActionTypeDefnBuilder = KrmsTypeDefinition.Builder.create(null, "KrmsActionResolverType", nameSpace);
229         krmsActionTypeDefnBuilder.setServiceName("testActionTypeService");
230         KrmsTypeDefinition krmsActionTypeDefinition = krmsTypeRepository.createKrmsType(krmsActionTypeDefnBuilder.build());
231 
232         return krmsActionTypeDefinition;
233     }
234 
235     private KrmsTypeDefinition createKrmsGenericTypeDefinition(String nameSpace) {
236 	    // Attribute Defn for generic type;
237         KrmsAttributeDefinition.Builder genericTypeAttributeDefnBuilder = KrmsAttributeDefinition.Builder.create(null, "Event", nameSpace);
238         genericTypeAttributeDefnBuilder.setLabel("event name");
239         KrmsAttributeDefinition genericTypeAttributeDefinition1 = krmsAttributeDefinitionService.createAttributeDefinition(genericTypeAttributeDefnBuilder.build());
240 
241         // Attr for generic type;
242         KrmsTypeAttribute.Builder genericTypeAttrBuilder = KrmsTypeAttribute.Builder.create(null, null, genericTypeAttributeDefinition1.getId(), 1);
243 
244 		// Can use this generic type for KRMS bits that don't actually rely on services on the bus at this point in time
245 	    KrmsTypeDefinition.Builder krmsGenericTypeDefnBuilder = KrmsTypeDefinition.Builder.create(null, "KrmsTestGenericType", nameSpace);
246 	    krmsGenericTypeDefnBuilder.setAttributes(Collections.singletonList(genericTypeAttrBuilder));
247 	    KrmsTypeDefinition krmsGenericTypeDefinition = krmsTypeRepository.createKrmsType(krmsGenericTypeDefnBuilder.build());
248 
249         return krmsGenericTypeDefinition;
250     }
251 
252     @Transactional
253     @Test
254     public void createAndExecuteTest1() {
255         String nameSpace = "KRMS_TEST";
256         ContextDefinition contextDefinition = createContextDefinition(nameSpace);
257         createAgendaDefinition(contextDefinition, "Tsunami", nameSpace);
258 
259         Map<String,String> contextQualifiers = new HashMap<String,String>();
260         contextQualifiers.put("namespaceCode", nameSpace);
261         contextQualifiers.put("name", "Context1");
262         contextQualifiers.put("Context1Qualifier", "BLAH");
263         Map<String,String> agendaQualifiers = new HashMap<String,String>();
264         Date now = new Date();
265 
266         SelectionCriteria sc1 = SelectionCriteria.createCriteria("Tsunami", now, contextQualifiers, agendaQualifiers);
267 
268         Map<Term, Object> facts1 = new HashMap<Term, Object>();
269         TermSpecification campusCodeTermSpecCond = new TermSpecification("campusCodeTermSpec", "java.lang.String");
270         Term myCampusCode = new Term( campusCodeTermSpecCond );
271         facts1.put(myCampusCode, "BL");
272 
273         ExecutionOptions xOptions1 = new ExecutionOptions();
274         xOptions1.setFlag(ExecutionFlag.LOG_EXECUTION, true);
275 
276 	    // Need to initialize ResultLogger to get results.
277 	    // TODO: I'm concerned about how this will deal w/ concurrency.
278 	    ResultLogger resultLogger = ResultLogger.getInstance();
279         EngineResultListener engineResultListener = new EngineResultListener();
280 	    resultLogger.addListener(engineResultListener);
281         resultLogger.addListener(new Log4jResultListener());
282 
283         PerformanceLogger perfLog = new PerformanceLogger();
284         perfLog.log("starting rule execution");
285         EngineResults eResults1 = engine.execute(sc1, facts1, xOptions1);
286         perfLog.log("finished rule execution", true);
287         resultLogger.removeListener(engineResultListener);
288         List<ResultEvent> rEvents1 = eResults1.getAllResults();
289 
290         List<ResultEvent> ruleEvaluationResults1 = eResults1.getResultsOfType(ResultEvent.RuleEvaluated.toString());
291 
292         assertEquals(1, ruleEvaluationResults1.size());
293         assertTrue("rule should have evaluated to true", ruleEvaluationResults1.get(0).getResult());
294     }
295 
296     private RuleDefinition createRuleDefinition1(ContextDefinition contextDefinition, String nameSpace) {
297         // Rule 1
298         RuleDefinition.Builder ruleDefBuilder1 =
299             RuleDefinition.Builder.create(null, "Rule1", nameSpace, createKrmsCampusTypeDefinition(nameSpace).getId(), null);
300         RuleDefinition ruleDef1 = ruleBoService.createRule(ruleDefBuilder1.build());
301 
302 
303         ruleDefBuilder1 = RuleDefinition.Builder.create(ruleDef1);
304         ruleDefBuilder1.setProposition(createPropositionDefinition1(contextDefinition, ruleDef1));
305         ruleDef1 = ruleDefBuilder1.build();
306         ruleBoService.updateRule(ruleDef1);
307 
308         // Action
309         ActionDefinition.Builder actionDefBuilder1 = ActionDefinition.Builder.create(null, "testAction1", nameSpace, createKrmsActionTypeDefinition(nameSpace).getId(), ruleDef1.getId(), 1);
310         ActionDefinition actionDef1 = actionBoService.createAction(actionDefBuilder1.build());
311 
312         return ruleDef1;
313     }
314 
315     private PropositionDefinition.Builder createPropositionDefinition1(ContextDefinition contextDefinition, RuleDefinition ruleDef1) {
316         // Proposition for rule 1
317         PropositionDefinition.Builder propositionDefBuilder1 =
318             PropositionDefinition.Builder.create(null, PropositionType.SIMPLE.getCode(), ruleDef1.getId(), null /* type code is only for custom props */, Collections.<PropositionParameter.Builder>emptyList());
319         propositionDefBuilder1.setDescription("is campus bloomington");
320 
321         // PropositionParams for rule 1
322         List<PropositionParameter.Builder> propositionParams1 = new ArrayList<PropositionParameter.Builder>();
323         propositionParams1.add(
324                 PropositionParameter.Builder.create(null, null, createTermDefinition1(contextDefinition).getId(), PropositionParameterType.TERM.getCode(), 1)
325         );
326         propositionParams1.add(
327                 PropositionParameter.Builder.create(null, null, "BL", PropositionParameterType.CONSTANT.getCode(), 2)
328         );
329         propositionParams1.add(
330                 PropositionParameter.Builder.create(null, null, "=", PropositionParameterType.OPERATOR.getCode(), 3)
331         );
332 
333         // set the parent proposition so the builder will not puke
334         for (PropositionParameter.Builder propositionParamBuilder : propositionParams1) {
335             propositionParamBuilder.setProposition(propositionDefBuilder1);
336         }
337 
338         propositionDefBuilder1.setParameters(propositionParams1);
339 
340         return propositionDefBuilder1;
341     }
342 
343     private TermDefinition createTermDefinition1(ContextDefinition contextDefinition) {
344         // campusCode TermSpec
345         TermSpecificationDefinition campusCodeTermSpec =
346             TermSpecificationDefinition.Builder.create(null, contextDefinition.getId(),
347                     "campusCodeTermSpec", "java.lang.String").build();
348         campusCodeTermSpec = termBoService.createTermSpecification(campusCodeTermSpec);
349 
350         // Term 1
351         TermDefinition termDefinition1 =
352             TermDefinition.Builder.create(null, TermSpecificationDefinition.Builder.create(campusCodeTermSpec), null).build();
353         termDefinition1 = termBoService.createTermDefinition(termDefinition1);
354 
355         return termDefinition1;
356     }
357 
358 
359     @Transactional
360     @Test
361     public void createAndExecuteTest2() {
362         String nameSpace = "KRMS_TEST_2";
363         ContextDefinition contextDefinition = createContextDefinition(nameSpace);
364         createAgendaDefinition(contextDefinition, "Earthquake", nameSpace);
365 
366         Map<String,String> contextQualifiers = new HashMap<String,String>();
367         contextQualifiers.put("namespaceCode", nameSpace);
368         contextQualifiers.put("name", "Context1");
369         contextQualifiers.put("Context1Qualifier", "BLAH");
370         Map<String,String> agendaQualifiers = new HashMap<String,String>();
371         Date now = new Date();
372 
373 	    SelectionCriteria sc2 = SelectionCriteria.createCriteria("Earthquake", now, contextQualifiers, agendaQualifiers);
374 
375 	    Map<Term, Object> facts2 = new HashMap<Term, Object>();
376         TermSpecification campusCodeTermSpecCond = new TermSpecification("campusCodeTermSpec", "java.lang.String");
377         Term myCampusCode = new Term( campusCodeTermSpecCond );
378 	    facts2.put(myCampusCode, "BL");
379 
380 	    TermSpecification resolverPrereqTermSpec = new TermSpecification("prereqTermSpec", "java.lang.String");
381         Term resolverPrereqTerm = new Term(resolverPrereqTermSpec);
382         facts2.put(resolverPrereqTerm, "prereqValue");
383 
384 	    ExecutionOptions xOptions2 = new ExecutionOptions();
385 	    xOptions2.setFlag(ExecutionFlag.LOG_EXECUTION, true);
386 
387 	    // Need to initialize ResultLogger to get results.
388 	    // TODO: I'm concerned about how this will deal w/ concurrency.
389 	    ResultLogger resultLogger = ResultLogger.getInstance();
390         EngineResultListener engineResultListener = new EngineResultListener();
391 	    resultLogger.addListener(engineResultListener);
392         resultLogger.addListener(new Log4jResultListener());
393 
394         PerformanceLogger perfLog = new PerformanceLogger();
395         perfLog.log("starting rule execution");
396 	    EngineResults eResults2 = engine.execute(sc2, facts2, xOptions2);
397         perfLog.log("finished rule execution", true);
398 
399         resultLogger.removeListener(engineResultListener);
400 
401         List<ResultEvent> rEvents2 = eResults2.getAllResults();
402 
403 	    List<ResultEvent> ruleEvaluationResults2 = eResults2.getResultsOfType(ResultEvent.RuleEvaluated.toString());
404 
405 	    assertEquals(1, ruleEvaluationResults2.size());
406 	    assertTrue("rule should have evaluated to true", ruleEvaluationResults2.get(0).getResult());
407 	    assertTrue("testAction (from type service configured in KRMSTestHarnessSpringBeans.xml) didn't fire",
408 	            TestActionTypeService.actionFired("testAction"));
409 	}
410 
411     private RuleDefinition createRuleDefinition2(ContextDefinition contextDefinition, String nameSpace) {
412         KrmsTypeDefinition krmsActionTypeDefinition = createKrmsActionTypeDefinition(nameSpace);
413 
414         // Rule 2
415         RuleDefinition.Builder ruleDefBuilder2 =
416             RuleDefinition.Builder.create(null, "Rule2", nameSpace, krmsActionTypeDefinition.getId(), null);
417         RuleDefinition ruleDef2 = ruleBoService.createRule(ruleDefBuilder2.build());
418 
419 
420         ruleDefBuilder2 = RuleDefinition.Builder.create(ruleDef2);
421         ruleDefBuilder2.setProposition(createPropositionDefinition2(contextDefinition, ruleDef2, nameSpace));
422         ruleDef2 = ruleDefBuilder2.build();
423         ruleBoService.updateRule(ruleDef2);
424 
425         // Action
426         ActionDefinition.Builder actionDefBuilder2 = ActionDefinition.Builder.create(null, "testAction2", nameSpace, krmsActionTypeDefinition.getId(), ruleDef2.getId(), 1);
427         ActionDefinition actionDef2 = actionBoService.createAction(actionDefBuilder2.build());
428 
429         return ruleDef2;
430     }
431 
432     private PropositionDefinition.Builder createPropositionDefinition2(ContextDefinition contextDefinition, RuleDefinition ruleDef2, String nameSpace) {
433 
434         // Proposition
435         PropositionDefinition.Builder propositionDefBuilder2 =
436             PropositionDefinition.Builder.create(null, PropositionType.SIMPLE.getCode(), ruleDef2.getId(), null /* type code is only for custom props */, Collections.<PropositionParameter.Builder>emptyList());
437         propositionDefBuilder2.setDescription("is campus bloomington");
438 
439         // PropositionParams
440         List<PropositionParameter.Builder> propositionParams2 = new ArrayList<PropositionParameter.Builder>();
441         propositionParams2.add(
442                 PropositionParameter.Builder.create(null, null, createTermDefinition2(contextDefinition, nameSpace).getId(), PropositionParameterType.TERM.getCode(), 1)
443         );
444         propositionParams2.add(
445                 PropositionParameter.Builder.create(null, null, "RESULT1", PropositionParameterType.CONSTANT.getCode(), 2)
446         );
447         propositionParams2.add(
448                 PropositionParameter.Builder.create(null, null, "=", PropositionParameterType.OPERATOR.getCode(), 3)
449         );
450 
451         // set the parent proposition so the builder will not puke
452         for (PropositionParameter.Builder propositionParamBuilder : propositionParams2) {
453             propositionParamBuilder.setProposition(propositionDefBuilder2);
454         }
455 
456         propositionDefBuilder2.setParameters(propositionParams2);
457 
458         return propositionDefBuilder2;
459     }
460 
461     private TermDefinition createTermDefinition2(ContextDefinition contextDefinition, String nameSpace) {
462         // output TermSpec
463         TermSpecificationDefinition outputTermSpec =
464             TermSpecificationDefinition.Builder.create(null, contextDefinition.getId(),
465                     "outputTermSpec", "java.lang.String").build();
466         outputTermSpec = termBoService.createTermSpecification(outputTermSpec);
467 
468         // prereq TermSpec
469         TermSpecificationDefinition prereqTermSpec =
470             TermSpecificationDefinition.Builder.create(null, contextDefinition.getId(),
471                     "prereqTermSpec", "java.lang.String").build();
472         prereqTermSpec = termBoService.createTermSpecification(prereqTermSpec);
473 
474         // Term Param
475         TermParameterDefinition.Builder termParamBuilder2 =
476             TermParameterDefinition.Builder.create(null, null, "testParamName", "testParamValue");
477 
478         // Term
479         TermDefinition termDefinition2 =
480             TermDefinition.Builder.create(null, TermSpecificationDefinition.Builder.create(outputTermSpec), Collections.singletonList(termParamBuilder2)).build();
481         termDefinition2 = termBoService.createTermDefinition(termDefinition2);
482 
483 		// KrmsType for TermResolver
484 		KrmsTypeDefinition.Builder krmsTermResolverTypeDefnBuilder = KrmsTypeDefinition.Builder.create(null, "KrmsTestResolverType", nameSpace);
485 		krmsTermResolverTypeDefnBuilder.setServiceName("testResolverTypeService1");
486 
487 		KrmsTypeDefinition krmsTermResolverTypeDefinition = krmsTypeRepository.createKrmsType(krmsTermResolverTypeDefnBuilder.build());
488 
489         // TermResolver
490 		TermResolverDefinition termResolverDef =
491 			TermResolverDefinition.Builder.create(null, nameSpace, "testResolver1", contextDefinition.getId(), krmsTermResolverTypeDefinition.getId(),
492 					TermSpecificationDefinition.Builder.create(outputTermSpec),
493 					Collections.singleton(TermSpecificationDefinition.Builder.create(prereqTermSpec)),
494 					null,
495 					Collections.singleton("testParamName")).build();
496 		termResolverDef = termBoService.createTermResolver(termResolverDef);
497 
498         return termDefinition2;
499     }
500 
501 }