1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
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 }