1 31 32 package org.opencms.xml; 33 34 import junit.framework.TestCase; 35 36 43 public class TestXmlUtils extends TestCase { 44 45 50 public void testCreateXpath() throws Exception { 51 52 assertEquals("Title[1]", CmsXmlUtils.createXpath("Title", 1)); 53 assertEquals("Title[1]/Test[1]", CmsXmlUtils.createXpath("Title/Test", 1)); 54 assertEquals("Title[1]/Test[1]/Toast[1]", CmsXmlUtils.createXpath("Title/Test/Toast", 1)); 55 assertEquals("Title[4]/Test[2]/Toast[1]", CmsXmlUtils.createXpath("Title[4]/Test[2]/Toast[1]", 1)); 56 assertEquals("Title[1]/Test[2]/Toast[2]", CmsXmlUtils.createXpath("Title/Test[2]/Toast", 2)); 57 assertEquals("Title[1]/Test[1]/Toast[1]/Toll[5]", CmsXmlUtils.createXpath("Title/Test/Toast/Toll", 5)); 58 } 59 60 65 public void testGetXpathIndex() throws Exception { 66 67 assertEquals("", CmsXmlUtils.getXpathIndex("Title")); 68 assertEquals("[1]", CmsXmlUtils.getXpathIndex("Title[1]")); 69 assertEquals("[1]", CmsXmlUtils.getXpathIndex("Title[4]/Test[2]/Toast[1]")); 70 assertEquals("", CmsXmlUtils.getXpathIndex("Title/Test[2]/Toast")); 71 assertEquals("[5]", CmsXmlUtils.getXpathIndex("Title/Test/Toast/Toll[5]")); 72 } 73 74 79 public void testRemoveXpath() throws Exception { 80 81 assertEquals("Title", CmsXmlUtils.removeXpath("Title[1]")); 82 assertEquals("Title/Test", CmsXmlUtils.removeXpath("Title[1]/Test[1]")); 83 assertEquals("Title/Test/Toast", CmsXmlUtils.removeXpath("Title[1]/Test[1]/Toast")); 84 assertEquals("Title/Test/Toast", CmsXmlUtils.removeXpath("Title/Test[2]/Toast[1]")); 85 assertEquals("Title/Test/Toast", CmsXmlUtils.removeXpath("Title/Test[2]/Toast")); 86 assertEquals("Title/Test/Toast/Toll", CmsXmlUtils.removeXpath("Title[1]/Test[1]/Toast[1]/Toll[5]")); 87 } 88 89 94 public void testSimplifyXpath() throws Exception { 95 96 assertEquals("Title[1]", CmsXmlUtils.simplifyXpath("/Title[1]")); 97 assertEquals("Title[1]", CmsXmlUtils.simplifyXpath("Title[1]/")); 98 assertEquals("Title[1]", CmsXmlUtils.simplifyXpath("/Title[1]/")); 99 100 assertEquals("Title", CmsXmlUtils.simplifyXpath("/Title")); 101 assertEquals("Title", CmsXmlUtils.simplifyXpath("Title/")); 102 assertEquals("Title", CmsXmlUtils.simplifyXpath("/Title/")); 103 } 104 } 105 | Popular Tags |