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.ksb.messaging.resourceloading;
17  
18  import java.util.Properties;
19  
20  import org.junit.Test;
21  import org.kuali.rice.core.api.CoreConstants;
22  import org.kuali.rice.core.api.config.ConfigurationException;
23  import org.kuali.rice.core.api.config.property.Config;
24  import org.kuali.rice.core.api.config.property.ConfigContext;
25  import org.kuali.rice.core.api.resourceloader.ResourceLoader;
26  import org.kuali.rice.core.impl.config.property.ConfigParserImplConfig;
27  import org.kuali.rice.core.impl.config.property.JAXBConfigImpl;
28  import org.kuali.rice.core.framework.config.property.SimpleConfig;
29  import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory;
30  
31  import static org.junit.Assert.*;
32  
33  public class KSBResourceLoaderFactoryTest {
34  
35  	private static String simpleConfig = "SIMPLE_CONFIG";
36  	private static String jaxbConfig = "JAXB_CONFIG";
37  	
38  	
39  	// We want to test with both impls
40  	protected Config getConfigObject(String configType, Properties p){
41  		Config cRet = null;
42  		if(simpleConfig.equals(configType)){
43  			cRet = new ConfigParserImplConfig(p);
44  		}else if(jaxbConfig.equals(configType)){
45  			cRet = new JAXBConfigImpl(p);
46  		}
47  		return cRet;
48  	}
49  	
50  	@Test public void testCreateKSBResourceLoader() throws Exception {
51  		createKSBResourceLoaderImpl(simpleConfig);
52  		createKSBResourceLoaderImpl(jaxbConfig);
53  	}
54  	protected void createKSBResourceLoaderImpl(String configType) throws Exception {
55  		String me = "TestME";
56  		Properties props = new Properties();
57  		props.put(CoreConstants.Config.APPLICATION_ID, me);
58  		Config config = getConfigObject(configType, props);
59  		config.parseConfig();
60  		ConfigContext.init(config);
61  		
62  		ResourceLoader rl = KSBResourceLoaderFactory.createRootKSBRemoteResourceLoader();
63  		assertNotNull(rl.getResourceLoader(KSBResourceLoaderFactory.getRemoteResourceLoaderName()));
64  	}
65  	
66  	@Test public void testCreateKSBResourceLoaderNoApplicationId() throws Exception {
67  		createKSBResourceLoaderNoApplicationIdImpl(simpleConfig);
68  		createKSBResourceLoaderNoApplicationIdImpl(jaxbConfig);
69  		
70  	}
71  	
72  	protected void createKSBResourceLoaderNoApplicationIdImpl(String configType) throws Exception {
73  		
74  		Properties props = new Properties();
75  		Config config = getConfigObject(configType,props);
76  		config.parseConfig();
77  		ConfigContext.init(config);
78  		
79  		boolean errorThrown = false;
80  		try {
81  			KSBResourceLoaderFactory.createRootKSBRemoteResourceLoader();
82  			fail("should have thrown configuration exception with no applicationId present");
83  		} catch (IllegalStateException ce) {
84  			errorThrown = true;
85  		}
86  		assertTrue(errorThrown);
87  	}
88  	
89  }