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.student.krms;
17  
18  import org.kuali.rice.core.api.lifecycle.Lifecycle;
19  import org.kuali.rice.core.framework.resourceloader.SpringResourceLoader;
20  import org.kuali.rice.krad.service.BusinessObjectService;
21  import org.kuali.rice.krad.service.KRADServiceLocator;
22  import org.kuali.rice.krms.api.repository.agenda.AgendaDefinition;
23  import org.kuali.rice.krms.api.repository.context.ContextDefinition;
24  import org.kuali.rice.krms.api.repository.term.TermDefinition;
25  import org.kuali.rice.krms.api.repository.term.TermResolverDefinition;
26  import org.kuali.rice.krms.api.repository.type.KrmsTypeRepositoryService;
27  import org.kuali.rice.krms.impl.repository.*;
28  import org.kuali.rice.test.BaselineTestCase;
29  import org.kuali.rice.test.BaselineTestCase.BaselineMode;
30  import org.kuali.rice.test.BaselineTestCase.Mode;
31  
32  import javax.xml.namespace.QName;
33  import java.util.ArrayList;
34  import java.util.HashMap;
35  import java.util.List;
36  import java.util.Map;
37  
38  @BaselineMode(Mode.NONE)
39  public class KSKRMSUploadTestCase extends BaselineTestCase {
40  
41      private static final String KRMS_MODULE_NAME = "krms";
42  
43  	protected ContextBoService contextRepository;
44  	protected KrmsTypeRepositoryService krmsTypeRepository;
45  	protected AgendaBoService agendaBoService;
46  	protected RuleBoService ruleBoService;
47  
48  	// Services needed for creation:
49  	protected TermBoService termBoService;
50  	protected SpringResourceLoader krmsTestResourceLoader;
51  
52      private static String KRMS_TEST_SPRING_BEANS = "classpath:KRMSUploadHarnessSpringBeans.xml";
53  
54  	public KSKRMSUploadTestCase() {
55          super(KRMS_MODULE_NAME);
56  		this.setClearTables(false);
57  	}
58  
59      /**
60       * Overridden to set dirty=true each time
61       * @see org.kuali.rice.test.RiceTestCase#setUp()
62       */
63      @Override
64      public void setUp() throws Exception {
65          super.setUp();
66          getLoadApplicationLifecycle();
67          termBoService = KrmsRepositoryServiceLocator.getTermBoService();
68          agendaBoService = KrmsRepositoryServiceLocator.getAgendaBoService();
69          contextRepository = KrmsRepositoryServiceLocator.getContextBoService();
70          ruleBoService = KrmsRepositoryServiceLocator.getRuleBoService();
71          krmsTypeRepository = KrmsRepositoryServiceLocator
72                  .getKrmsTypeRepositoryService();
73      }
74  
75  	@Override
76  	protected void loadSuiteTestData() throws Exception {
77  		// Do nothing
78  	}
79  
80  	@Override
81  	protected List<String> getPerTestTablesNotToClear() {
82  		List<String> tablesNotToClear = super.getPerTestTablesNotToClear();
83  		// tablesNotToClear.add("KRMS_.*");
84  		return tablesNotToClear;
85  	}
86  
87  	@Override
88  	protected Lifecycle getLoadApplicationLifecycle() {
89  		if (krmsTestResourceLoader == null) {
90              List<String> files = new ArrayList<String>();
91              files.add(KRMS_TEST_SPRING_BEANS);
92              if (this.getAdditionalSpringFile() != null){
93                  files.add(getAdditionalSpringFile());
94              }
95              
96  			krmsTestResourceLoader = new SpringResourceLoader(new QName(
97  					"KRMSTestHarnessApplicationResourceLoader"), files, null);
98  			krmsTestResourceLoader
99  					.setParentSpringResourceLoader(getTestHarnessSpringResourceLoader());
100 			getTestHarnessSpringResourceLoader().addResourceLoader(
101 					krmsTestResourceLoader);
102 		}
103 		return krmsTestResourceLoader;
104 	}
105     
106     protected String getAdditionalSpringFile(){
107         return null;
108     }
109 
110 	protected BusinessObjectService getBoService() {
111 		return KRADServiceLocator.getBusinessObjectService();
112 	}
113 	
114 	//@Test
115 	/*public void testHello() {
116 			System.out.println("Test hello");
117 			assertNotNull(termBoService);
118 			assertNotNull(agendaBoService);
119 			assertNotNull(contextRepository);
120 			assertNotNull(ruleBoService);
121 			assertNotNull(krmsTypeRepository);
122 	}*/
123 	
124 	protected AgendaDefinition getKRMSAgenda(String agendaName, ContextDefinition contextDef) {
125 		AgendaDefinition agendaDef = agendaBoService
126 				.getAgendaByNameAndContextId(agendaName,
127 						contextDef.getId());
128 		return agendaDef;
129 	}
130 
131 	//@Test
132 	/*public void testKRMSContext() {
133 		ContextDefinition cnt = getKRMSContext(KSKRMSConstants.CONTEXT_STUD_ELIGIBILITY);
134 		assertNotNull(cnt);
135 		System.out.println(cnt.getDescription());
136 		AgendaDefinition adef = getKRMSAgenda(KSKRMSConstants.AGENDA1, cnt);
137 		assertNotNull(adef);
138 		System.out.println(adef.getName());
139 	}*/
140 
141 	protected ContextDefinition getKRMSContext(String context) {
142 		return contextRepository.getContextByNameAndNamespace(
143 				context, KSKRMSConstants.KSNAMESPACE);
144 	}
145 	
146 	protected TermDefinition krmsTermLookup(String termName) {
147 		// this may be called more than once, we only want to create one though
148 		Map<String, String> queryArgs = new HashMap<String, String>();
149 		queryArgs.put("desc_txt", termName);
150 		TermBo termBo = getBoService()
151 				.findByPrimaryKey(TermBo.class, queryArgs);
152 		if (termBo != null) {
153 			return TermBo.to(termBo);
154 		}
155 		return null;
156 	}
157 	
158 	protected TermResolverDefinition krmsTermResolverLookup(String termResolverName) {
159 		// this may be called more than once, we only want to create one though
160 		Map<String, String> queryArgs = new HashMap<String, String>();
161 		queryArgs.put("nm", termResolverName);
162 		TermResolverBo termBo = getBoService()
163 				.findByPrimaryKey(TermResolverBo.class, queryArgs);
164 		if (termBo != null) {
165 			return TermResolverBo.to(termBo);
166 		}
167 		return null;
168 	}
169 	
170 }