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.kuali.rice.krms.test;
17  
18  import java.util.Collections;
19  
20  import org.junit.Before;
21  import org.junit.Test;
22  import org.kuali.rice.krms.api.repository.context.ContextDefinition;
23  import org.kuali.rice.krms.api.repository.term.TermDefinition;
24  import org.kuali.rice.krms.api.repository.term.TermParameterDefinition;
25  import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
26  import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition;
27  import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition;
28  import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
29  import org.kuali.rice.krms.impl.repository.ContextBoService;
30  import org.kuali.rice.krms.impl.repository.ContextBoServiceImpl;
31  import org.kuali.rice.krms.impl.repository.KrmsTypeBoServiceImpl;
32  import org.kuali.rice.krms.impl.repository.TermBoService;
33  import org.kuali.rice.krms.impl.repository.TermBoServiceImpl;
34  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
35  import org.kuali.rice.test.BaselineTestCase.Mode;
36  
37  @BaselineMode(Mode.CLEAR_DB)
38  public class TermRelatedBoTest extends AbstractBoTest {
39  	
40  	private TermBoService termBoService;
41  	private ContextBoService contextRepository;
42  	private KrmsTypeRepositoryService krmsTypeRepository;
43  	
44  	@Before
45  	public void setup() {
46  
47  		// wire up BO services
48  
49  		termBoService = new TermBoServiceImpl();
50  		((TermBoServiceImpl)termBoService).setBusinessObjectService(getBoService());
51  
52  		contextRepository = new ContextBoServiceImpl();
53  		((ContextBoServiceImpl)contextRepository).setBusinessObjectService(getBoService());
54  		
55  		krmsTypeRepository = new KrmsTypeBoServiceImpl();
56  		((KrmsTypeBoServiceImpl)krmsTypeRepository).setBusinessObjectService(getBoService());
57  	}
58  	
59  	@Test
60  	public void creationTest() {
61  
62  		// KrmsType for context
63  		KrmsTypeDefinition krmsContextTypeDefinition = KrmsTypeDefinition.Builder.create("KrmsTestContextType", "KRMS").build();
64  		krmsContextTypeDefinition = krmsTypeRepository.createKrmsType(krmsContextTypeDefinition);
65  
66  		// Context
67  		ContextDefinition.Builder contextBuilder = ContextDefinition.Builder.create("KRMS", "testContext");
68  		contextBuilder.setTypeId(krmsContextTypeDefinition.getId());
69  		ContextDefinition contextDefinition = contextBuilder.build();
70  		contextDefinition = contextRepository.createContext(contextDefinition);
71  		
72  		// output TermSpec
73  		TermSpecificationDefinition outputTermSpec = 
74  			TermSpecificationDefinition.Builder.create(null, "outputTermSpec", contextDefinition.getId(),
75                      "java.lang.String").build();
76  		outputTermSpec = termBoService.createTermSpecification(outputTermSpec);
77  
78  		// prereq TermSpec
79  		TermSpecificationDefinition prereqTermSpec = 
80  			TermSpecificationDefinition.Builder.create(null, "prereqTermSpec", contextDefinition.getId(),
81                      "java.lang.String").build();
82  		prereqTermSpec = termBoService.createTermSpecification(prereqTermSpec);
83  
84  		// KrmsType for TermResolver
85  		KrmsTypeDefinition krmsTermResolverTypeDefinition = KrmsTypeDefinition.Builder.create("KrmsTestResolverType", "KRMS").build();
86  		krmsTermResolverTypeDefinition = krmsTypeRepository.createKrmsType(krmsTermResolverTypeDefinition);
87  
88  		// TermResolver
89  		TermResolverDefinition termResolverDef = 
90  			TermResolverDefinition.Builder.create(null, "KRMS", "testResolver", krmsTermResolverTypeDefinition.getId(),
91  					TermSpecificationDefinition.Builder.create(outputTermSpec), 
92  					Collections.singleton(TermSpecificationDefinition.Builder.create(prereqTermSpec)), 
93  					null, 
94  					Collections.singleton("testParamName")).build();
95  		termResolverDef = termBoService.createTermResolver(termResolverDef);
96  
97  		// Term Param
98  		TermParameterDefinition.Builder termParamBuilder = 
99  			TermParameterDefinition.Builder.create(null, null, "testParamName", "testParamValue");
100 		
101 		// Term
102 		TermDefinition termDefinition = 
103 			TermDefinition.Builder.create(null, TermSpecificationDefinition.Builder.create(outputTermSpec), Collections.singletonList(termParamBuilder)).build();
104 		termBoService.createTerm(termDefinition);
105 	}
106 	
107 }