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.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
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 }