KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > util > PropertyExpanderTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. The ASF licenses this file to You
4  * under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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. For additional information regarding
15  * copyright in this work, please see the NOTICE file in the top level
16  * directory of this distribution.
17  */

18
19 package org.apache.roller.util;
20
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import junit.framework.TestCase;
25
26 /**
27  * Unit test for org.apache.roller.util.PropertyExpander.
28  *
29  * @author <a HREF="mailto:anil@busybuddha.org">Anil Gangolli</a>
30  */

31 public class PropertyExpanderTest extends TestCase
32 {
33     private static final Map JavaDoc props = new HashMap JavaDoc();
34
35     static
36     {
37         props.put("defined.property.one", "value one");
38         props.put("defined.property.two", "value two");
39         props.put("defined.property.with.dollar.sign.in.value", "$2");
40     }
41
42     public void testExpansion() throws Exception JavaDoc
43     {
44         String JavaDoc expanded =
45             PropertyExpander.expandProperties("String with ${defined.property.one} and ${defined.property.two} and ${defined.property.with.dollar.sign.in.value} and ${undefined.property} and some stuff.", props);
46
47         assertEquals("Expanded string doesn't match expected",
48             "String with value one and value two and $2 and ${undefined.property} and some stuff.",
49             expanded);
50     }
51
52     public void testSystemProperty() throws Exception JavaDoc
53     {
54         String JavaDoc expanded =
55             PropertyExpander.expandSystemProperties("${java.home}");
56         assertEquals("Expanded string doesn't match expected",
57             System.getProperty("java.home"),
58             expanded);
59     }
60
61 }
62
Popular Tags