View Javadoc

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