Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.ua.tests/help')
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/BrowserIdentificationTest.java55
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java55
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java23
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java33
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FragmentServletTest.java20
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerBinding.java49
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerInterrupt.java51
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HtmlCoderTest.java35
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/LocaleTest.java59
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java42
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java51
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PrintSubtopics.java28
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java40
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java21
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TopicPathTest.java23
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlCoderTest.java81
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlUtilsTests.java64
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java76
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java33
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java93
20 files changed, 573 insertions, 359 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/BrowserIdentificationTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/BrowserIdentificationTest.java
index 86446eea2..f9f753bf6 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/BrowserIdentificationTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/BrowserIdentificationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2008 IBM Corporation and others.
+ * Copyright (c) 2006, 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,17 +11,20 @@
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;
/**
- * Tests for the code which identifies the browser kind and version based upon the
+ * Tests for the code which identifies the browser kind and version based upon the
* User-Agent attribute of the HTTP request header. Each test uses a string derived
* from a specific browser.
*/
-public class BrowserIdentificationTest extends TestCase {
-
+public class BrowserIdentificationTest {
+ @Test
public void testIE_6() {
final String agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
assertTrue(UrlUtil.isIE(agent));
@@ -34,6 +37,7 @@ public class BrowserIdentificationTest extends TestCase {
assertTrue(UrlUtil.isAdvanced(agent));
}
+ @Test
public void testWindowsFirefox_1_8() {
final String agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.8) Gecko/20061025 (CK-IBM) Firefox/1.5.0.8";
assertFalse(UrlUtil.isIE(agent));
@@ -46,6 +50,7 @@ public class BrowserIdentificationTest extends TestCase {
assertTrue(UrlUtil.isAdvanced(agent));
}
+ @Test
public void testGTKFirefox_1_4() {
final String agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030922";
assertFalse(UrlUtil.isIE(agent));
@@ -57,7 +62,8 @@ public class BrowserIdentificationTest extends TestCase {
assertEquals("1.4", UrlUtil.getMozillaVersion(agent));
assertTrue(UrlUtil.isAdvanced(agent));
}
-
+
+ @Test
public void testGTKKonqueror_3_1() {
final String agent = "Mozilla/5.0 (compatible; Konqueror/3.1; Linux)";
assertFalse(UrlUtil.isIE(agent));
@@ -68,8 +74,9 @@ public class BrowserIdentificationTest extends TestCase {
assertFalse(UrlUtil.isGecko(agent));
assertFalse(UrlUtil.isAdvanced(agent));
}
-
- public void testMacMozilla1_7_3 () {
+
+ @Test
+ public void testMacMozilla1_7_3 () {
final String agent = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.7.3) Gecko/20040910";
assertFalse(UrlUtil.isIE(agent));
assertTrue(UrlUtil.isMozilla(agent));
@@ -79,9 +86,10 @@ public class BrowserIdentificationTest extends TestCase {
assertTrue(UrlUtil.isGecko(agent));
assertEquals("1.7.3", UrlUtil.getMozillaVersion(agent));
assertTrue(UrlUtil.isAdvanced(agent));
- }
-
- public void testSafari_417_8 () {
+ }
+
+ @Test
+ public void testSafari_417_8 () {
final String agent = "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/417.9 (KHTML, like Gecko) Safari/417.8";
assertFalse(UrlUtil.isIE(agent));
assertTrue(UrlUtil.isMozilla(agent));
@@ -91,8 +99,9 @@ public class BrowserIdentificationTest extends TestCase {
assertFalse(UrlUtil.isGecko(agent));
assertEquals("417", UrlUtil.getSafariVersion(agent));
assertTrue(UrlUtil.isAdvanced(agent));
- }
-
+ }
+
+ @Test
public void testOpera_9() {
final String agent = "Opera/9.02 (Windows NT 5.1; U; en)";
assertFalse(UrlUtil.isIE(agent));
@@ -105,7 +114,8 @@ public class BrowserIdentificationTest extends TestCase {
assertTrue(UrlUtil.isAdvanced(agent));
}
- public void testOpera_9_IEMode () {
+ @Test
+ public void testOpera_9_IEMode () {
final String agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.02";
assertTrue(UrlUtil.isIE(agent));
assertFalse(UrlUtil.isMozilla(agent));
@@ -115,8 +125,9 @@ public class BrowserIdentificationTest extends TestCase {
assertFalse(UrlUtil.isGecko(agent));
assertEquals("6.0", UrlUtil.getIEVersion(agent));
assertTrue(UrlUtil.isAdvanced(agent));
- }
+ }
+ @Test
public void testXulRunnerOnUbuntu() {
final String agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko";
assertFalse(UrlUtil.isIE(agent));
@@ -128,7 +139,8 @@ public class BrowserIdentificationTest extends TestCase {
assertEquals("1.9", UrlUtil.getMozillaVersion(agent));
assertTrue(UrlUtil.isAdvanced(agent));
}
-
+
+ @Test
public void testXulRunnerTruncated() {
final String agent = "Mozilla/5.0 (X11; U; Linux i686;";
assertFalse(UrlUtil.isIE(agent));
@@ -139,7 +151,8 @@ public class BrowserIdentificationTest extends TestCase {
assertFalse(UrlUtil.isGecko(agent));
assertTrue(UrlUtil.isAdvanced(agent));
}
-
+
+ @Test
public void testFirefox3() {
final String agent = "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.13) Gecko/2008031";
assertFalse(UrlUtil.isIE(agent));
@@ -151,7 +164,7 @@ public class BrowserIdentificationTest extends TestCase {
assertEquals("1.8.1.13", UrlUtil.getMozillaVersion(agent));
assertTrue(UrlUtil.isAdvanced(agent));
}
-
-
-
+
+
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java
index 7f7ee9bfb..eeec010fb 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ChildLinkInsertion.java
@@ -1,32 +1,35 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 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.assertNull;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
-import junit.framework.TestCase;
-
import org.eclipse.help.internal.webapp.servlet.PluginsRootResolvingStream;
+import org.junit.Test;
/**
* Test for text matching when inserting links
*/
-public class ChildLinkInsertion extends TestCase {
-
+public class ChildLinkInsertion {
+
private class TestableReplacementStream extends PluginsRootResolvingStream {
public TestableReplacementStream(OutputStream out, HttpServletRequest req, String prefix) {
super(out, req, prefix);
@@ -44,102 +47,120 @@ public class ChildLinkInsertion extends TestCase {
}
}
+ @Test
public void testEmpty() {
final String input = "";
checkFilter(input, input);
}
+ @Test
public void testNoMatch() {
final String input = "<HEAD><HEAD/>";
checkFilter(input, input);
}
+ @Test
public void testPartialMatch1() {
final String input = "<A href = \"PLUGINS\"><!--INSTRUCT-->";
checkFilter(input, input);
}
+ @Test
public void testPartialMatch2() {
final String input = "<A href = \"PLUGINS\"><!A -->";
checkFilter(input, input);
}
+ @Test
public void testPartialMatch3() {
final String input = "<A href = \"PLUGINS\"><!-A -->";
checkFilter(input, input);
}
-
+
+ @Test
public void testPartialMatch4() {
final String input = "<A href = \"PLUGINS\"><!--A-->";
checkFilter(input, input);
}
-
+
+ @Test
public void testEndsUnmatched() {
final String input = "<A><!--INSTR";
checkFilter(input, input);
}
+ @Test
public void testNotAtStart() {
final String input = "<A><!-- INSERT_CHILD_LINKS-->";
checkFilter(input, input);
}
+ @Test
public void testSpaceBeforeEnd() {
final String input = "<A><!-- INSERT_CHILD_LINKS -->";
checkFilter(input, input);
}
+ @Test
public void testTooManyCharacters_1() {
final String input = "<A><!--INSERT_CHILD_LINKSS-->";
checkFilter(input, input);
}
-
+
+ @Test
public void testTooManyCharacters_2() {
final String input = "<A><!--INSERT_CHILD_LINKS_STYLES-->";
checkFilter(input, input);
}
+ @Test
public void testAtStart() {
final String input = "<!--INSERT_CHILD_LINKS--><A>";
final String expected = "<LINKS><A>";
checkFilter(input, expected);
}
+ @Test
public void testChildStyle() {
final String input = "<!--INSERT_CHILD_LINK_STYLE--><A>";
final String expected = "<STYLE><A>";
checkFilter(input, expected);
}
+ @Test
public void testDefaultEncoding() {
final String input = "";
checkEncoding(input, null);
}
+ @Test
public void testEncodingUtf8() {
- final String input =
+ final String input =
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
checkEncoding(input, "utf-8");
}
-
+
+ @Test
public void testMetaNoEncoding() {
- final String input =
+ final String input =
"<meta http-equiv=\"Content-Type\" content=\"text/html\">";
checkEncoding(input, null);
}
+ @Test
public void testMultiMeta() {
- final String input =
+ final String input =
"<meta name=\"test\" content=\"test\">" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">" +
"<meta name=\"test\" content=\"test\">";
checkEncoding(input, "utf-8");
}
-
+
+ @Test
public void testMetaAndInsert() {
final String metaInfo = "<meta name=\"test\" content=\"test\">" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">";
- final String input =
+ final String input =
metaInfo + "<!--INSERT_CHILD_LINK_STYLE--><A>";
final String expected = metaInfo + "<STYLE><A>";
checkFilter(input, expected);
@@ -157,7 +178,7 @@ public class ChildLinkInsertion extends TestCase {
}
assertEquals(expected, output.toString());
}
-
+
private void checkEncoding(String input, String expectedEncoding) {
ByteArrayOutputStream output = new ByteArrayOutputStream();
TestableReplacementStream filteredOutput = new TestableReplacementStream(output, null, "../");
@@ -173,5 +194,5 @@ public class ChildLinkInsertion extends TestCase {
assertEquals(expectedEncoding, filteredOutput.getCharset());
}
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java
index 612cd3590..d9c7ae8da 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterExtensionTest.java
@@ -1,35 +1,38 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 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
* 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 java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.eclipse.help.internal.webapp.servlet.ExtraFilters;
import org.eclipse.help.internal.webapp.servlet.PrioritizedFilter;
-
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Test;
/**
* Tests for the code which supports the extension point org.eclipse.help.webapp.extraFilter
*/
-public class FilterExtensionTest extends TestCase {
-
- @Override
- protected void tearDown() throws Exception {
+public class FilterExtensionTest {
+
+ @After
+ public void tearDown() throws Exception {
ExtraFilters.setFilters(new PrioritizedFilter[0]);
}
+ @Test
public void testFilterExtensions() throws IOException {
PrioritizedFilter[] filters = new PrioritizedFilter[] {
new PrioritizedFilter(new CommentFilterTwo(), 2),
@@ -47,6 +50,7 @@ public class FilterExtensionTest extends TestCase {
assertEquals(expected, result);
}
+ @Test
public void testRepeatedExtensions() throws IOException {
PrioritizedFilter[] filters = new PrioritizedFilter[] {
new PrioritizedFilter(new CommentFilterTwo(), 2),
@@ -64,6 +68,7 @@ public class FilterExtensionTest extends TestCase {
assertEquals(expected, result);
}
+ @Test
public void testNoFilters() throws IOException {
PrioritizedFilter[] filters = new PrioritizedFilter[0];
ExtraFilters.setFilters(filters);
@@ -76,5 +81,5 @@ public class FilterExtensionTest extends TestCase {
String expected = "<html>";
assertEquals(expected, result);
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java
index eecb269ed..d7a1b3a18 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FilterTest.java
@@ -1,33 +1,35 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 IBM Corporation and others.
+ * Copyright (c) 2007, 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.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import junit.framework.TestCase;
-
import org.eclipse.help.internal.search.HTMLDocParser;
import org.eclipse.help.internal.webapp.servlet.FilterHTMLHeadAndBodyOutputStream;
import org.eclipse.help.internal.webapp.servlet.FilterHTMLHeadOutputStream;
+import org.junit.Test;
/**
* Test for functions which decode a topic string
*/
-public class FilterTest extends TestCase {
+public class FilterTest {
private final String HTML40 = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
private final String HEAD1 = "<HEAD>";
private final String HEAD2 = "</HEAD>";
@@ -48,6 +50,7 @@ public class FilterTest extends TestCase {
private String CHINESE_CONTENT = "<p>" + (char)24320 + (char)21457 + (char)29932 + "</p>";
private String CHINESE_ENTITY_CONTENT = "<p>&#24320;&#21457;&#29932;</p>";
+ @Test
public void testHeadOutputFilter() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
OutputStream filteredOutput = new FilterHTMLHeadOutputStream(output, CSS2.getBytes());
@@ -67,6 +70,7 @@ public class FilterTest extends TestCase {
assertEquals(expected, output.toString());
}
+ @Test
public void testHeadAndBodyOutputFilter() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS2.getBytes(), CONTENT2);
@@ -86,7 +90,8 @@ public class FilterTest extends TestCase {
final String expected = HTML40 + HEAD1 + CONTENT_TYPE_ISO_8859_1 + CSS1 + CSS2 + '\n' + HEAD2 + BODY1 + '\n' + CONTENT2 + '\n' + CONTENT1 + BODY2;
assertEquals(expected, output.toString());
}
-
+
+ @Test
public void testLowerCaseTags() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
OutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS1.getBytes(), CONTENT2);
@@ -103,8 +108,9 @@ public class FilterTest extends TestCase {
}
final String expected = HTML40 + HEADLC1 + CSS1 + '\n' + HEADLC2 + BODYLC1 + '\n' + CONTENT2 + '\n' + CONTENT1 + BODYLC2;
assertEquals(expected, output.toString());
- }
-
+ }
+
+ @Test
public void testFilterHeadlessDocument() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
OutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, CSS1.getBytes(), CONTENT2);
@@ -121,6 +127,7 @@ public class FilterTest extends TestCase {
assertEquals(expected, output.toString());
}
+ @Test
public void testInsertChineseUtf8() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null, CHINESE_CONTENT);
@@ -139,6 +146,7 @@ public class FilterTest extends TestCase {
}
}
+ @Test
public void testInsertChineseISO8859() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null, CHINESE_CONTENT);
@@ -156,7 +164,8 @@ public class FilterTest extends TestCase {
fail("IO Exception");
}
}
-
+
+ @Test
public void testInsertChineseNoCharsetSpecified() {
ByteArrayOutputStream output = new ByteArrayOutputStream();
FilterHTMLHeadAndBodyOutputStream filteredOutput = new FilterHTMLHeadAndBodyOutputStream(output, null, CHINESE_CONTENT);
@@ -174,14 +183,16 @@ public class FilterTest extends TestCase {
}
}
+ @Test
public void testCharsetUtf8Upper() {
InputStream is = new ByteArrayInputStream(CONTENT_TYPE_UTF8UC.getBytes());
assertEquals("UTF-8", HTMLDocParser.getCharsetFromHTML(is));
}
-
+
+ @Test
public void testCharsetISO_8859_UCUpper() {
InputStream is = new ByteArrayInputStream(CONTENT_TYPE_ISO_8859_1_UC.getBytes());
assertEquals("ISO-8859-1", HTMLDocParser.getCharsetFromHTML(is));
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FragmentServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FragmentServletTest.java
index 46d7b4de5..4237c8858 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FragmentServletTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/FragmentServletTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 IBM Corporation and others.
+ * Copyright (c) 2009, 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,41 +11,47 @@
package org.eclipse.ua.tests.help.webapp;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
import org.eclipse.help.internal.webapp.servlet.TocFragmentServlet;
+import org.junit.Test;
/**
* Tests for the class TocFragmentServlet
*/
-public class FragmentServletTest extends TestCase {
-
+public class FragmentServletTest {
+
private static final String PATH = "1_2";
private static final String DOC_HTML = "org.eclipse.ua.tests/doc.html";
+ @Test
public void testFixHrefNormal() {
String href = TocFragmentServlet.fixupHref(DOC_HTML, PATH);
assertEquals(DOC_HTML + "?cp=1_2", href);
}
-
+
+ @Test
public void testFixHrefWithParameter() {
String href = TocFragmentServlet.fixupHref(DOC_HTML + "?a=b", PATH);
assertEquals(DOC_HTML + "?a=b&cp=1_2", href);
}
+ @Test
public void testFixHrefNull() {
String href = TocFragmentServlet.fixupHref(null, PATH);
assertEquals("/../nav/1_2", href);
}
+ @Test
public void testFixHrefWithAnchor() {
String href = TocFragmentServlet.fixupHref(DOC_HTML + "#A", PATH);
assertEquals(DOC_HTML + "?cp=1_2#A" , href);
}
-
+
+ @Test
public void testFixHrefWithAnchorAndParams() {
String href = TocFragmentServlet.fixupHref(DOC_HTML + "?a=b#A", PATH);
assertEquals(DOC_HTML + "?a=b&cp=1_2#A" , href);
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerBinding.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerBinding.java
index 8bb83937f..8772ca3f9 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerBinding.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerBinding.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2015 IBM Corporation and others.
+ * Copyright (c) 2010, 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,22 +11,26 @@
package org.eclipse.ua.tests.help.webapp;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.io.InputStream;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLConnection;
import java.net.UnknownHostException;
-import junit.framework.TestCase;
-
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.server.WebappManager;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* Test to see if the help server binds to host 127.0.0.1 in Workbench mode
*/
-public class HelpServerBinding extends TestCase {
+public class HelpServerBinding {
private int previousMode;
// Tests to access the server using it's IP need to be disabled
@@ -34,19 +38,19 @@ public class HelpServerBinding extends TestCase {
// To enable these tests for local testing set testUsingIP to true.
private final boolean testUsingIP = false;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
previousMode = BaseHelpSystem.getMode();
}
-
- @Override
- protected void tearDown() throws Exception {
+
+ @After
+ public void tearDown() throws Exception {
BaseHelpSystem.setMode(previousMode);
}
-
- private String getHostIP() throws UnknownHostException {
+
+ private String getHostIP() throws UnknownHostException {
InetAddress host = InetAddress.getLocalHost();
- byte[] ipAddr = host.getAddress();
+ byte[] ipAddr = host.getAddress();
String result = "" + ipAddr[0];
for (int i = 1; i < ipAddr.length; i++) {
result += '.';
@@ -55,6 +59,7 @@ public class HelpServerBinding extends TestCase {
return result;
}
+ @Test
public void testInfocenterBinding() throws Exception {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
WebappManager.stop("help");
@@ -63,8 +68,9 @@ public class HelpServerBinding extends TestCase {
if (testUsingIP) {
assertTrue(canAccessServer(getHostIP()));
}
- }
+ }
+ @Test
public void testWorkbenchBinding() throws Exception {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_WORKBENCH);
WebappManager.stop("help");
@@ -73,8 +79,9 @@ public class HelpServerBinding extends TestCase {
if (testUsingIP) {
assertFalse(canAccessServer(getHostIP()));
}
- }
-
+ }
+
+ @Test
public void testStandaloneBinding() throws Exception {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_STANDALONE);
WebappManager.stop("help");
@@ -83,13 +90,13 @@ public class HelpServerBinding extends TestCase {
if (testUsingIP) {
assertTrue(canAccessServer(getHostIP()));
}
- }
-
+ }
+
private boolean canAccessServer(String host) throws Exception {
InputStream input;
try {
int port = WebappManager.getPort();
- URL url = new URL("http", host, port, "/help/index.jsp");
+ URL url = new URL("http", host, port, "/help/index.jsp");
URLConnection connection = url.openConnection();
setTimeout(connection, 5000);
input = connection.getInputStream();
@@ -97,13 +104,13 @@ public class HelpServerBinding extends TestCase {
input.close();
return firstbyte > 0;
} catch (Exception e) {
- return false;
+ return false;
}
}
-
+
private static void setTimeout(URLConnection conn, int milliseconds) {
conn.setConnectTimeout(milliseconds);
conn.setReadTimeout(milliseconds);
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerInterrupt.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerInterrupt.java
index 9e804fc9b..eb6095fd2 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerInterrupt.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HelpServerInterrupt.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2015 IBM Corporation and others.
+ * Copyright (c) 2009, 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,27 +11,27 @@
package org.eclipse.ua.tests.help.webapp;
+import static org.junit.Assert.fail;
+
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
-import junit.framework.TestCase;
-
-import org.junit.Assert;
-
import org.eclipse.help.internal.server.WebappManager;
+import org.junit.Assert;
+import org.junit.Test;
/**
* Test to see if the help server is interruptable
*/
-public class HelpServerInterrupt extends TestCase {
-
+public class HelpServerInterrupt {
+
private static boolean enableTimeout = true;
private int iterations;
- private int sleepTime = 10;
+ private int sleepTime = 10;
private class ServerStarter extends Thread {
-
+
private Exception exception = null;
@Override
@@ -48,25 +48,22 @@ public class HelpServerInterrupt extends TestCase {
}
}
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
+ @Test
public void testServerWithoutInterrupt() throws Exception {
WebappManager.stop("help");
startServerWithoutInterrupt();
checkServer();
WebappManager.stop("help");
- }
-
+ }
+
+ @Test
public void testServerWithInterrupt() throws Exception {
WebappManager.stop("help");
startServerWithInterrupt();
checkServer();
WebappManager.stop("help");
- }
-
+ }
+
private void startServerWithoutInterrupt() throws Exception {
ServerStarter starter = new ServerStarter();
starter.start();
@@ -76,15 +73,15 @@ public class HelpServerInterrupt extends TestCase {
iterations++;
if (enableTimeout && sleepTime * iterations > 10000) {
fail("Test did not complete within 10 seconds");
- }
- Thread.sleep(sleepTime);
+ }
+ Thread.sleep(sleepTime);
} while (starter.isAlive());
Exception exception = starter.getException();
if (exception != null) {
throw exception;
}
}
-
+
private void startServerWithInterrupt() throws Exception {
ServerStarter starter = new ServerStarter();
starter.start();
@@ -95,21 +92,21 @@ public class HelpServerInterrupt extends TestCase {
if (enableTimeout && sleepTime * iterations > 10000) {
fail("Test did not complete within 10 seconds");
}
- starter.interrupt();
- Thread.sleep(sleepTime);
+ starter.interrupt();
+ Thread.sleep(sleepTime);
} while (starter.isAlive());
Exception exception = starter.getException();
if (exception != null) {
throw exception;
}
}
-
+
private void checkServer() throws Exception {
InputStream input;
long start = System.currentTimeMillis();
try {
int port = WebappManager.getPort();
- URL url = new URL("http", "localhost", port, "/help/index.jsp");
+ URL url = new URL("http", "localhost", port, "/help/index.jsp");
URLConnection connection = url.openConnection();
setTimeout(connection, 5000);
input = connection.getInputStream();
@@ -122,10 +119,10 @@ public class HelpServerInterrupt extends TestCase {
throw e;
}
}
-
+
private static void setTimeout(URLConnection conn, int milliseconds) {
conn.setConnectTimeout(milliseconds);
conn.setReadTimeout(milliseconds);
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HtmlCoderTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HtmlCoderTest.java
index de3092c4a..8cbdd1643 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HtmlCoderTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/HtmlCoderTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 IBM Corporation and others.
+ * Copyright (c) 2010, 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,38 +11,44 @@
package org.eclipse.ua.tests.help.webapp;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
import org.eclipse.help.internal.webapp.data.UrlUtil;
+import org.junit.Test;
-public class HtmlCoderTest extends TestCase {
-
+public class HtmlCoderTest {
+ @Test
public void testEncodeEmpty() {
String encoded = UrlUtil.htmlEncode(null);
assertNull(encoded);
- }
+ }
/**
* Verify that alpha characters are not encoded
*/
+ @Test
public void testEncodeAlpha() {
final String letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
String encoded = UrlUtil.htmlEncode(letters);
assertEquals(letters, encoded);
}
-
+
/**
* Verify that alpha characters are not encoded
*/
+ @Test
public void testEncodeNumeric() {
final String numbers = "1234567890";
String encoded = UrlUtil.htmlEncode(numbers);
assertEquals(numbers, encoded);
}
-
+
/**
* Verify that space is not encoded
*/
+ @Test
public void testEncodeSpace() {
final String spaces = " ";
String encoded = UrlUtil.htmlEncode(spaces);
@@ -52,24 +58,27 @@ public class HtmlCoderTest extends TestCase {
/**
* Verify that quote is encoded
*/
+ @Test
public void testEncodeQuote() {
final String source = "\'";
String encoded = UrlUtil.htmlEncode(source);
assertNotSame(source, encoded);
}
-
+
/**
* Verify that less than is encoded
*/
+ @Test
public void testEncodeLt() {
final String source = "<";
String encoded = UrlUtil.htmlEncode(source);
assertNotSame(source, encoded);
- }
+ }
/**
* Verify that greater than is encoded
*/
+ @Test
public void testEncodeGt() {
final String source = ">";
String encoded = UrlUtil.htmlEncode(source);
@@ -79,6 +88,7 @@ public class HtmlCoderTest extends TestCase {
/**
* Verify that ampersand is encoded
*/
+ @Test
public void testEncodeAmp() {
final String source = "&";
String encoded = UrlUtil.htmlEncode(source);
@@ -88,6 +98,7 @@ public class HtmlCoderTest extends TestCase {
/**
* Verify that ampersand is encoded
*/
+ @Test
public void testEncodeBackslash() {
final String source = "\\";
String encoded = UrlUtil.htmlEncode(source);
@@ -97,6 +108,7 @@ public class HtmlCoderTest extends TestCase {
/**
* Verify that newline is encoded
*/
+ @Test
public void testEncodeNewline() {
final String source = "\n";
String encoded = UrlUtil.htmlEncode(source);
@@ -106,6 +118,7 @@ public class HtmlCoderTest extends TestCase {
/**
* Verify that CR is encoded
*/
+ @Test
public void testEncodeCarriageReturn() {
final String source = "\r";
String encoded = UrlUtil.htmlEncode(source);
@@ -115,15 +128,17 @@ public class HtmlCoderTest extends TestCase {
/**
* Verify that accented character is not encoded
*/
+ @Test
public void testNoEncodeAccented() {
final String source = "\u00c1";
String encoded = UrlUtil.htmlEncode(source);
assertEquals(source, encoded);
}
-
+
/**
* Verify that Chinese character is not encoded
*/
+ @Test
public void testNoEncodeChinese() {
final String source = "\u4e01";
String encoded = UrlUtil.htmlEncode(source);
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/LocaleTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/LocaleTest.java
index bf0242814..456482051 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/LocaleTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/LocaleTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 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,42 +11,51 @@
package org.eclipse.ua.tests.help.webapp;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.util.Locale;
import javax.servlet.http.Cookie;
-import junit.framework.TestCase;
-
import org.eclipse.core.runtime.Platform;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.util.ProductPreferences;
import org.eclipse.help.internal.webapp.data.UrlUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for locale related code in UrlUtil
*/
-public class LocaleTest extends TestCase {
-
+public class LocaleTest {
+
private int mode;
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
BaseHelpSystem.setMode(mode);
}
-
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
mode = BaseHelpSystem.getMode();
}
+ @Test
public void testFixLocaleNull() {
assertNull(UrlUtil.cleanLocale(null));
}
-
+
+ @Test
public void testFixLocaleWithIllegalChars() {
assertEquals("ab-cd______ef", UrlUtil.cleanLocale("ab-cd\n\r_\"\'_ef"));
}
+ @Test
public void testForced_Locale() {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
MockServletRequest req = new MockServletRequest();
@@ -56,6 +65,7 @@ public class LocaleTest extends TestCase {
assertEquals("es", locale);
}
+ @Test
public void testForcedLangOverridesCookies() {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
MockServletRequest req = new MockServletRequest();
@@ -65,7 +75,8 @@ public class LocaleTest extends TestCase {
String locale = UrlUtil.getLocale(req, null);
assertEquals("es", locale);
}
-
+
+ @Test
public void testForcedUsingCookies() {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
MockServletRequest req = new MockServletRequest();
@@ -75,6 +86,7 @@ public class LocaleTest extends TestCase {
assertEquals("it", locale);
}
+ @Test
public void testGetLocale_De_Standalone() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_STANDALONE);
@@ -82,7 +94,8 @@ public class LocaleTest extends TestCase {
String locale = UrlUtil.getLocale(req, null);
assertEquals(Platform.getNL(), locale);
}
-
+
+ @Test
public void testGetLocale_De_Workbench() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_WORKBENCH);
@@ -90,7 +103,8 @@ public class LocaleTest extends TestCase {
String locale = UrlUtil.getLocale(req, null);
assertEquals(Platform.getNL(), locale);
}
-
+
+ @Test
public void testGetLocale_De_Infocenter() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
@@ -99,6 +113,7 @@ public class LocaleTest extends TestCase {
assertEquals("de", locale);
}
+ @Test
public void testGetLocale_Pt_Br_Infocenter() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
@@ -106,7 +121,8 @@ public class LocaleTest extends TestCase {
String locale = UrlUtil.getLocale(req, null);
assertEquals("pt_br", locale.toLowerCase());
}
-
+
+ @Test
public void testGetLocale_Fr_Ca_To_Infocenter() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
@@ -114,14 +130,16 @@ public class LocaleTest extends TestCase {
String locale = UrlUtil.getLocale(req, null);
assertEquals("fr_CA_to", locale);
}
-
+
+ @Test
public void testIsRTLWorkbench() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_WORKBENCH);
req.setLocale(new Locale("de"));
assertEquals(ProductPreferences.isRTL(), UrlUtil.isRTL(req, null));
- }
+ }
+ @Test
public void testIsRTLInfocenter_ar() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
@@ -129,6 +147,7 @@ public class LocaleTest extends TestCase {
assertTrue(UrlUtil.isRTL(req, null));
}
+ @Test
public void testIsRTLInfocenter_he() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
@@ -136,18 +155,20 @@ public class LocaleTest extends TestCase {
assertTrue(UrlUtil.isRTL(req, null));
}
+ @Test
public void testIsRTLInfocenter_de() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
req.setLocale(new Locale("de"));
assertFalse(UrlUtil.isRTL(req, null));
}
-
+
+ @Test
public void testIsRTLInfocenter_en_us() {
MockServletRequest req = new MockServletRequest();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
req.setLocale(new Locale("en_US"));
assertFalse(UrlUtil.isRTL(req, null));
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java
index eca959685..f2414ee09 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/ParallelServerAccessTest.java
@@ -11,13 +11,15 @@
package org.eclipse.ua.tests.help.webapp;
+import static org.junit.Assert.fail;
+
import java.io.InputStream;
import java.net.URL;
import org.eclipse.help.internal.server.WebappManager;
import org.eclipse.ua.tests.help.util.LoadServletUtil;
-
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Test;
/**
* Test the performance of the help server without launching the Help UI
@@ -25,26 +27,22 @@ import junit.framework.TestCase;
* It is no longer run as part of the UA test suite
*/
-public class ParallelServerAccessTest extends TestCase {
+public class ParallelServerAccessTest {
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
- protected void tearDown() throws Exception {
+ @After
+ public void tearDown() throws Exception {
LoadServletUtil.stopServer();
}
+ @Test
public void testServletReadInParallel() throws Exception {
LoadServletUtil.startServer();
int iterations = 1; // Change this to increase the length of the test
for (int i=0; i < iterations; ++i) {
accessInParallel(10);
}
- }
-
+ }
+
private void accessInParallel(int numberOfThreads) throws Exception {
ReadThread[] readers = new ReadThread[numberOfThreads];
for (int i = 0; i < numberOfThreads; i++) {
@@ -79,11 +77,11 @@ public class ParallelServerAccessTest extends TestCase {
}
}
}
-
+
private class ReadThread extends Thread {
-
+
public Exception exception;
-
+
@Override
public void run() {
for (int j = 0; j <= 100; j++) {
@@ -94,9 +92,9 @@ public class ParallelServerAccessTest extends TestCase {
e.printStackTrace();
}
}
- }
+ }
}
-
+
private class UnexpectedValueException extends Exception {
private static final long serialVersionUID = 1L;
private long expected;
@@ -106,20 +104,20 @@ public class ParallelServerAccessTest extends TestCase {
this.expected = expected;
this.actual = actual;
}
-
+
@Override
public String getMessage() {
return "Expected: " + expected +" Actual: " + actual;
}
}
-
+
long readOperations = 0;
-
+
public void readLoadServlet(int paragraphs) throws Exception {
int port = WebappManager.getPort();
// Use a unique parameter to defeat caching
long uniqueId = getReadOperations();
- URL url = new URL("http", "localhost", port,
+ URL url = new URL("http", "localhost", port,
"/help/loadtest?value=" + uniqueId + "&repeat=" + paragraphs);
InputStream input = url.openStream();
int nextChar;
@@ -146,5 +144,5 @@ public class ParallelServerAccessTest extends TestCase {
private synchronized long getReadOperations() {
return ++readOperations;
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java
index 4425cc1ac..d7bffd9c5 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PluginsRootReplacement.java
@@ -1,72 +1,81 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 IBM Corporation and others.
+ * Copyright (c) 2009, 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.assertNotNull;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
-import junit.framework.TestCase;
-
import org.eclipse.help.internal.webapp.servlet.PluginsRootResolvingStream;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.eclipse.ua.tests.util.ResourceFinder;
+import org.junit.Test;
/**
* Test for replacing PLUGINS_ROOT with a relative path
*/
-public class PluginsRootReplacement extends TestCase {
-
+public class PluginsRootReplacement {
+ @Test
public void testEmpty() {
final String input = "";
checkFilter(input, input);
}
+ @Test
public void testNoMatch() {
final String input = "<HEAD><HEAD/>";
checkFilter(input, input);
}
+ @Test
public void testPartialMatch() {
final String input = "<A href = \"PLUGINS\">";
checkFilter(input, input);
}
-
+
+ @Test
public void testEndsUnmatched() {
final String input = "<A href = \"PLUGIN";
checkFilter(input, input);
}
+ @Test
public void testNotAtStart() {
final String input = "<A href = \"../PLUGINS_ROOT/plugin/a.html\">";
checkFilter(input, input);
}
+ @Test
public void testAtStart() {
final String input = "<A href = \"PLUGINS_ROOT/plugin/a.html\">";
final String expected = "<A href = \"../plugin/a.html\">";
checkFilter(input, expected);
}
+ @Test
public void testSecondArg() {
final String input = "<A alt=\"alt\" href = \"PLUGINS_ROOT/plugin/a.html\">";
final String expected = "<A alt=\"alt\" href = \"../plugin/a.html\">";
checkFilter(input, expected);
}
-
+ @Test
public void testMultipleMatches() {
final String input = "<A href = \"PLUGINS_ROOT/plugin/a.html\"><A href = \"PLUGINS_ROOT/plugin/b.html\">";
final String expected = "<A href = \"../plugin/a.html\"><A href = \"../plugin/b.html\">";
@@ -85,56 +94,66 @@ public class PluginsRootReplacement extends TestCase {
assertEquals(expected, output.toString());
}
+ @Test
public void testHelpContentActiveAction() throws IOException {
String filename = "ua_help_content_active_action.htm";
checkFileContentsPreserved(filename);
}
-
+
+ @Test
public void testHelpContentActiveDebug() throws IOException {
String filename = "ua_help_content_active_debug.htm";
checkFileContentsPreserved(filename);
}
+ @Test
public void testHelpContentActiveInvoke() throws IOException {
String filename = "ua_help_content_active_invoke.htm";
checkFileContentsPreserved(filename);
}
+ @Test
public void testHelpContentActive() throws IOException {
String filename = "ua_help_content_active.htm";
checkFileContentsPreserved(filename);
}
-
+
+ @Test
public void testHelpContentManifest() throws IOException {
String filename = "ua_help_content_manifest.htm";
checkFileContentsPreserved(filename);
}
-
+
+ @Test
public void testHelpContentProcess() throws IOException {
String filename = "ua_help_content_process.htm";
checkFileContentsPreserved(filename);
}
+ @Test
public void testHelpContentNested() throws IOException {
String filename = "ua_help_content_nested.htm";
checkFileContentsPreserved(filename);
}
-
+
+ @Test
public void testHelpContentToc() throws IOException {
String filename = "ua_help_content_toc.htm";
checkFileContentsPreserved(filename);
}
-
+
+ @Test
public void testHelpContentXhtml() throws IOException {
String filename = "ua_help_content_xhtml.htm";
checkFileContentsPreserved(filename);
}
-
+
+ @Test
public void testHelpContent() throws IOException {
String filename = "ua_help_content.htm";
checkFileContentsPreserved(filename);
}
-
+
/*
* Test a pages from the help system to make sure there is no corruption
* when it is transformed.
@@ -154,5 +173,5 @@ public class PluginsRootReplacement extends TestCase {
input.close();
output.close();
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PrintSubtopics.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PrintSubtopics.java
index fe6215569..cd77cf3b0 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PrintSubtopics.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/PrintSubtopics.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 IBM Corporation and others.
+ * Copyright (c) 2011, 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,50 +11,58 @@
package org.eclipse.ua.tests.help.webapp;
+import static org.junit.Assert.assertEquals;
+
import org.eclipse.help.internal.webapp.data.PrintData;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Test for methods in PrintData
*/
-public class PrintSubtopics extends TestCase {
-
+public class PrintSubtopics {
+ @Test
public void testHeadingInsertion() {
String result = PrintData.injectHeading("<body> <p>Title</p>", "1");
assertEquals("<body> <p><a id=\"section1\">1. </a>Title</p>", result);
}
-
+
+ @Test
public void testHeaderInsertionSkipsWhitespace() {
checkHeadingInsertion("<body> <p> \n\r</p><h1>", "Title</h1>");
}
+ @Test
public void testAccentedCharacter() {
checkHeadingInsertion("<body> <p>", "\u00E1guila</p>");
}
+ @Test
public void testinvertedQuestionmark() {
checkHeadingInsertion("<body> <p>", "\u00BFQu\u00E9 es Eclipse?</p>");
}
-
+
+ @Test
public void testSlash() {
checkHeadingInsertion("<body> <p>", "/usr/bin</p>");
}
+ @Test
public void testChineseCharacter() {
checkHeadingInsertion("<body> <p>", "\u623F\u5B50</p>");
}
-
+
+ @Test
public void testChineseExtbCharacter() {
checkHeadingInsertion("<body> <p>", "\uD840\uDC06</p>");
}
-
+
/*
- * Check that insertions occur between preInsert and postInsert
+ * Check that insertions occur between preInsert and postInsert
*/
public void checkHeadingInsertion(String preInsert, String postInsert) {
String result = PrintData.injectHeading(preInsert + postInsert, "1");
assertEquals(preInsert + "<a id=\"section1\">1. </a>" + postInsert, result);
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java
index 73c5c3995..ac822c9ee 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/RestrictedTopicParameter.java
@@ -1,54 +1,59 @@
/*******************************************************************************
- * Copyright (c) 2008, 2015 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
* 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.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.webapp.data.UrlUtil;
-
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* Test for function which determines whether a topic path can be passed to the content frame
*/
-public class RestrictedTopicParameter extends TestCase {
-
+public class RestrictedTopicParameter {
+
private static final String RESTRICT_TOPIC = "restrictTopicParameter";
private boolean restrictTopic;
private int helpMode;
-
- @Override
- protected void setUp() throws Exception {
+
+ @Before
+ public void setUp() throws Exception {
restrictTopic = Platform.getPreferencesService().getBoolean
(HelpBasePlugin.PLUGIN_ID, RESTRICT_TOPIC,
false, null);
helpMode = BaseHelpSystem.getMode();
}
-
- @Override
- protected void tearDown() throws Exception {
+
+ @After
+ public void tearDown() throws Exception {
setRestrictTopic(restrictTopic);
BaseHelpSystem.setMode(helpMode);
}
private void setRestrictTopic(boolean isRestrict) {
IEclipsePreferences pref = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
- pref.putBoolean(RESTRICT_TOPIC, isRestrict);
+ pref.putBoolean(RESTRICT_TOPIC, isRestrict);
}
+ @Test
public void testWorkbenchMode() {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_WORKBENCH);
setRestrictTopic(true);
@@ -58,7 +63,8 @@ public class RestrictedTopicParameter extends TestCase {
assertTrue(UrlUtil.isValidTopicParamOrWasOpenedFromHelpDisplay("http://www.eclipse.org"));
assertTrue(UrlUtil.isValidTopicParamOrWasOpenedFromHelpDisplay("https://www.eclipse.org"));
}
-
+
+ @Test
public void testStandaloneMode() {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_STANDALONE);
setRestrictTopic(true);
@@ -69,6 +75,7 @@ public class RestrictedTopicParameter extends TestCase {
assertTrue(UrlUtil.isValidTopicParamOrWasOpenedFromHelpDisplay("https://www.eclipse.org"));
}
+ @Test
public void testInfocenterUnrestricted() {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
setRestrictTopic(false);
@@ -76,7 +83,8 @@ public class RestrictedTopicParameter extends TestCase {
assertTrue(UrlUtil.isValidTopicParamOrWasOpenedFromHelpDisplay("https://www.eclipse.org"));
assertTrue(UrlUtil.isValidTopicParamOrWasOpenedFromHelpDisplay("org.eclipse.platform.doc.user/reference/ref-43.htm"));
}
-
+
+ @Test
public void testInfocenterResestricted() {
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
setRestrictTopic(true);
@@ -86,5 +94,5 @@ public class RestrictedTopicParameter extends TestCase {
assertFalse(UrlUtil.isValidTopicParamOrWasOpenedFromHelpDisplay("file://somepath.html"));
assertTrue(UrlUtil.isValidTopicParamOrWasOpenedFromHelpDisplay("org.eclipse.platform.doc.user/reference/ref-43.htm"));
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java
index 0608b2b32..0f9b57fe1 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TocZipTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 IBM Corporation and others.
+ * Copyright (c) 2011, 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,6 +11,9 @@
package org.eclipse.ua.tests.help.webapp;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -18,21 +21,22 @@ import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import junit.framework.TestCase;
-
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.server.WebappManager;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for reading from toc.zip
*/
-public class TocZipTest extends TestCase {
+public class TocZipTest {
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
BaseHelpSystem.ensureWebappRunning();
}
+ @Test
public void testDocInZipOnly() throws IOException {
final String path= "/org.eclipse.ua.tests/data/help/manual/dz1.html";
String contents= readPage(path);
@@ -43,6 +47,7 @@ public class TocZipTest extends TestCase {
* Verify that loose files override those in doc.zip
* @throws IOException
*/
+ @Test
public void testDocInZipAndBundle() throws IOException {
final String path = "/org.eclipse.ua.tests/data/help/manual/dz2.html";
String contents = readPage(path);
@@ -61,10 +66,10 @@ public class TocZipTest extends TestCase {
while(result != -1) {
os.write(result);
result = buffered.read();
- }
+ }
buffered.close();
os.close();
return os.toString();
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TopicPathTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TopicPathTest.java
index 1b24344c3..edde5c959 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TopicPathTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/TopicPathTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 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,22 +11,25 @@
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.assertNull;
-import junit.framework.TestCase;
+import org.eclipse.help.internal.webapp.data.UrlUtil;
+import org.junit.Test;
/**
* Test for functions which decode a topic string
*/
-public class TopicPathTest extends TestCase {
-
+public class TopicPathTest {
+ @Test
public void testTocOnly() {
int[] topics = UrlUtil.splitPath("25");
assertEquals(1, topics.length);
assertEquals(25, topics[0]);
}
-
+
+ @Test
public void testTopic() {
int[] topics = UrlUtil.splitPath("2_5");
assertEquals(2, topics.length);
@@ -34,26 +37,30 @@ public class TopicPathTest extends TestCase {
assertEquals(5, topics[1]);
}
+ @Test
public void testNullPath() {
int[] topics = UrlUtil.splitPath(null);
assertNull(topics);
}
+ @Test
public void testEmptyPath() {
int[] topics = UrlUtil.splitPath("");
assertNull(topics);
}
+ @Test
public void testDoubleUnderscore() {
int[] topics = UrlUtil.splitPath("1__2");
assertEquals(2, topics.length);
assertEquals(1, topics[0]);
assertEquals(2, topics[1]);
}
-
+
+ @Test
public void testMalformedPath() {
int[] topics = UrlUtil.splitPath("3_A");
assertNull(topics);
}
-
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlCoderTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlCoderTest.java
index 504b1a11f..4c894c4bb 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlCoderTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/UrlCoderTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 IBM Corporation and others.
+ * Copyright (c) 2010, 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,17 +11,20 @@
package org.eclipse.ua.tests.help.webapp;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import org.eclipse.help.internal.util.URLCoder;
+import org.junit.Test;
+
+public class UrlCoderTest {
-public class UrlCoderTest extends TestCase {
-
private static final String SPECIAL_CHARACTERS = "!@#$%^&*()_+-={}[]:\";'<>,.?/'";
private static final String ALPHANUMERIC = "Bxz91r";
private static final String ALPHA = "acgrdft";
private static final String EMPTY_STRING = "";
- private static final String ACCENTED = "seg\u00FAn cu\u00E1l oto\u00F1o";
+ private static final String ACCENTED = "seg\u00FAn cu\u00E1l oto\u00F1o";
private static final String CHINESE = "\u4ECA\u5929\u662F\u5929";
private void encodeDecode(String value) {
@@ -33,86 +36,102 @@ public class UrlCoderTest extends TestCase {
String encoded = URLCoder.compactEncode(value);
assertEquals(value, URLCoder.decode(encoded));
}
-
+
private boolean compactEncodingIsShorter(String value) {
String compactEncoded = URLCoder.compactEncode(value);
String encoded = URLCoder.encode(value);
return compactEncoded.length() < encoded.length();
}
+ @Test
public void testEncodeEmpty() {
encodeDecode(EMPTY_STRING);
- }
+ }
+ @Test
public void testEncodeAlphabetic() {
encodeDecode(ALPHA);
- }
-
+ }
+
+ @Test
public void testEncodeAlphaNumeric() {
encodeDecode(ALPHANUMERIC);
}
-
+
+ @Test
public void testEncodeSpecialCharacters() {
encodeDecode(SPECIAL_CHARACTERS);
- }
-
+ }
+
+ @Test
public void testEncodeAccented() {
encodeDecode(ACCENTED);
}
-
+
+ @Test
public void testEncodeChinese() {
encodeDecode(CHINESE);
}
-
- // Compact Encodings
+ // Compact Encodings
+ @Test
public void testCompactEncodeEmpty() {
compactEncodeDecode(EMPTY_STRING);
- }
+ }
+ @Test
public void testCompactEncodeAlphabetic() {
compactEncodeDecode(ALPHA);
- }
-
+ }
+
+ @Test
public void testCompactEncodeAlphaNumeric() {
compactEncodeDecode(ALPHANUMERIC);
}
-
+
+ @Test
public void testCompactEncodeSpecialCharacters() {
compactEncodeDecode(SPECIAL_CHARACTERS);
- }
-
+ }
+
+ @Test
public void testCompactEncodeAccented() {
compactEncodeDecode(ACCENTED);
}
-
+
+ @Test
public void testCompactEncodeChinese() {
compactEncodeDecode(CHINESE);
}
-
+
// Verify compaction
-
+ @Test
public void testCompactionEmpty() {
assertFalse(compactEncodingIsShorter(EMPTY_STRING));
- }
+ }
+ @Test
public void testCompactionAlphabetic() {
assertTrue(compactEncodingIsShorter(ALPHA));
- }
-
+ }
+
+ @Test
public void testCompactionAlphaNumeric() {
assertTrue(compactEncodingIsShorter(ALPHANUMERIC));
}
-
+
+ @Test
public void testCompactionSpecialCharacters() {
assertTrue(compactEncodingIsShorter(SPECIAL_CHARACTERS));
- }
-
+ }
+
+ @Test
public void testCompactionAccented() {
assertTrue(compactEncodingIsShorter(ACCENTED));
}
-
+
+ @Test
public void testCompactionChinese() {
assertFalse(compactEncodingIsShorter(CHINESE));
}
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));
}
-
-
+
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java
index d93059b25..a392ba7ba 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/ExtensionServiceTest.java
@@ -1,16 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 IBM Corporation and others.
+ * Copyright (c) 2011, 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.service;
+import static org.junit.Assert.assertEquals;
+
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
@@ -19,99 +21,107 @@ import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import junit.framework.TestCase;
-
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.entityresolver.LocalEntityResolver;
import org.eclipse.help.internal.server.WebappManager;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
-public class ExtensionServiceTest extends TestCase {
+public class ExtensionServiceTest {
private int mode;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
BaseHelpSystem.ensureWebappRunning();
mode = BaseHelpSystem.getMode();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
}
-
- @Override
- protected void tearDown() throws Exception {
+
+ @After
+ public void tearDown() throws Exception {
BaseHelpSystem.setMode(mode);
}
+ @Test
public void testExtensionServiceContributionExactMatch1() throws Exception {
Node root = getContentExtensions("en");
- Element[] UARoot = findContributionByContent(root,
+ Element[] UARoot = findContributionByContent(root,
"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.1");
assertEquals(1, UARoot.length);
}
+ @Test
public void testExtensionServiceContributionExactMatch3() throws Exception {
Node root = getContentExtensions("en");
- Element[] UARoot = findContributionByContent(root,
+ Element[] UARoot = findContributionByContent(root,
"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.3");
assertEquals(1, UARoot.length);
}
-
+
+ @Test
public void testExtensionServiceContributionNoMatch() throws Exception {
Node root = getContentExtensions("en");
- Element[] UARoot = findContributionByContent(root,
+ Element[] UARoot = findContributionByContent(root,
"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.4");
assertEquals(0, UARoot.length);
}
-
+
+ @Test
public void testExtensionServiceContributionByPath() throws Exception {
Node root = getContentExtensions("en");
- Element[] UARoot = findContributionByPath(root,
+ Element[] UARoot = findContributionByPath(root,
"/org.eclipse.ua.tests/data/help/dynamic/extension.xml#anchor.invalidcontribution");
assertEquals(2, UARoot.length);
}
+ @Test
public void testExtensionServiceReplacementExactMatch() throws Exception {
Node root = getContentExtensions("en");
- Element[] UARoot = findReplacementByContent(root,
+ Element[] UARoot = findReplacementByContent(root,
"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.1");
assertEquals(1, UARoot.length);
}
-
+
+ @Test
public void testExtensionServiceReplacementNoMatch() throws Exception {
Node root = getContentExtensions("en");
- Element[] UARoot = findReplacementByContent(root,
+ Element[] UARoot = findReplacementByContent(root,
"/org.eclipse.ua.tests/data/help/dynamic/shared/doc2.xml#element.3");
assertEquals(0, UARoot.length);
}
-
+
+ @Test
public void testExtensionServiceReplacementByPath() throws Exception {
Node root = getContentExtensions("en");
- Element[] UARoot = findReplacementByPath(root,
+ Element[] UARoot = findReplacementByPath(root,
"/org.eclipse.ua.tests/data/help/dynamic/shared/doc1.xml#element.2");
assertEquals(1, UARoot.length);
}
-
+
private Element[] findContributionByContent(Node root, String content) {
return findChildren(root, "contribution", "content", content);
}
-
+
private Element[] findContributionByPath(Node root, String path) {
return findChildren(root, "contribution", "path", path);
}
-
+
private Element[] findReplacementByContent(Node root, String content) {
return findChildren(root, "replacement", "content", content);
}
-
+
private Element[] findReplacementByPath(Node root, String path) {
return findChildren(root, "replacement", "path", path);
}
-
- private Element[] findChildren(Node parent, String childKind,
+
+ private Element[] findChildren(Node parent, String childKind,
String attributeName, String attributeValue) {
NodeList contributions = parent.getChildNodes();
List<Node> results = new ArrayList<Node>();
@@ -120,8 +130,8 @@ public class ExtensionServiceTest extends TestCase {
if (next instanceof Element) {
Element nextElement = (Element)next;
if ( childKind.equals(nextElement.getTagName()) && attributeValue.equals(nextElement.getAttribute(attributeName))) {
-
- results.add(next);
+
+ results.add(next);
}
}
}
@@ -143,7 +153,8 @@ public class ExtensionServiceTest extends TestCase {
return root;
}
- public void testExtensionFragmentServiceXMLSchema()
+ @Test
+ public void testExtensionFragmentServiceXMLSchema()
throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/vs/service/extension?lang=en");
@@ -151,11 +162,12 @@ public class ExtensionServiceTest extends TestCase {
String schema = schemaUrl.toString();
String uri = url.toString();
String result = SchemaValidator.testXMLSchema(uri, schema);
-
+
assertEquals("URL: \"" + uri + "\" is ", "valid", result);
}
- public void testExtensionFragmentServiceJSONSchema()
+ @Test
+ public void testExtensionFragmentServiceJSONSchema()
throws Exception {
// fail("Not yet implemented.");
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java
index 3baf5fba5..a3f2f9709 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/IndexFragmentServiceTest.java
@@ -1,51 +1,56 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 IBM Corporation and others.
+ * Copyright (c) 2011, 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.service;
+import static org.junit.Assert.assertEquals;
+
import java.io.InputStream;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import junit.framework.TestCase;
-
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.entityresolver.LocalEntityResolver;
import org.eclipse.help.internal.server.WebappManager;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
-public class IndexFragmentServiceTest extends TestCase {
+public class IndexFragmentServiceTest {
private int mode;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
BaseHelpSystem.ensureWebappRunning();
mode = BaseHelpSystem.getMode();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
}
-
- @Override
- protected void tearDown() throws Exception {
+
+ @After
+ public void tearDown() throws Exception {
BaseHelpSystem.setMode(mode);
}
+ @Test
public void testIndexServletEn() throws Exception {
getTreeData("en");
}
+ @Test
public void testIndexServletDe() throws Exception {
getTreeData("de");
}
@@ -64,7 +69,8 @@ public class IndexFragmentServiceTest extends TestCase {
assertEquals("tree_data", root.getNodeName());
}
- public void testIndexFragmentServiceXMLSchema()
+ @Test
+ public void testIndexFragmentServiceXMLSchema()
throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/vs/service/indexfragment?lang=en");
@@ -72,11 +78,12 @@ public class IndexFragmentServiceTest extends TestCase {
String schema = schemaUrl.toString();
String uri = url.toString();
String result = SchemaValidator.testXMLSchema(uri, schema);
-
+
assertEquals("URL: \"" + uri + "\" is ", "valid", result);
}
- public void testIndexFragmentServiceJSONSchema()
+ @Test
+ public void testIndexFragmentServiceJSONSchema()
throws Exception {
// fail("Not yet implemented.");
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java
index 228827aae..4f601e86a 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/webapp/service/TocFragmentServiceTest.java
@@ -1,15 +1,18 @@
/*******************************************************************************
- * Copyright (c) 2011, 2015 IBM Corporation and others.
+ * Copyright (c) 2011, 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.service;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
@@ -18,81 +21,85 @@ import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import junit.framework.TestCase;
-
import org.eclipse.help.ITopic;
import org.eclipse.help.internal.HelpPlugin;
import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.entityresolver.LocalEntityResolver;
import org.eclipse.help.internal.server.WebappManager;
import org.eclipse.help.internal.toc.Toc;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
-public class TocFragmentServiceTest extends TestCase {
+public class TocFragmentServiceTest {
private int mode;
- @Override
- protected void setUp() throws Exception {
+ @Before
+ public void setUp() throws Exception {
BaseHelpSystem.ensureWebappRunning();
mode = BaseHelpSystem.getMode();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
}
-
- @Override
- protected void tearDown() throws Exception {
+
+ @After
+ public void tearDown() throws Exception {
BaseHelpSystem.setMode(mode);
}
+ @Test
public void testTocFragmentServiceContainsUAToc() throws Exception {
int port = WebappManager.getPort();
- URL url = new URL("http", "localhost", port,
+ URL url = new URL("http", "localhost", port,
"/help/vs/service/tocfragment?lang=en");
Node root = getTreeData(url);
- Element[] UARoot = findNodeById(root,
+ Element[] UARoot = findNodeById(root,
"/org.eclipse.ua.tests/data/help/toc/root.xml");
assertEquals(1, UARoot.length);
}
+ @Test
public void testTocFragmentServiceContainsFilteredToc() throws Exception {
int port = WebappManager.getPort();
- URL url = new URL("http", "localhost", port,
+ URL url = new URL("http", "localhost", port,
"/help/vs/service/tocfragment?lang=en&toc=/org.eclipse.ua.tests/data/help/toc/root.xml&path=2");
Node root = getTreeData(url);
- Element[] UARoot = findNodeById(root,
+ Element[] UARoot = findNodeById(root,
"/org.eclipse.ua.tests/data/help/toc/root.xml");
assertEquals(1, UARoot.length);
Element[] filterNode = findNodeById(UARoot[0], "2");
assertEquals(1, filterNode.length);
- Element[] results = findHref(filterNode[0], "node",
+ Element[] results = findHref(filterNode[0], "node",
"../topic/org.eclipse.ua.tests/data/help/toc/filteredToc/simple_page.html");
assertEquals(24, results.length);
-
- results = findHref(filterNode[0], "node",
+
+ results = findHref(filterNode[0], "node",
"../topic/org.eclipse.ua.tests/data/help/toc/filteredToc/helpInstalled.html");
assertEquals(1, results.length);
}
-
+
+ @Test
public void testTocFragmentServiceReadEnToc() throws Exception {
int uaSearch = findUATopicIndex("search", "en");
assertTrue(uaSearch >= 0);
int port = WebappManager.getPort();
- URL url = new URL("http", "localhost", port,
+ URL url = new URL("http", "localhost", port,
"/help/vs/service/tocfragment?lang=en&toc=/org.eclipse.ua.tests/data/help/toc/root.xml&path=" + uaSearch);
Node root = getTreeData(url);
- Element[] UARoot = findNodeById(root,
+ Element[] UARoot = findNodeById(root,
"/org.eclipse.ua.tests/data/help/toc/root.xml");
assertEquals(1, UARoot.length);
Element[] searchNode = findChildren(UARoot[0], "node", "title", "search");
assertEquals(1, searchNode.length);
- Element[] topicEn = findHref(searchNode[0], "node",
+ Element[] topicEn = findHref(searchNode[0], "node",
"../topic/org.eclipse.ua.tests/data/help/search/test_en.html");
assertEquals(1, topicEn.length);
- Element[] topicDe = findHref(searchNode[0], "node",
+ Element[] topicDe = findHref(searchNode[0], "node",
"../topic/org.eclipse.ua.tests/data/help/search/test_de.html");
assertEquals(0, topicDe.length);
}
@@ -111,35 +118,36 @@ public class TocFragmentServiceTest extends TestCase {
}
}
return index;
- }
-
+ }
+
+ @Test
public void testTocFragmentServiceReadDeToc() throws Exception {
int helpMode = BaseHelpSystem.getMode();
BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER);
int uaSearch = findUATopicIndex("search", "de");
assertTrue(uaSearch >= 0);
int port = WebappManager.getPort();
- URL url = new URL("http", "localhost", port,
+ URL url = new URL("http", "localhost", port,
"/help/vs/service/tocfragment?lang=de&toc=/org.eclipse.ua.tests/data/help/toc/root.xml&path=" + uaSearch);
Node root = getTreeData(url);
- Element[] UARoot = findNodeById(root,
+ Element[] UARoot = findNodeById(root,
"/org.eclipse.ua.tests/data/help/toc/root.xml");
assertEquals(1, UARoot.length);
Element[] searchNode = findChildren(UARoot[0], "node", "title", "search");
- Element[] topicEn = findHref(searchNode[0], "node",
+ Element[] topicEn = findHref(searchNode[0], "node",
"../topic/org.eclipse.ua.tests/data/help/search/test_en.html");
assertEquals(0, topicEn.length);
- Element[] topicDe = findHref(searchNode[0], "node",
+ Element[] topicDe = findHref(searchNode[0], "node",
"../topic/org.eclipse.ua.tests/data/help/search/test_de.html");
assertEquals(1, topicDe.length);
BaseHelpSystem.setMode(helpMode);
}
-
+
private Element[] findNodeById(Node root, String id) {
return findChildren(root, "node", "id", id);
}
- private Element[] findChildren(Node parent, String childKind,
+ private Element[] findChildren(Node parent, String childKind,
String attributeName, String attributeValue) {
NodeList nodes = parent.getChildNodes();
List<Node> results = new ArrayList<Node>();
@@ -147,20 +155,20 @@ public class TocFragmentServiceTest extends TestCase {
Node next = nodes.item(i);
if (next instanceof Element) {
Element nextElement = (Element)next;
- if ( childKind.equals(nextElement.getTagName())
+ if ( childKind.equals(nextElement.getTagName())
&& attributeValue.equals(nextElement.getAttribute(attributeName))) {
-
- results.add(next);
+
+ results.add(next);
}
}
}
return results.toArray(new Element[results.size()]);
}
-
+
/*
* Look for a matching href, the query part of the href is not compared
*/
- private Element[] findHref(Node parent, String childKind,
+ private Element[] findHref(Node parent, String childKind,
String attributeValue) {
NodeList nodes = parent.getChildNodes();
List<Node> results = new ArrayList<Node>();
@@ -175,8 +183,8 @@ public class TocFragmentServiceTest extends TestCase {
if (query >= 0) {
href = href.substring(0, query);
}
- if (href.equals (attributeValue)) {
- results.add(next);
+ if (href.equals (attributeValue)) {
+ results.add(next);
}
}
}
@@ -184,7 +192,7 @@ public class TocFragmentServiceTest extends TestCase {
}
return results.toArray(new Element[results.size()]);
}
-
+
private Node getTreeData(URL url)
throws Exception {
@@ -199,7 +207,8 @@ public class TocFragmentServiceTest extends TestCase {
return root;
}
- public void testTocFragmentServiceXMLSchema()
+ @Test
+ public void testTocFragmentServiceXMLSchema()
throws Exception {
int port = WebappManager.getPort();
URL url = new URL("http", "localhost", port, "/help/vs/service/tocfragment?lang=en");
@@ -207,12 +216,12 @@ public class TocFragmentServiceTest extends TestCase {
String schema = schemaUrl.toString();
String uri = url.toString();
String result = SchemaValidator.testXMLSchema(uri, schema);
-
+
assertEquals("URL: \"" + uri + "\" is ", "valid", result);
}
-
+
/*
- public void testTocFragmentServiceJSONSchema()
+ public void testTocFragmentServiceJSONSchema()
throws Exception {
fail("Not yet implemented.");
}

Back to the top