1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/*******************************************************************************
* 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ua.tests.help.webapp;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.eclipse.help.internal.webapp.data.UrlUtil;
import org.junit.Test;
/**
* Test for methods in UrlUtils
*/
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);
assertEquals(23, path[0]);
assertEquals(4, path[1]);
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));
}
}
|