01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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.outerj.daisy.xmlutil.test;
17:
18: import junit.framework.TestCase;
19:
20: import java.util.Properties;
21:
22: import org.outerj.daisy.configutil.PropertyResolver;
23:
24: public class PropertyResolverTest extends TestCase {
25:
26: public void testPropertyResolving() throws Exception {
27: Properties properties = new Properties();
28: properties.setProperty("prop1", "val1");
29: properties.setProperty("prop2", "special things : / %");
30: properties.setProperty("space", " ");
31:
32: String resolved = PropertyResolver.resolveProperties(
33: "foo ${prop1} bar", properties);
34: assertEquals("foo val1 bar", resolved);
35:
36: resolved = PropertyResolver.resolveProperties("$", properties);
37: assertEquals("$", resolved);
38:
39: resolved = PropertyResolver.resolveProperties(
40: "foo ${prop1} bar$", properties);
41: assertEquals("foo val1 bar$", resolved);
42:
43: resolved = PropertyResolver.resolveProperties(
44: "foo ${prop1} bar${", properties);
45: assertEquals("foo val1 bar${", resolved);
46:
47: resolved = PropertyResolver
48: .resolveProperties(
49: "foo ${prop1} ${url-encode:${prop2}}${url-encode: } bar",
50: properties);
51: assertEquals("foo val1 special+things+%3A+%2F+%25++ bar",
52: resolved);
53:
54: resolved = PropertyResolver.resolveProperties(
55: "foo ${prop1} ${stupid${stuff${at${the${end}}}}}",
56: properties);
57: assertEquals("foo val1 ${stupid${stuff${at${the${end}}}}}",
58: resolved);
59:
60: resolved = PropertyResolver.resolveProperties(
61: "foo ${prop1} ${stupid${stuff${at${the${end",
62: properties);
63: assertEquals("foo val1 ${stupid${stuff${at${the${end", resolved);
64:
65: resolved = PropertyResolver.resolveProperties(
66: "foo ${prop1} ${stupid${stuff${at${the${end}",
67: properties);
68: assertEquals("foo val1 ${stupid${stuff${at${the${end}",
69: resolved);
70:
71: resolved = PropertyResolver.resolveProperties(
72: "foo ${prop1} ${end", properties);
73: assertEquals("foo val1 ${end", resolved);
74:
75: resolved = PropertyResolver.resolveProperties(
76: "${tripple-url-encode: }", properties);
77: assertEquals("%252B", resolved);
78:
79: resolved = PropertyResolver
80: .resolveProperties(
81: "${tripple-url-encode:${space}other/stuff}",
82: properties);
83: assertEquals("%252Bother%25252Fstuff", resolved);
84: }
85: }
|