diff options
Diffstat (limited to 'org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlUtilsTests.java')
-rw-r--r-- | org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlUtilsTests.java | 64 |
1 files changed, 45 insertions, 19 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlUtilsTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlUtilsTests.java index 9410bda74..b076ad546 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlUtilsTests.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlUtilsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2011 IBM Corporation and others. + * Copyright (c) 2008, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,36 +11,44 @@ package org.eclipse.ua.tests.help.webapp; -import org.eclipse.help.internal.webapp.data.UrlUtil; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; -import junit.framework.TestCase; +import org.eclipse.help.internal.webapp.data.UrlUtil; +import org.junit.Test; /** * Test for methods in UrlUtils */ -public class UrlUtilsTests extends TestCase { - +public class UrlUtilsTests { + @Test public void testHelpNav() { assertTrue(UrlUtil.isNavPath("/help/nav/1_2")); } + @Test public void testOtherNav() { assertTrue(UrlUtil.isNavPath("/other/nav/1_2")); } + @Test public void testHelpHelpNav() { assertFalse(UrlUtil.isNavPath("/help/help/nav/1_2")); } + @Test public void testNoNav() { assertFalse(UrlUtil.isNavPath("/helpcontext")); } - + + @Test public void testNoSlash() { assertFalse(UrlUtil.isNavPath("help/nav/1_2")); } - + + @Test public void testNavTopicPath() { int[] path = UrlUtil.getTopicPath("/nav/23_4_5", "en_us"); assertEquals(3, path.length); @@ -49,93 +57,111 @@ public class UrlUtilsTests extends TestCase { assertEquals(5, path[2]); } + @Test public void testRelativePathUnrelated() { MockServletRequest req = new MockServletRequest(); req.setPathInfo("/advanced/index.jsp"); assertEquals("../basic/index.jsp", UrlUtil.getRelativePath(req, "/basic/index.jsp")); } + @Test public void testRelativePathSameStart() { MockServletRequest req = new MockServletRequest(); req.setPathInfo("/advanced/index.jsp"); assertEquals("test.jsp", UrlUtil.getRelativePath(req, "/advanced/test.jsp")); } - + + @Test public void testRelativePathSameFile() { MockServletRequest req = new MockServletRequest(); req.setPathInfo("/advanced/index.jsp"); assertEquals("index.jsp", UrlUtil.getRelativePath(req, "/advanced/index.jsp")); } + @Test public void testRelativeAlmostMatch1() { MockServletRequest req = new MockServletRequest(); req.setPathInfo("/advanced/index.jsp"); assertEquals("../advance/index.jsp", UrlUtil.getRelativePath(req, "/advance/index.jsp")); } - + + @Test public void testRelativeAlmostMatch2() { MockServletRequest req = new MockServletRequest(); req.setPathInfo("/advanced/index.jsp"); assertEquals("../advancedd/index.jsp", UrlUtil.getRelativePath(req, "/advancedd/index.jsp")); } - + + @Test public void testRelativePathMultipleMatchingSegments() { MockServletRequest req = new MockServletRequest(); req.setPathInfo("/a/b/c/index.jsp"); assertEquals("../d/test.jsp", UrlUtil.getRelativePath(req, "/a/b/d/test.jsp")); - } + } + @Test public void testRelativePathSecondSegmentMatch1() { MockServletRequest req = new MockServletRequest(); req.setPathInfo("/a/a/a/index.jsp"); assertEquals("../../../b/a/c/test.jsp", UrlUtil.getRelativePath(req, "/b/a/c/test.jsp")); } - + + @Test public void testRelativePathSecondSegmentMatch2() { MockServletRequest req = new MockServletRequest(); req.setPathInfo("/b/a/c/index.jsp"); assertEquals("../../../a/a/a/test.jsp", UrlUtil.getRelativePath(req, "/a/a/a/test.jsp")); } + @Test public void testGetHelpUrlNull() { assertEquals("about:blank", UrlUtil.getHelpURL(null)); } + @Test public void testGetHelpUrlHttp() { assertEquals("http://www.eclipse.org", UrlUtil.getHelpURL("http://www.eclipse.org")); } + @Test public void testGetHelpUrlHttps() { assertEquals("https://bugs.eclipse.org/bugs/", UrlUtil.getHelpURL("https://bugs.eclipse.org/bugs/")); } - + + @Test public void testGetHelpUrlFile() { assertEquals("../topic/file://etc/about.html", UrlUtil.getHelpURL("file://etc/about.html")); } - + + @Test public void testGetHelpUrlPageInBundle() { assertEquals("../topic/bundle/help.html", UrlUtil.getHelpURL("/bundle/help.html")); } - + + @Test public void testGetHelpUrlNullDepthTwo() { assertEquals("about:blank", UrlUtil.getHelpURL(null, 2)); } + @Test public void testGetHelpUrlHttpDepthTwo() { assertEquals("http://www.eclipse.org", UrlUtil.getHelpURL("http://www.eclipse.org", 2)); } + @Test public void testGetHelpUrlHttpDepthTwos() { assertEquals("https://bugs.eclipse.org/bugs/", UrlUtil.getHelpURL("https://bugs.eclipse.org/bugs/", 2)); } - + + @Test public void testGetHelpUrlFileDepthTwo() { assertEquals("../../topic/file://etc/about.html", UrlUtil.getHelpURL("file://etc/about.html", 2)); } - + + @Test public void testGetHelpUrlPageInBundleDepthTwo() { assertEquals("../../topic/bundle/help.html", UrlUtil.getHelpURL("/bundle/help.html", 2)); } - - + + } |