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