View Javadoc

1   /**
2    * Copyright 2010-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }