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.kuali.rice.ksb.messaging.resourceloading;
017
018 import java.util.Properties;
019
020 import org.junit.Test;
021 import org.kuali.rice.core.api.CoreConstants;
022 import org.kuali.rice.core.api.config.ConfigurationException;
023 import org.kuali.rice.core.api.config.property.Config;
024 import org.kuali.rice.core.api.config.property.ConfigContext;
025 import org.kuali.rice.core.api.resourceloader.ResourceLoader;
026 import org.kuali.rice.core.impl.config.property.ConfigParserImplConfig;
027 import org.kuali.rice.core.impl.config.property.JAXBConfigImpl;
028 import org.kuali.rice.core.framework.config.property.SimpleConfig;
029 import org.kuali.rice.ksb.messaging.resourceloader.KSBResourceLoaderFactory;
030
031 import static org.junit.Assert.*;
032
033 public class KSBResourceLoaderFactoryTest {
034
035 private static String simpleConfig = "SIMPLE_CONFIG";
036 private static String jaxbConfig = "JAXB_CONFIG";
037
038
039 // We want to test with both impls
040 protected Config getConfigObject(String configType, Properties p){
041 Config cRet = null;
042 if(simpleConfig.equals(configType)){
043 cRet = new ConfigParserImplConfig(p);
044 }else if(jaxbConfig.equals(configType)){
045 cRet = new JAXBConfigImpl(p);
046 }
047 return cRet;
048 }
049
050 @Test public void testCreateKSBResourceLoader() throws Exception {
051 createKSBResourceLoaderImpl(simpleConfig);
052 createKSBResourceLoaderImpl(jaxbConfig);
053 }
054 protected void createKSBResourceLoaderImpl(String configType) throws Exception {
055 String me = "TestME";
056 Properties props = new Properties();
057 props.put(CoreConstants.Config.APPLICATION_ID, me);
058 Config config = getConfigObject(configType, props);
059 config.parseConfig();
060 ConfigContext.init(config);
061
062 ResourceLoader rl = KSBResourceLoaderFactory.createRootKSBRemoteResourceLoader();
063 assertNotNull(rl.getResourceLoader(KSBResourceLoaderFactory.getRemoteResourceLoaderName()));
064 }
065
066 @Test public void testCreateKSBResourceLoaderNoApplicationId() throws Exception {
067 createKSBResourceLoaderNoApplicationIdImpl(simpleConfig);
068 createKSBResourceLoaderNoApplicationIdImpl(jaxbConfig);
069
070 }
071
072 protected void createKSBResourceLoaderNoApplicationIdImpl(String configType) throws Exception {
073
074 Properties props = new Properties();
075 Config config = getConfigObject(configType,props);
076 config.parseConfig();
077 ConfigContext.init(config);
078
079 boolean errorThrown = false;
080 try {
081 KSBResourceLoaderFactory.createRootKSBRemoteResourceLoader();
082 fail("should have thrown configuration exception with no applicationId present");
083 } catch (IllegalStateException ce) {
084 errorThrown = true;
085 }
086 assertTrue(errorThrown);
087 }
088
089 }