KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > util > LinkUtilTest


1 /**
2  *
3  * Magnolia and its source-code is licensed under the LGPL.
4  * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5  * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6  * you are required to provide proper attribution to obinary.
7  * If you reproduce or distribute the document without making any substantive modifications to its content,
8  * please use the following attribution line:
9  *
10  * Copyright 1993-2006 obinary Ltd. (http://www.obinary.com) All rights reserved.
11  *
12  */

13 package info.magnolia.cms.util;
14
15 import junit.framework.TestCase;
16
17 /**
18  * @author gjoseph
19  * @version $Revision: $ ($Author: $)
20  */

21 public class LinkUtilTest extends TestCase {
22     public void testInternalRelativeLinksAreProperlyDetermined() {
23         assertTrue(LinkUtil.isInternalRelativeLink("foo"));
24         assertTrue(LinkUtil.isInternalRelativeLink("foo/bar"));
25         assertTrue(LinkUtil.isInternalRelativeLink("foo/bar.gif"));
26
27         assertFalse(LinkUtil.isInternalRelativeLink("/foo"));
28         assertFalse(LinkUtil.isInternalRelativeLink("/foo/bar"));
29         assertFalse(LinkUtil.isInternalRelativeLink("/foo/bar.gif"));
30
31         assertFalse(LinkUtil.isInternalRelativeLink("http://foo.com/bar.gif"));
32         assertFalse(LinkUtil.isInternalRelativeLink("http://foo.com/bar/baz.gif"));
33         assertFalse(LinkUtil.isInternalRelativeLink("http://foo.com/bar/"));
34         assertFalse(LinkUtil.isInternalRelativeLink("http://foo.com/bar"));
35         assertFalse(LinkUtil.isInternalRelativeLink("http://foo.com/"));
36         assertFalse(LinkUtil.isInternalRelativeLink("http://foo.com"));
37         assertFalse(LinkUtil.isInternalRelativeLink("https://foo.com"));
38         assertFalse(LinkUtil.isInternalRelativeLink("https://foo.com/bar"));
39         assertFalse(LinkUtil.isInternalRelativeLink("ftp://user:pass@server.com/foo/bar"));
40
41         assertFalse(LinkUtil.isInternalRelativeLink("mailto:murdock@a-team.org"));
42
43         assertFalse(LinkUtil.isInternalRelativeLink("#anchor"));
44         assertFalse(LinkUtil.isInternalRelativeLink("#another-anchor"));
45
46         assertFalse(LinkUtil.isInternalRelativeLink("javascript:void(window.open('http://www.google.com','','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=200,height=200'))"));
47         assertFalse(LinkUtil.isInternalRelativeLink("javascript:void(window.open('/foo/bar','','resizable=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,fullscreen=no,dependent=no,width=200,height=200'))"));
48     }
49 }
50
Popular Tags