KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > search > TestCmsSearchUtils


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/search/TestCmsSearchUtils.java,v $
3  * Date : $Date: 2005/06/27 23:22:25 $
4  * Version: $Revision: 1.5 $
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.search;
33
34 import junit.framework.TestCase;
35
36 /**
37  * Tests some search utils that don't require an OpenCms context.<p>
38  *
39  * @author Alexander Kandzior
40  * @version $Revision: 1.5 $
41  */

42 public class TestCmsSearchUtils extends TestCase {
43
44     /**
45      * Default JUnit constructor.<p>
46      *
47      * @param arg0 JUnit parameters
48      */

49     public TestCmsSearchUtils(String JavaDoc arg0) {
50
51         super(arg0);
52     }
53
54     /**
55      * Test root path term splitting.<p>
56      *
57      * @throws Exception if the test fails
58      */

59     public void testRootPathTokenizer() throws Exception JavaDoc {
60
61         String JavaDoc t = CmsSearchIndex.ROOT_PATH_TOKEN;
62         String JavaDoc s = CmsSearchIndex.ROOT_PATH_SUFFIX;
63
64         assertEquals(t, CmsSearchIndex.rootPathRewrite(null));
65         assertEquals(t, CmsSearchIndex.rootPathRewrite(""));
66         assertEquals(t, CmsSearchIndex.rootPathRewrite("/"));
67         assertEquals(t + " sites" + s, CmsSearchIndex.rootPathRewrite("/sites/"));
68         assertEquals(t + " sites" + s, CmsSearchIndex.rootPathRewrite("/sites"));
69         assertEquals(t + " sites" + s + " default" + s, CmsSearchIndex.rootPathRewrite("/sites/default/"));
70         assertEquals(t + " sites" + s + " default" + s, CmsSearchIndex.rootPathRewrite("/sites/default"));
71
72         assertStringArray(new String JavaDoc[] {t}, CmsSearchIndex.rootPathSplit("/"));
73         assertStringArray(new String JavaDoc[] {t, "sites" + s}, CmsSearchIndex.rootPathSplit("/sites/"));
74         assertStringArray(new String JavaDoc[] {t, "sites" + s}, CmsSearchIndex.rootPathSplit("/sites"));
75         assertStringArray(new String JavaDoc[] {t, "sites" + s, "default" + s}, CmsSearchIndex.rootPathSplit("/sites/default/"));
76         assertStringArray(new String JavaDoc[] {t, "sites" + s, "default" + s}, CmsSearchIndex.rootPathSplit("/sites/default"));
77
78     }
79
80     /**
81      * Asserts that 2 String arrays are equal.<p>
82      * @param a the first array to compare
83      * @param b the second array to compare
84      */

85     public void assertStringArray(String JavaDoc[] a, String JavaDoc[] b) {
86
87         if ((a == null) || (b == null)) {
88             assertTrue(a == b);
89         }
90         assertEquals(a.length, b.length);
91         for (int i = 0; i < a.length; i++) {
92             assertEquals(a[i], b[i]);
93         }
94     }
95 }
Popular Tags