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