1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.service;
17
18 import java.io.File;
19 import java.util.List;
20 import java.util.Properties;
21
22 import org.junit.Ignore;
23 import org.junit.Test;
24 import org.kuali.common.util.LocationUtils;
25 import org.springframework.context.support.ClassPathXmlApplicationContext;
26
27 public class SpringContextLoadingTest {
28
29 @Test
30 @Ignore
31 public void test() {
32 try {
33
34 Properties properties = new Properties();
35 properties.setProperty("spring.message", "Good bye!");
36
37 ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext();
38 parent.refresh();
39 parent.getBeanFactory().registerSingleton("properties", properties);
40
41 String location1 = "classpath:org/kuali/common/util/child-context.xml";
42 String location2 = "/Users/jeffcaddel/ws/kuali-util/src/test/resources/org/kuali/common/util/child-context.xml";
43 String[] locations = getLocations(new String[] { location1, location2 });
44
45 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(locations, false, parent);
46 context.refresh();
47 context.close();
48 } catch (Exception e) {
49 e.printStackTrace();
50 }
51 }
52
53 protected String[] getLocations(List<String> locations) {
54 return getLocations(locations.toArray(new String[locations.size()]));
55 }
56
57 protected String[] getLocations(String[] locations) {
58 for (int i = 0; i < locations.length; i++) {
59 String location = locations[i];
60 if (!LocationUtils.exists(location)) {
61 throw new IllegalArgumentException("Location [" + location + "] does not exist");
62 }
63 if (LocationUtils.isExistingFile(location)) {
64 File file = new File(location);
65 locations[i] = LocationUtils.getURLString(file);
66 }
67 }
68 return locations;
69 }
70 }