View Javadoc

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