001 /** 002 * Copyright 2010-2012 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.common.util.service; 017 018 import java.io.File; 019 import java.util.List; 020 import java.util.Properties; 021 022 import org.junit.Test; 023 import org.kuali.common.util.LocationUtils; 024 import org.springframework.context.support.ClassPathXmlApplicationContext; 025 026 public class SpringContextLoadingTest { 027 028 @Test 029 public void test() { 030 try { 031 032 Properties properties = new Properties(); 033 properties.setProperty("spring.message", "Good bye!"); 034 035 ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext(); 036 parent.refresh(); 037 parent.getBeanFactory().registerSingleton("properties", properties); 038 039 String location1 = "classpath:org/kuali/common/util/child-context.xml"; 040 String location2 = "/Users/jeffcaddel/ws/kuali-util/src/test/resources/org/kuali/common/util/child-context.xml"; 041 String[] locations = getLocations(new String[] { location1, location2 }); 042 043 ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(locations, false, parent); 044 context.refresh(); 045 } catch (Exception e) { 046 e.printStackTrace(); 047 } 048 } 049 050 protected String[] getLocations(List<String> locations) { 051 return getLocations(locations.toArray(new String[locations.size()])); 052 } 053 054 protected String[] getLocations(String[] locations) { 055 for (int i = 0; i < locations.length; i++) { 056 String location = locations[i]; 057 if (!LocationUtils.exists(location)) { 058 throw new IllegalArgumentException("Location [" + location + "] does not exist"); 059 } 060 if (LocationUtils.isExistingFile(location)) { 061 File file = new File(location); 062 locations[i] = LocationUtils.getURLString(file); 063 } 064 } 065 return locations; 066 } 067 }