1 package org.kuali.db;
2
3 import static org.junit.Assert.*;
4
5 import java.io.IOException;
6 import java.util.Properties;
7
8 import org.junit.Test;
9 import org.springframework.util.PropertyPlaceholderHelper;
10
11 import org.kuali.rice.core.config.ConfigContext;
12 import org.kuali.rice.core.config.JAXBConfigImpl;
13
14 public class PropertyPlaceholderHelperTest {
15
16 @Test
17 public void replacePlaceholders() {
18 Properties properties = new Properties();
19 properties.put("schema", "KSEMBEDDED");
20 String value = "DROP USER ${schema} CASCADE;";
21 PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
22 value = helper.replacePlaceholders(value, properties);
23 assertEquals(value, "DROP USER KSEMBEDDED CASCADE;");
24 }
25
26 @Test
27 public void nestedProperties() {
28 Properties properties = new Properties();
29 properties.put("db.vendor", "derby");
30 properties.put("datasource.url.oracle", "jdbc:oracle:thin:@localhost:1521:XE");
31 properties.put("datasource.url.derby", "jdbc:derby://localhost:1527/derby/rice-db;create=true");
32 properties.put("datasource.url", "${datasource.url.${db.vendor}}");
33 PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${", "}");
34 String value = "${datasource.url}";
35 value = helper.replacePlaceholders(value, properties);
36
37 }
38
39 @Test
40 public void configContext() throws IOException {
41 JAXBConfigImpl config = new JAXBConfigImpl("classpath:standalone-config.xml", ConfigContext.getCurrentContextConfig());
42 config.setSystemOverride(true);
43 config.parseConfig();
44 ConfigContext.init(config);
45 Properties properties = config.getProperties();
46 System.out.println(properties.getProperty("environment"));
47 System.out.println(properties.getProperty("s"));
48 }
49
50 }