1
2
3
4
5
6
7
8
9
10
11 package org.mule.util;
12
13 import org.mule.tck.AbstractMuleTestCase;
14
15 import java.text.NumberFormat;
16 import java.util.HashMap;
17 import java.util.Map;
18
19 import org.apache.commons.collections.keyvalue.DefaultMapEntry;
20
21 public class PropertiesUtilsTestCase extends AbstractMuleTestCase
22 {
23
24 public void testRemoveNameSpacePrefix()
25 {
26 String temp = "this.is.a.namespace";
27 String result = PropertiesUtils.removeNamespacePrefix(temp);
28 assertEquals("namespace", result);
29
30 temp = "this.namespace";
31 result = PropertiesUtils.removeNamespacePrefix(temp);
32 assertEquals("namespace", result);
33
34 temp = "namespace";
35 result = PropertiesUtils.removeNamespacePrefix(temp);
36 assertEquals("namespace", result);
37
38 temp = "this_is-a-namespace";
39 result = PropertiesUtils.removeNamespacePrefix(temp);
40 assertEquals("this_is-a-namespace", result);
41 }
42
43 public void testRemoveXMLNameSpacePrefix()
44 {
45 String temp = "j:namespace";
46 String result = PropertiesUtils.removeXmlNamespacePrefix(temp);
47 assertEquals("namespace", result);
48
49 temp = "this-namespace";
50 result = PropertiesUtils.removeNamespacePrefix(temp);
51 assertEquals("this-namespace", result);
52
53 temp = "namespace";
54 result = PropertiesUtils.removeNamespacePrefix(temp);
55 assertEquals("namespace", result);
56 }
57
58 public void testRemoveNamespaces() throws Exception
59 {
60 Map props = new HashMap();
61
62 props.put("blah.booleanProperty", "true");
63 props.put("blah.blah.doubleProperty", NumberFormat.getInstance().format(0.124));
64 props.put("blah.blah.Blah.intProperty", "14");
65 props.put("longProperty", "999999999");
66 props.put("3456.stringProperty", "string");
67
68 props = PropertiesUtils.removeNamespaces(props);
69
70 assertTrue(MapUtils.getBooleanValue(props, "booleanProperty", false));
71 assertEquals(0.124, 0, MapUtils.getDoubleValue(props, "doubleProperty", 0));
72 assertEquals(14, MapUtils.getIntValue(props, "intProperty", 0));
73 assertEquals(999999999, 0, MapUtils.getLongValue(props, "longProperty", 0));
74 assertEquals("string", MapUtils.getString(props, "stringProperty", ""));
75 }
76
77 public void testMaskedProperties()
78 {
79
80 assertNull(PropertiesUtils.maskedPropertyValue(null));
81 assertNull(PropertiesUtils.maskedPropertyValue(new DefaultMapEntry(null, "value")));
82 assertNull(PropertiesUtils.maskedPropertyValue(new DefaultMapEntry("key", null)));
83
84
85 Map.Entry property = new DefaultMapEntry("secretname", "secret");
86 assertTrue("secret".equals(PropertiesUtils.maskedPropertyValue(property)));
87
88
89 PropertiesUtils.registerMaskedPropertyName("secretname");
90 String masked = PropertiesUtils.maskedPropertyValue(property);
91 assertFalse("secret".equals(masked));
92 assertTrue(masked.startsWith("*"));
93 }
94
95 }