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