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