001 /** 002 * Copyright 2005-2011 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.rice.krms.test; 017 018 import java.util.Collections; 019 020 import org.junit.Before; 021 import org.junit.Test; 022 import org.kuali.rice.krms.api.repository.context.ContextDefinition; 023 import org.kuali.rice.krms.api.repository.term.TermDefinition; 024 import org.kuali.rice.krms.api.repository.term.TermParameterDefinition; 025 import org.kuali.rice.krms.api.repository.term.TermResolverDefinition; 026 import org.kuali.rice.krms.api.repository.term.TermSpecificationDefinition; 027 import org.kuali.rice.krms.api.repository.type.KrmsTypeDefinition; 028 import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService; 029 import org.kuali.rice.krms.impl.repository.ContextBoService; 030 import org.kuali.rice.krms.impl.repository.ContextBoServiceImpl; 031 import org.kuali.rice.krms.impl.repository.KrmsTypeBoServiceImpl; 032 import org.kuali.rice.krms.impl.repository.TermBoService; 033 import org.kuali.rice.krms.impl.repository.TermBoServiceImpl; 034 import org.kuali.rice.test.BaselineTestCase.BaselineMode; 035 import org.kuali.rice.test.BaselineTestCase.Mode; 036 037 @BaselineMode(Mode.CLEAR_DB) 038 public class TermRelatedBoTest extends AbstractBoTest { 039 040 private TermBoService termBoService; 041 private ContextBoService contextRepository; 042 private KrmsTypeRepositoryService krmsTypeRepository; 043 044 @Before 045 public void setup() { 046 047 // wire up BO services 048 049 termBoService = new TermBoServiceImpl(); 050 ((TermBoServiceImpl)termBoService).setBusinessObjectService(getBoService()); 051 052 contextRepository = new ContextBoServiceImpl(); 053 ((ContextBoServiceImpl)contextRepository).setBusinessObjectService(getBoService()); 054 055 krmsTypeRepository = new KrmsTypeBoServiceImpl(); 056 ((KrmsTypeBoServiceImpl)krmsTypeRepository).setBusinessObjectService(getBoService()); 057 } 058 059 @Test 060 public void creationTest() { 061 062 // KrmsType for context 063 KrmsTypeDefinition krmsContextTypeDefinition = KrmsTypeDefinition.Builder.create("KrmsTestContextType", "KRMS").build(); 064 krmsContextTypeDefinition = krmsTypeRepository.createKrmsType(krmsContextTypeDefinition); 065 066 // Context 067 ContextDefinition.Builder contextBuilder = ContextDefinition.Builder.create("KRMS", "testContext"); 068 contextBuilder.setTypeId(krmsContextTypeDefinition.getId()); 069 ContextDefinition contextDefinition = contextBuilder.build(); 070 contextDefinition = contextRepository.createContext(contextDefinition); 071 072 // output TermSpec 073 TermSpecificationDefinition outputTermSpec = 074 TermSpecificationDefinition.Builder.create(null, "outputTermSpec", contextDefinition.getId(), 075 "java.lang.String").build(); 076 outputTermSpec = termBoService.createTermSpecification(outputTermSpec); 077 078 // prereq TermSpec 079 TermSpecificationDefinition prereqTermSpec = 080 TermSpecificationDefinition.Builder.create(null, "prereqTermSpec", contextDefinition.getId(), 081 "java.lang.String").build(); 082 prereqTermSpec = termBoService.createTermSpecification(prereqTermSpec); 083 084 // KrmsType for TermResolver 085 KrmsTypeDefinition krmsTermResolverTypeDefinition = KrmsTypeDefinition.Builder.create("KrmsTestResolverType", "KRMS").build(); 086 krmsTermResolverTypeDefinition = krmsTypeRepository.createKrmsType(krmsTermResolverTypeDefinition); 087 088 // TermResolver 089 TermResolverDefinition termResolverDef = 090 TermResolverDefinition.Builder.create(null, "KRMS", "testResolver", krmsTermResolverTypeDefinition.getId(), 091 TermSpecificationDefinition.Builder.create(outputTermSpec), 092 Collections.singleton(TermSpecificationDefinition.Builder.create(prereqTermSpec)), 093 null, 094 Collections.singleton("testParamName")).build(); 095 termResolverDef = termBoService.createTermResolver(termResolverDef); 096 097 // Term Param 098 TermParameterDefinition.Builder termParamBuilder = 099 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.createTermDefinition(termDefinition); 105 } 106 107 }