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.AgendaItem;
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);
214 
215         AgendaDefinition agendaDef =
216             AgendaDefinition.Builder.create(null, "testAgenda", krmsGenericTypeDefinition.getId(), contextDefinition.getId()).build();
217         agendaDef = agendaBoService.createAgenda(agendaDef);
218 
219         AgendaItem.Builder agendaItemBuilder1 = AgendaItem.Builder.create(null, agendaDef.getId());
220         agendaItemBuilder1.setRuleId(createRuleDefinition1(contextDefinition, nameSpace).getId());
221 
222         AgendaItem 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 	    // Attribute Defn for generic type;
249         KrmsAttributeDefinition.Builder genericTypeAttributeDefnBuilder = KrmsAttributeDefinition.Builder.create(null, "Event", nameSpace);
250         genericTypeAttributeDefnBuilder.setLabel("event name");
251         KrmsAttributeDefinition genericTypeAttributeDefinition1 = krmsAttributeDefinitionService.createAttributeDefinition(genericTypeAttributeDefnBuilder.build());
252 
253         // Attr for generic type;
254         KrmsTypeAttribute.Builder genericTypeAttrBuilder = KrmsTypeAttribute.Builder.create(null, genericTypeAttributeDefinition1.getId(), 1);
255 
256 		// Can use this generic type for KRMS bits that don't actually rely on services on the bus at this point in time
257 	    KrmsTypeDefinition.Builder krmsGenericTypeDefnBuilder = KrmsTypeDefinition.Builder.create("KrmsTestGenericType", nameSpace);
258 	    krmsGenericTypeDefnBuilder.setAttributes(Collections.singletonList(genericTypeAttrBuilder));
259 	    KrmsTypeDefinition krmsGenericTypeDefinition = krmsTypeRepository.createKrmsType(krmsGenericTypeDefnBuilder.build());
260 
261         return krmsGenericTypeDefinition;
262     }
263 
264     @Transactional
265     @Test
266     public void createAndExecuteTest1() {
267         String nameSpace = "KRMS_TEST";
268         ContextDefinition contextDefinition = createContextDefinition(nameSpace);
269         createAgendaDefinition(contextDefinition, "Tsunami", nameSpace);
270 
271         Map<String,String> contextQualifiers = new HashMap<String,String>();
272         contextQualifiers.put("namespaceCode", nameSpace);
273         contextQualifiers.put("name", "Context1");
274         contextQualifiers.put("Context1Qualifier", "BLAH");
275         DateTime now = new DateTime();
276 
277         SelectionCriteria sc1 = SelectionCriteria.createCriteria(now, contextQualifiers,
278                 Collections.singletonMap(AgendaDefinition.Constants.EVENT, "Tsunami"));
279 
280         Facts.Builder factsBuilder1 = Facts.Builder.create();
281         factsBuilder1.addFact(CAMPUS_CODE_TERM_NAME, "BL");
282 
283         ExecutionOptions xOptions1 = new ExecutionOptions();
284         xOptions1.setFlag(ExecutionFlag.LOG_EXECUTION, true);
285 
286         PerformanceLogger perfLog = new PerformanceLogger();
287         perfLog.log("starting rule execution");
288         EngineResults eResults1 = engine.execute(sc1, factsBuilder1.build(), xOptions1);
289         perfLog.log("finished rule execution", true);
290         List<ResultEvent> rEvents1 = eResults1.getAllResults();
291 
292         List<ResultEvent> ruleEvaluationResults1 = eResults1.getResultsOfType(ResultEvent.RuleEvaluated.toString());
293 
294         assertEquals(1, ruleEvaluationResults1.size());
295         assertTrue("rule should have evaluated to true", ruleEvaluationResults1.get(0).getResult());
296     }
297 
298     private RuleDefinition createRuleDefinition1(ContextDefinition contextDefinition, String nameSpace) {
299         // Rule 1
300         RuleDefinition.Builder ruleDefBuilder1 =
301             RuleDefinition.Builder.create(null, "Rule1", nameSpace, null, null);
302         RuleDefinition ruleDef1 = ruleBoService.createRule(ruleDefBuilder1.build());
303 
304 
305         ruleDefBuilder1 = RuleDefinition.Builder.create(ruleDef1);
306         ruleDefBuilder1.setProposition(createPropositionDefinition1(contextDefinition, ruleDef1));
307         ruleDef1 = ruleDefBuilder1.build();
308         ruleBoService.updateRule(ruleDef1);
309 
310         // Action
311         ActionDefinition.Builder actionDefBuilder1 = ActionDefinition.Builder.create(null, "testAction1", nameSpace, createKrmsActionTypeDefinition(nameSpace).getId(), ruleDef1.getId(), 1);
312         ActionDefinition actionDef1 = actionBoService.createAction(actionDefBuilder1.build());
313 
314         return ruleDef1;
315     }
316 
317     private PropositionDefinition.Builder createPropositionDefinition1(ContextDefinition contextDefinition, RuleDefinition ruleDef1) {
318         // Proposition for rule 1
319         PropositionDefinition.Builder propositionDefBuilder1 =
320             PropositionDefinition.Builder.create(null, PropositionType.SIMPLE.getCode(), ruleDef1.getId(), null /* type code is only for custom props */, Collections.<PropositionParameter.Builder>emptyList());
321         propositionDefBuilder1.setDescription("is campus bloomington");
322 
323         // PropositionParams for rule 1
324         List<PropositionParameter.Builder> propositionParams1 = new ArrayList<PropositionParameter.Builder>();
325         propositionParams1.add(
326                 PropositionParameter.Builder.create(null, null, createTermDefinition1(contextDefinition).getId(), PropositionParameterType.TERM.getCode(), 1)
327         );
328         propositionParams1.add(
329                 PropositionParameter.Builder.create(null, null, "BL", PropositionParameterType.CONSTANT.getCode(), 2)
330         );
331         propositionParams1.add(
332                 PropositionParameter.Builder.create(null, null, "=", PropositionParameterType.OPERATOR.getCode(), 3)
333         );
334 
335         // set the parent proposition so the builder will not puke
336         for (PropositionParameter.Builder propositionParamBuilder : propositionParams1) {
337             propositionParamBuilder.setProposition(propositionDefBuilder1);
338         }
339 
340         propositionDefBuilder1.setParameters(propositionParams1);
341 
342         return propositionDefBuilder1;
343     }
344 
345     private TermDefinition createTermDefinition1(ContextDefinition contextDefinition) {
346         // campusCode TermSpec
347         TermSpecificationDefinition campusCodeTermSpec =
348             TermSpecificationDefinition.Builder.create(null, "campusCodeTermSpec", contextDefinition.getId(),
349                     "java.lang.String").build();
350         campusCodeTermSpec = termBoService.createTermSpecification(campusCodeTermSpec);
351 
352         // Term 1
353         TermDefinition termDefinition1 =
354             TermDefinition.Builder.create(null, TermSpecificationDefinition.Builder.create(campusCodeTermSpec), null).build();
355         termDefinition1 = termBoService.createTermDefinition(termDefinition1);
356 
357         return termDefinition1;
358     }
359 
360 
361     @Transactional
362     @Test
363     public void createAndExecuteTest2() {
364         String nameSpace = "KRMS_TEST_2";
365         ContextDefinition contextDefinition = createContextDefinition(nameSpace);
366         createAgendaDefinition(contextDefinition, "Earthquake", nameSpace);
367 
368         Map<String,String> contextQualifiers = new HashMap<String,String>();
369         contextQualifiers.put("namespaceCode", nameSpace);
370         contextQualifiers.put("name", "Context1");
371         contextQualifiers.put("Context1Qualifier", "BLAH");
372         Map<String,String> agendaQualifiers = new HashMap<String,String>();
373         agendaQualifiers.put(AgendaDefinition.Constants.EVENT, "Earthquake");
374         DateTime now = new DateTime();
375 
376 	    SelectionCriteria sc2 = SelectionCriteria.createCriteria(now, contextQualifiers, agendaQualifiers);
377 
378 	    Facts.Builder factsBuilder2 = Facts.Builder.create();
379         factsBuilder2.addFact(CAMPUS_CODE_TERM_NAME, "BL");
380         factsBuilder2.addFact("prereqTermSpec", "prereqValue");
381 
382 	    ExecutionOptions xOptions2 = new ExecutionOptions();
383 	    xOptions2.setFlag(ExecutionFlag.LOG_EXECUTION, true);
384 
385 
386         PerformanceLogger perfLog = new PerformanceLogger();
387         perfLog.log("starting rule execution");
388 	    EngineResults eResults2 = engine.execute(sc2, factsBuilder2.build(), xOptions2);
389         perfLog.log("finished rule execution", true);
390 
391         List<ResultEvent> rEvents2 = eResults2.getAllResults();
392 
393 	    List<ResultEvent> ruleEvaluationResults2 = eResults2.getResultsOfType(ResultEvent.RuleEvaluated.toString());
394 
395 	    assertEquals(1, ruleEvaluationResults2.size());
396 	    assertTrue("rule should have evaluated to true", ruleEvaluationResults2.get(0).getResult());
397 	    assertTrue("testAction (from type service configured in KRMSTestHarnessSpringBeans.xml) didn't fire",
398 	            TestActionTypeService.actionFired("testAction"));
399 	}
400 
401     private RuleDefinition createRuleDefinition2(ContextDefinition contextDefinition, String nameSpace) {
402         KrmsTypeDefinition krmsActionTypeDefinition = createKrmsActionTypeDefinition(nameSpace);
403 
404         // Rule 2
405         RuleDefinition.Builder ruleDefBuilder2 =
406             RuleDefinition.Builder.create(null, "Rule2", nameSpace, krmsActionTypeDefinition.getId(), null);
407         RuleDefinition ruleDef2 = ruleBoService.createRule(ruleDefBuilder2.build());
408 
409 
410         ruleDefBuilder2 = RuleDefinition.Builder.create(ruleDef2);
411         ruleDefBuilder2.setProposition(createPropositionDefinition2(contextDefinition, ruleDef2, nameSpace));
412         ruleDef2 = ruleDefBuilder2.build();
413         ruleBoService.updateRule(ruleDef2);
414 
415         // Action
416         ActionDefinition.Builder actionDefBuilder2 = ActionDefinition.Builder.create(null, "testAction2", nameSpace, krmsActionTypeDefinition.getId(), ruleDef2.getId(), 1);
417         ActionDefinition actionDef2 = actionBoService.createAction(actionDefBuilder2.build());
418 
419         return ruleDef2;
420     }
421 
422     private PropositionDefinition.Builder createPropositionDefinition2(ContextDefinition contextDefinition, RuleDefinition ruleDef2, String nameSpace) {
423 
424         // Proposition
425         PropositionDefinition.Builder propositionDefBuilder2 =
426             PropositionDefinition.Builder.create(null, PropositionType.SIMPLE.getCode(), ruleDef2.getId(), null /* type code is only for custom props */, Collections.<PropositionParameter.Builder>emptyList());
427         propositionDefBuilder2.setDescription("is campus bloomington");
428 
429         // PropositionParams
430         List<PropositionParameter.Builder> propositionParams2 = new ArrayList<PropositionParameter.Builder>();
431         propositionParams2.add(
432                 PropositionParameter.Builder.create(null, null, createTermDefinition2(contextDefinition, nameSpace).getId(), PropositionParameterType.TERM.getCode(), 1)
433         );
434         propositionParams2.add(
435                 PropositionParameter.Builder.create(null, null, "RESULT1", PropositionParameterType.CONSTANT.getCode(), 2)
436         );
437         propositionParams2.add(
438                 PropositionParameter.Builder.create(null, null, "=", PropositionParameterType.OPERATOR.getCode(), 3)
439         );
440 
441         // set the parent proposition so the builder will not puke
442         for (PropositionParameter.Builder propositionParamBuilder : propositionParams2) {
443             propositionParamBuilder.setProposition(propositionDefBuilder2);
444         }
445 
446         propositionDefBuilder2.setParameters(propositionParams2);
447 
448         return propositionDefBuilder2;
449     }
450 
451     private TermDefinition createTermDefinition2(ContextDefinition contextDefinition, String nameSpace) {
452         // output TermSpec
453         TermSpecificationDefinition outputTermSpec =
454             TermSpecificationDefinition.Builder.create(null, "outputTermSpec", contextDefinition.getId(),
455                     "java.lang.String").build();
456         outputTermSpec = termBoService.createTermSpecification(outputTermSpec);
457 
458         // prereq TermSpec
459         TermSpecificationDefinition prereqTermSpec =
460             TermSpecificationDefinition.Builder.create(null, "prereqTermSpec", contextDefinition.getId(),
461                     "java.lang.String").build();
462         prereqTermSpec = termBoService.createTermSpecification(prereqTermSpec);
463 
464         // Term Param
465         TermParameterDefinition.Builder termParamBuilder2 =
466             TermParameterDefinition.Builder.create(null, null, "testParamName", "testParamValue");
467 
468         // Term
469         TermDefinition termDefinition2 =
470             TermDefinition.Builder.create(null, TermSpecificationDefinition.Builder.create(outputTermSpec), Collections.singletonList(termParamBuilder2)).build();
471         termDefinition2 = termBoService.createTermDefinition(termDefinition2);
472 
473 		// KrmsType for TermResolver
474 		KrmsTypeDefinition.Builder krmsTermResolverTypeDefnBuilder = KrmsTypeDefinition.Builder.create("KrmsTestResolverType", nameSpace);
475 		krmsTermResolverTypeDefnBuilder.setServiceName("testResolverTypeService1");
476 
477 		KrmsTypeDefinition krmsTermResolverTypeDefinition = krmsTypeRepository.createKrmsType(krmsTermResolverTypeDefnBuilder.build());
478 
479         // TermResolver
480 		TermResolverDefinition termResolverDef =
481 			TermResolverDefinition.Builder.create(null, nameSpace, "testResolver1", krmsTermResolverTypeDefinition.getId(),
482 					TermSpecificationDefinition.Builder.create(outputTermSpec),
483 					Collections.singleton(TermSpecificationDefinition.Builder.create(prereqTermSpec)),
484 					null,
485 					Collections.singleton("testParamName")).build();
486 		termResolverDef = termBoService.createTermResolver(termResolverDef);
487 
488         return termDefinition2;
489     }
490 
491 }