1 16 17 package org.apache.commons.betwixt; 18 19 import junit.framework.Test; 20 import junit.framework.TestSuite; 21 import junit.textui.TestRunner; 22 23 28 public class TestXMLUtils extends AbstractTestCase { 29 30 public static void main( String [] args ) { 31 TestRunner.run( suite() ); 32 } 33 34 public static Test suite() { 35 return new TestSuite(TestXMLUtils.class); 36 } 37 38 public TestXMLUtils(String testName) { 39 super(testName); 40 } 41 42 45 public void testXMLNameTest() { 46 assertEquals("Testing name 'Name<'", false, XMLUtils.isWellFormedXMLName("Name<")); 48 assertEquals("Testing name 'Name>'", false, XMLUtils.isWellFormedXMLName("Name>")); 49 assertEquals("Testing name 'Name''", false, XMLUtils.isWellFormedXMLName("Name'")); 50 assertEquals("Testing name 'Name_:-.'", true, XMLUtils.isWellFormedXMLName("Name_:-.")); 51 assertEquals("Testing name '.Name'", false, XMLUtils.isWellFormedXMLName(".Name")); 52 assertEquals("Testing name '-Name'", false, XMLUtils.isWellFormedXMLName("-Name")); 53 assertEquals("Testing name ':Name'", true, XMLUtils.isWellFormedXMLName(":Name")); 54 assertEquals("Testing name '_Name'", true, XMLUtils.isWellFormedXMLName("_Name")); 55 assertEquals("Testing name 'A0123456789Name", true, XMLUtils.isWellFormedXMLName("A0123456789Name")); 56 } 57 58 59 public void testAttributeEscaping() { 60 assertEquals("Escaping: <", "<", XMLUtils.escapeAttributeValue("<")); 61 assertEquals("Escaping: >", ">", XMLUtils.escapeAttributeValue(">")); 62 assertEquals("Escaping: '", "'", XMLUtils.escapeAttributeValue("'")); 63 assertEquals("Escaping: \"", """, XMLUtils.escapeAttributeValue("\"")); 64 assertEquals("Escaping: &", "&", XMLUtils.escapeAttributeValue("&")); 65 assertEquals("Escaping: 1<", "1<", XMLUtils.escapeAttributeValue("1<")); 66 assertEquals("Escaping: 1>", "1>", XMLUtils.escapeAttributeValue("1>")); 67 assertEquals("Escaping: 1'", "1'", XMLUtils.escapeAttributeValue("1'")); 68 assertEquals("Escaping: 1\"", "1"", XMLUtils.escapeAttributeValue("1\"")); 69 assertEquals("Escaping: 1&", "1&", XMLUtils.escapeAttributeValue("1&")); 70 assertEquals("Escaping: <2", "<2", XMLUtils.escapeAttributeValue("<2")); 71 assertEquals("Escaping: >2", ">2", XMLUtils.escapeAttributeValue(">2")); 72 assertEquals("Escaping: '2", "'2", XMLUtils.escapeAttributeValue("'2")); 73 assertEquals("Escaping: \"2", ""2", XMLUtils.escapeAttributeValue("\"2")); 74 assertEquals("Escaping: &2", "&2", XMLUtils.escapeAttributeValue("&2")); 75 assertEquals("Escaping: a<b", "a<b", XMLUtils.escapeAttributeValue("a<b")); 76 assertEquals("Escaping: a>b", "a>b", XMLUtils.escapeAttributeValue("a>b")); 77 assertEquals("Escaping: a'b", "a'b", XMLUtils.escapeAttributeValue("a'b")); 78 assertEquals("Escaping: a\"b", "a"b", XMLUtils.escapeAttributeValue("a\"b")); 79 assertEquals("Escaping: a&b", "a&b", XMLUtils.escapeAttributeValue("a&b")); 80 assertEquals("Escaping: <<abba", "<<abba", XMLUtils.escapeAttributeValue("<<abba")); 81 assertEquals("Escaping: >>abba", ">>abba", XMLUtils.escapeAttributeValue(">>abba")); 82 assertEquals("Escaping: ''abba", "''abba", XMLUtils.escapeAttributeValue("''abba")); 83 assertEquals("Escaping: \"\"abba", """abba", XMLUtils.escapeAttributeValue("\"\"abba")); 84 assertEquals("Escaping: &&abba", "&&abba", XMLUtils.escapeAttributeValue("&&abba")); 85 assertEquals( 86 "Escaping: a<>b''c\"e>f'&g", 87 "a<>b''c"e>f'&g", 88 XMLUtils.escapeAttributeValue("a<>b''c\"e>f'&g")); 89 90 } 91 92 98 public void testCDATAEscaping() { 99 assertEquals("Escaping: <", "<", XMLUtils.escapeCDATAContent("<")); 100 assertEquals("Escaping: >", ">", XMLUtils.escapeCDATAContent(">")); 101 assertEquals("Escaping: '", "'", XMLUtils.escapeCDATAContent("'")); 102 assertEquals("Escaping: \"", "\"", XMLUtils.escapeCDATAContent("\"")); 103 assertEquals("Escaping: &", "&", XMLUtils.escapeCDATAContent("&")); 104 assertEquals("Escaping: ]]", "]]", XMLUtils.escapeCDATAContent("]]")); 105 assertEquals("Escaping: ]>", "]>", XMLUtils.escapeCDATAContent("]>")); 106 assertEquals("Escaping: ]]>", "]]>", XMLUtils.escapeCDATAContent("]]>")); 107 assertEquals("Escaping: ]]>]]>", "]]>]]>", XMLUtils.escapeCDATAContent("]]>]]>")); 108 assertEquals("Escaping: ]>]]>", "]>]]>", XMLUtils.escapeCDATAContent("]>]]>")); 109 assertEquals("Escaping: ]]>]]]>", "]]>]]]>", XMLUtils.escapeCDATAContent("]]>]]]>")); 110 assertEquals("Escaping: ", "", XMLUtils.escapeCDATAContent("")); 111 } 112 113 114 } 115 116 | Popular Tags |