KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > xml > TestXmlUtils


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/xml/TestXmlUtils.java,v $
3  * Date : $Date: 2005/06/23 14:27:27 $
4  * Version: $Revision: 1.7 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.xml;
33
34 import junit.framework.TestCase;
35
36 /**
37  * @author Alexander Kandzior
38  *
39  * @version $Revision: 1.7 $
40  *
41  * @since 6.0.0
42  */

43 public class TestXmlUtils extends TestCase {
44
45     /**
46      * Test case for the Xpath generation methods.
47      *
48      * @throws Exception in case the test fails
49      */

50     public void testCreateXpath() throws Exception JavaDoc {
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     /**
61      * Test case for the Xpath index cut off.
62      *
63      * @throws Exception in case the test fails
64      */

65     public void testGetXpathIndex() throws Exception JavaDoc {
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     /**
75      * Test case for the Xpath remove methods.
76      *
77      * @throws Exception in case the test fails
78      */

79     public void testRemoveXpath() throws Exception JavaDoc {
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     /**
90      * Test case for the Xpath simplification.
91      *
92      * @throws Exception in case the test fails
93      */

94     public void testSimplifyXpath() throws Exception JavaDoc {
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