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.property;
17  
18  import java.util.Properties;
19  
20  import org.junit.Test;
21  import org.springframework.util.PropertyPlaceholderHelper;
22  
23  public class EscapingPropertyPlaceholderHelperTest {
24  
25  	@Test
26  	public void test() {
27  		PropertyPlaceholderHelper helper = Constants.DEFAULT_PROPERTY_PLACEHOLDER_HELPER;
28  		Properties properties = new Properties();
29  		properties.setProperty("a", "1");
30  		properties.setProperty("b", "2");
31  		properties.setProperty("d", "5");
32  		properties.setProperty("1.2", "foo");
33  		String original = "\\${${a}.${b}} ${${a}.${b}} ${c:${d:4}} \\${foo";
34  		String resolved = helper.replacePlaceholders(original, properties);
35  		System.out.println(resolved);
36  	}
37  
38  	@Test
39  	public void test1() {
40  		PropertyPlaceholderHelper helper = Constants.DEFAULT_PROPERTY_PLACEHOLDER_HELPER;
41  		Properties properties = new Properties();
42  		properties.setProperty("kuali.encoding", "UTF-8");
43  		String original = "kuali.encoding=${kuali.encoding}  \\${user.home}";
44  		String resolved = helper.replacePlaceholders(original, properties);
45  		System.out.println(resolved);
46  	}
47  }