Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2009-10-08 23:24:31 +0000
committerChris Goldthorpe2009-10-08 23:24:31 +0000
commit7199504c1b1a911db0664bfe5cc75e157cbd6cc9 (patch)
tree3b6bd175aef2fde1efdb2e483331601775ec8fd1
parent69b03cb32f5955a8ebdb5412ede15c5924230fee (diff)
downloadeclipse.platform.ua-7199504c1b1a911db0664bfe5cc75e157cbd6cc9.tar.gz
eclipse.platform.ua-7199504c1b1a911db0664bfe5cc75e157cbd6cc9.tar.xz
eclipse.platform.ua-7199504c1b1a911db0664bfe5cc75e157cbd6cc9.zip
Add new tests
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java2
-rwxr-xr-xorg.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java34
-rwxr-xr-xorg.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/SearchServletTest.java96
3 files changed, 132 insertions, 0 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java
index 26de3b912..65f14e38b 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/AllHelpTests.java
@@ -17,6 +17,7 @@ import org.eclipse.ua.tests.help.dynamic.AllDynamicTests;
import org.eclipse.ua.tests.help.index.AllIndexTests;
import org.eclipse.ua.tests.help.other.AllOtherHelpTests;
import org.eclipse.ua.tests.help.preferences.AllPreferencesTests;
+import org.eclipse.ua.tests.help.remote.AllRemoteTests;
import org.eclipse.ua.tests.help.search.AllSearchTests;
import org.eclipse.ua.tests.help.toc.AllTocTests;
import org.eclipse.ua.tests.help.webapp.AllWebappTests;
@@ -44,5 +45,6 @@ public class AllHelpTests extends TestSuite {
addTest(AllIndexTests.suite());
addTest(AllWebappTests.suite());
addTest(AllOtherHelpTests.suite());
+ addTest(AllRemoteTests.suite());
}
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java
new file mode 100755
index 000000000..45ac1c549
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/AllRemoteTests.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2006 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.remote;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/*
+ * Tests help keyword index functionality.
+ */
+public class AllRemoteTests extends TestSuite {
+
+ /*
+ * Returns the entire test suite.
+ */
+ public static Test suite() {
+ return new AllRemoteTests();
+ }
+
+ /*
+ * Constructs a new test suite.
+ */
+ public AllRemoteTests() {
+ addTestSuite(SearchServletTest.class);
+ }
+}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/SearchServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/SearchServletTest.java
new file mode 100755
index 000000000..2a0240688
--- /dev/null
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/SearchServletTest.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.remote;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+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.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+public class SearchServletTest extends TestCase {
+
+ protected void setUp() throws Exception {
+ BaseHelpSystem.ensureWebappRunning();
+ }
+
+ public void testRemoteSearchNotFound() throws Exception {
+ Node[] hits = getSearchHitsFromServlet("duernfryehd");
+ assertEquals(0, hits.length);
+ }
+
+ public void testRemoteSearchFound() throws Exception {
+ Node[] hits = getSearchHitsFromServlet("jehcyqpfjs");
+ assertEquals(1, hits.length);
+ }
+
+ public void testRemoteSearchOrFound() throws Exception {
+ Node[] hits = getSearchHitsFromServlet("jehcyqpfjs OR duernfryehd");
+ assertEquals(1, hits.length);
+ }
+
+ public void testRemoteSearchAndFound() throws Exception {
+ Node[] hits = getSearchHitsFromServlet("jehcyqpfjs AND vkrhjewiwh");
+ assertEquals(1, hits.length);
+ }
+
+ public void testRemoteSearchAndNotFound() throws Exception {
+ Node[] hits = getSearchHitsFromServlet("jehcyqpfjs AND duernfryehd");
+ assertEquals(0, hits.length);
+ }
+
+ public void testRemoteSearchExactMatchFound() throws Exception {
+ Node[] hits = getSearchHitsFromServlet("\"jehcyqpfjs vkrhjewiwh\"");
+ assertEquals(1, hits.length);
+ }
+
+ public void testRemoteSearchExactMatchNotFound() throws Exception {
+ Node[] hits = getSearchHitsFromServlet("\"vkrhjewiwh jehcyqpfjs\"");
+ assertEquals(0, hits.length);
+ }
+
+ private Node[] getSearchHitsFromServlet(String phrase)
+ throws Exception {
+ int port = WebappManager.getPort();
+ URL url = new URL("http", "localhost", port, "/help/search?phrase=" + URLEncoder.encode(phrase, "UTF-8"));
+ InputStream is = url.openStream();
+ InputSource inputSource = new InputSource(is);
+ DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ documentBuilder.setEntityResolver(new LocalEntityResolver());
+ Document document = documentBuilder.parse(inputSource);
+ Node root = document.getFirstChild();
+ assertEquals("searchHits", root.getNodeName());
+ NodeList children = root.getChildNodes();
+ List hits = new ArrayList();
+ int length = children.getLength();
+ for (int i = 0; i < length; i++) {
+ Node next = children.item(i);
+ if ("hit".equals(next.getNodeName())) {
+ hits.add(next);
+ }
+ }
+ return (Node[]) hits.toArray(new Node[hits.size()]);
+ }
+
+}

Back to the top