KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > staticexport > TestCmsLinkManager


1 /*
2  * File : $Source: /usr/local/cvs/opencms/test/org/opencms/staticexport/TestCmsLinkManager.java,v $
3  * Date : $Date: 2006/10/18 09:29:05 $
4  * Version: $Revision: 1.9 $
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.staticexport;
33
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.OpenCms;
36 import org.opencms.test.OpenCmsTestCase;
37 import org.opencms.test.OpenCmsTestProperties;
38
39 import junit.extensions.TestSetup;
40 import junit.framework.Test;
41 import junit.framework.TestSuite;
42
43 /**
44  * @author Alexander Kandzior
45  *
46  * @version $Revision: 1.9 $
47  *
48  * @since 6.0.0
49  */

50 public class TestCmsLinkManager extends OpenCmsTestCase {
51
52     /**
53      * Default JUnit constructor.<p>
54      *
55      * @param arg0 JUnit parameters
56      */

57     public TestCmsLinkManager(String JavaDoc arg0) {
58
59         super(arg0);
60     }
61
62     /**
63      * Test suite for this test class.<p>
64      *
65      * @return the test suite
66      */

67     public static Test suite() {
68
69         OpenCmsTestProperties.initialize(org.opencms.test.AllTests.TEST_PROPERTIES_PATH);
70
71         TestSuite suite = new TestSuite();
72         suite.setName(TestCmsLinkManager.class.getName());
73
74         suite.addTest(new TestCmsLinkManager("testToAbsolute"));
75         suite.addTest(new TestCmsLinkManager("testLinkSubstitution"));
76
77         TestSetup wrapper = new TestSetup(suite) {
78
79             protected void setUp() {
80
81                 setupOpenCms("simpletest", "/sites/default/");
82             }
83
84             protected void tearDown() {
85
86                 removeOpenCms();
87             }
88
89         };
90
91         return wrapper;
92     }
93     
94     /**
95      * Tests the method getAbsoluteUri.<p>
96      */

97     public void testToAbsolute() {
98
99         String JavaDoc test;
100
101         test = CmsLinkManager.getRelativeUri("/dir1/dir2/index.html", "/dir1/dirB/index.html");
102         System.out.println(test);
103         assertEquals(test, "../dirB/index.html");
104
105         test = CmsLinkManager.getRelativeUri("/exp/en/test/index.html", "/exp/de/test/index.html");
106         System.out.println(test);
107         assertEquals(test, "../../de/test/index.html");
108
109         test = CmsLinkManager.getAbsoluteUri("../../index.html", "/dir1/dir2/dir3/");
110         System.out.println(test);
111         assertEquals(test, "/dir1/index.html");
112
113         test = CmsLinkManager.getAbsoluteUri("./../././.././dir2/./../index.html", "/dir1/dir2/dir3/");
114         System.out.println(test);
115         assertEquals(test, "/dir1/index.html");
116
117         test = CmsLinkManager.getAbsoluteUri("/dirA/index.html", "/dir1/dir2/dir3/");
118         System.out.println(test);
119         assertEquals(test, "/dirA/index.html");
120     }
121     
122     /**
123      * Tests the link substitution.<p>
124      * @throws Exception
125      */

126     public void testLinkSubstitution() throws Exception JavaDoc {
127         
128         String JavaDoc test;
129         CmsObject cms = getCmsObject();
130         echo("Testing link substitution");
131         
132         cms.getRequestContext().setCurrentProject(cms.readProject("Online"));
133         CmsLinkManager linkManager = OpenCms.getLinkManager();
134         test = linkManager.substituteLink(cms, "/folder1/index.html?additionalParam", "/sites/default");
135         System.out.println(test);
136         assertEquals("/data/opencms/folder1/index.html?additionalParam", test);
137
138         test = linkManager.substituteLink(
139             cms,
140             CmsLinkManager.getAbsoluteUri("/", "/folder1/index.html"),
141             "/sites/default");
142         System.out.println(test);
143         assertEquals("/data/opencms/", test);
144
145         test = linkManager.substituteLink(
146             cms,
147             CmsLinkManager.getAbsoluteUri("./", "/folder1/index.html"),
148             "/sites/default");
149         System.out.println(test);
150         assertEquals("/data/opencms/folder1/", test);
151                 
152         test = CmsLinkManager.getRelativeUri("/index.html", "/index.html");
153         System.out.println(test);
154         assertEquals("index.html", test);
155         
156         test = CmsLinkManager.getRelativeUri("/folder1/index.html", "/folder1/");
157         System.out.println(test);
158         assertEquals("./", test);
159         
160         test = CmsLinkManager.getRelativeUri("/index.html", "/");
161         System.out.println(test);
162         assertEquals("./", test);
163         
164         test = CmsLinkManager.getRelativeUri("/index.html", "./");
165         System.out.println(test);
166         assertEquals("./", test);
167         
168         test = CmsLinkManager.getRelativeUri("/", "/");
169         System.out.println(test);
170         assertEquals("./", test);
171     }
172 }
173
Popular Tags