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