Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Goldthorpe2008-03-16 23:53:09 +0000
committerChris Goldthorpe2008-03-16 23:53:09 +0000
commitdac2f1fe004cfe6eb980c8fb57c10f2e2d081426 (patch)
tree5341295ad7824f7b11e4238129458f3e687096b7 /org.eclipse.ua.tests
parent477966a3f3e416b16111686a9fbf54a6912dbb3d (diff)
downloadeclipse.platform.ua-dac2f1fe004cfe6eb980c8fb57c10f2e2d081426.tar.gz
eclipse.platform.ua-dac2f1fe004cfe6eb980c8fb57c10f2e2d081426.tar.xz
eclipse.platform.ua-dac2f1fe004cfe6eb980c8fb57c10f2e2d081426.zip
Bug 222895 – [CheatSheet] Failing Junit tests in I20080314-1059v20080316
Diffstat (limited to 'org.eclipse.ua.tests')
-rw-r--r--org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/ResourceFinder.java41
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java67
-rw-r--r--org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java83
-rw-r--r--org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java44
4 files changed, 154 insertions, 81 deletions
diff --git a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/ResourceFinder.java b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/ResourceFinder.java
index f3bb73d29..87b9cfa16 100644
--- a/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/ResourceFinder.java
+++ b/org.eclipse.ua.tests/base/org/eclipse/ua/tests/util/ResourceFinder.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2002, 2006 IBM Corporation and others.
+ * Copyright (c) 2002, 2008 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
@@ -15,14 +15,13 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Enumeration;
import java.util.List;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
-import org.osgi.framework.Bundle;
/*
* Utility methods for finding resources.
@@ -33,26 +32,7 @@ public class ResourceFinder {
* Finds the specified file in the given plugin and returns a URL to it.
*/
public static URL findFile(Plugin plugin, String path) {
- String fullLocation = plugin.getBundle().getLocation();
- String location = fullLocation.substring(fullLocation.indexOf('@') + 1);
- IPath fullPath = new Path(location).append(path);
- File file = fullPath.toFile();
-
- /*
- * If it's a relative path, append it to the install location.
- */
- if (!file.exists()) {
- fullPath = new Path(Platform.getInstallLocation().getURL().toString().substring("file:".length()) + fullPath);
- file = fullPath.toFile();
- }
-
- try {
- return file.toURL();
- }
- catch (MalformedURLException e) {
- e.printStackTrace();
- return null;
- }
+ return FileLocator.find(plugin.getBundle(), new Path(path), null);
}
/*
@@ -108,19 +88,4 @@ public class ResourceFinder {
return array;
}
- /*
- * Finds all files in the given bundle under the given path that end with
- * the given suffix. Returns bundle-relative paths.
- */
- public static String[] findFiles(Bundle bundle, String path, String suffix) {
- List list = new ArrayList();
- Enumeration e = bundle.getEntryPaths(path);
- while (e.hasMoreElements()) {
- String entry = (String)e.nextElement();
- if (entry.endsWith(suffix)) {
- list.add(entry);
- }
- }
- return (String[])list.toArray(new String[list.size()]);
- }
}
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java
index afcab3306..3b473de31 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/TolerateTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * Copyright (c) 2000, 2008 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
@@ -17,9 +17,10 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
-import org.eclipse.ua.tests.util.ResourceFinder;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheet;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetParser;
@@ -35,18 +36,54 @@ public class TolerateTest extends TestCase {
public static Test suite() {
return new TestSuite(TolerateTest.class);
}
-
- /*
- * Test cheat sheets that are not quite correct, but are tolerated by the parser.
- */
- public void testParserTolerate() {
- URL[] urls = ResourceFinder.findFiles(UserAssistanceTestPlugin.getDefault(), "data/cheatsheet/valid/tolerate", ".xml", true);
- Assert.assertTrue("Unable to find sample cheat sheets to test parser", urls.length > 0);
- for (int i=0;i<urls.length;++i) {
- CheatSheetParser parser = new CheatSheetParser();
- CheatSheet sheet = (CheatSheet)parser.parse(urls[i], UserAssistanceTestPlugin.getPluginId(), CheatSheetParser.SIMPLE_ONLY);
- Assert.assertEquals("Warning not generated: " + urls[i], IStatus.WARNING, parser.getStatus().getSeverity());
- Assert.assertNotNull("Tried parsing a tolerable cheat sheet but parser returned null: " + urls[i], sheet);
- }
+
+ private void parseCheatsheet(String file) {
+ Path path = new Path("data/cheatsheet/valid/tolerate/" + file);
+ URL url = FileLocator.find(UserAssistanceTestPlugin.getDefault().getBundle(), path, null);
+ CheatSheetParser parser = new CheatSheetParser();
+ CheatSheet sheet = (CheatSheet)parser.parse(url, UserAssistanceTestPlugin.getPluginId(), CheatSheetParser.SIMPLE_ONLY);
+ Assert.assertEquals("Warning not generated: " + url, IStatus.WARNING, parser.getStatus().getSeverity());
+ Assert.assertNotNull("Tried parsing a tolerable cheat sheet but parser returned null: " + url, sheet);
}
+
+ public void testItemExtraAttr() {
+ parseCheatsheet("ItemElement_ExtraAttr.xml");
+ }
+
+ public void testIntroExtraElement() {
+ parseCheatsheet("IntroElement_ExtraElement.xml");
+ }
+
+ public void testIntroExtraAttr() {
+ parseCheatsheet("IntroElement_ExtraAttr.xml");
+ }
+
+ public void testDescExtraElement() {
+ parseCheatsheet("DescriptionElement_ExtraElements.xml");
+ }
+
+ public void testConditionalExtraElement() {
+ parseCheatsheet("ConditionalSubItem_ExtraElement.xml");
+ }
+
+ public void testConditionalExtraAttr() {
+ parseCheatsheet("ConditionalSubItem_ExtraAttr.xml");
+ }
+
+ public void testElementExtraElement() {
+ parseCheatsheet("CheatSheetElement_ExtraElement.xml");
+ }
+
+ public void testElementExtraAttr() {
+ parseCheatsheet("CheatSheetElement_ExtraAttr.xml");
+ }
+
+ public void testExtraElement() {
+ parseCheatsheet("ActionElement_ExtraElement.xml");
+ }
+
+ public void testExtraAttr() {
+ parseCheatsheet("ActionElement_ExtraAttr.xml");
+ }
+
}
diff --git a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java
index 94ca1880b..d396c4976 100644
--- a/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java
+++ b/org.eclipse.ua.tests/cheatsheet/org/eclipse/ua/tests/cheatsheet/parser/ValidTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2006 IBM Corporation and others.
+ * Copyright (c) 2005, 2008 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
@@ -18,12 +18,14 @@ import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Path;
import org.eclipse.ua.tests.cheatsheet.util.CheatSheetModelSerializer;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.eclipse.ua.tests.util.FileUtil;
-import org.eclipse.ua.tests.util.ResourceFinder;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheet;
import org.eclipse.ui.internal.cheatsheets.data.CheatSheetParser;
+import org.osgi.framework.Bundle;
/*
* Tests the cheat sheets parser on valid cheat sheets.
@@ -37,21 +39,66 @@ public class ValidTest extends TestCase {
return new TestSuite(ValidTest.class);
}
- /*
- * Test valid cheat sheets.
- */
- public void testParserValid() throws IOException {
- URL[] urls = ResourceFinder.findFiles(UserAssistanceTestPlugin.getDefault(), "data/cheatsheet/valid", ".xml", false);
- Assert.assertTrue("Unable to find sample cheat sheets to test parser", urls.length > 0);
- for (int i=0;i<urls.length;++i) {
- CheatSheetParser parser = new CheatSheetParser();
- CheatSheet sheet = (CheatSheet)parser.parse(urls[i], UserAssistanceTestPlugin.getPluginId(), CheatSheetParser.ANY);
- Assert.assertNotNull("Tried parsing a valid cheat sheet but parser returned null: " + urls[i], sheet);
-
- String path = urls[i].toString().substring("file:".length());
- String expected = FileUtil.getContents(FileUtil.getResultFile(path));
- String actual = CheatSheetModelSerializer.serialize(sheet);
- Assert.assertEquals("The model serialization generated for the cheatsheet did not match the expected result for: " + path, expected, actual);
- }
+ private void parseCheatsheet(String file) throws IOException {
+ Path path = new Path("data/cheatsheet/valid/" + file);
+ Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle();
+ URL url = FileLocator.find(bundle, path, null);
+ CheatSheetParser parser = new CheatSheetParser();
+ CheatSheet sheet = (CheatSheet)parser.parse(url, UserAssistanceTestPlugin.getPluginId(), CheatSheetParser.ANY);
+ Assert.assertNotNull("Tried parsing a valid cheat sheet but parser returned null: " + url, sheet);
+ String expectedPath = "data/cheatsheet/valid/" + getExpected(file);
+ String expected = FileUtil.getContents(bundle, expectedPath);
+ String actual = CheatSheetModelSerializer.serialize(sheet);
+ Assert.assertEquals("The model serialization generated for the cheatsheet did not match the expected result for: " + path, expected, actual);
+ }
+
+ private String getExpected(String file) {
+ int suffix = file.lastIndexOf(".xml");
+ return file.substring(0, suffix) + "_expected.txt";
+ }
+
+ public void testSubItems() throws IOException {
+ parseCheatsheet("TestSubItems.xml");
+ }
+
+ public void testParameters() throws IOException {
+ parseCheatsheet("TestParameters.xml");
+ }
+
+ public void testOpeningURL() throws IOException {
+ parseCheatsheet("TestOpeningURL.xml");
+ }
+
+ public void testDynamicSubitems() throws IOException {
+ parseCheatsheet("TestDynamicSubItems.xml");
+ }
+
+ public void testDescriptionFormatting() throws IOException {
+ parseCheatsheet("TestDescriptionFormatting.xml");
}
+
+ public void testCSActions() throws IOException {
+ parseCheatsheet("TestCSActions.xml");
+ }
+
+ public void testContextHelp() throws IOException {
+ parseCheatsheet("TestContext_Help.xml");
+ }
+
+ public void testActions() throws IOException {
+ parseCheatsheet("TestActions.xml");
+ }
+
+ public void testHelloWorldWithSubitems() throws IOException {
+ parseCheatsheet("HelloWorldWithSubitems.xml");
+ }
+
+ public void testHelloWorldWithExtensions() throws IOException {
+ parseCheatsheet("HelloWorldWithExtensions.xml");
+ }
+
+ public void testHelloWorld() throws IOException {
+ parseCheatsheet("HelloWorld.xml");
+ }
+
}
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java
index 6c4572a9d..ff2986b1c 100644
--- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java
+++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/dynamic/XMLProcessorTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2006, 2007 IBM Corporation and others.
+ * Copyright (c) 2006, 2008 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
@@ -27,7 +27,6 @@ import org.eclipse.help.internal.dynamic.XMLProcessor;
import org.eclipse.help.ui.internal.HelpUIPlugin;
import org.eclipse.ua.tests.plugin.UserAssistanceTestPlugin;
import org.eclipse.ua.tests.util.FileUtil;
-import org.eclipse.ua.tests.util.ResourceFinder;
import org.eclipse.ua.tests.util.XMLUtil;
import org.osgi.framework.Bundle;
@@ -44,8 +43,8 @@ public class XMLProcessorTest extends TestCase {
// activate the UI plug-in for UI filtering ability
HelpUIPlugin.getDefault();
}
-
- public void testXMLProcessor() throws Exception {
+
+ private void xmlProcess(String path) throws Exception {
DocumentReader reader = new DocumentReader();
ProcessorHandler[] handlers = new ProcessorHandler[] {
new IncludeHandler(reader, Platform.getNL()),
@@ -54,11 +53,36 @@ public class XMLProcessorTest extends TestCase {
};
XMLProcessor processor = new XMLProcessor(handlers);
Bundle bundle = UserAssistanceTestPlugin.getDefault().getBundle();
- String[] paths = ResourceFinder.findFiles(bundle, "data/help/dynamic", ".xml");
- for (int i=0;i<paths.length;++i) {
- InputStream in = bundle.getEntry(FileUtil.getResultFile(paths[i])).openStream();
- InputStream in2 = processor.process(bundle.getEntry(paths[i]).openStream(), '/' + bundle.getSymbolicName() + '/' + paths[i], "UTF-8");
- XMLUtil.assertXMLEquals("XML content was not processed correctly: " + paths[i], in, in2);
- }
+ InputStream in = bundle.getEntry(FileUtil.getResultFile(path)).openStream();
+ InputStream in2 = processor.process(bundle.getEntry(path).openStream(), '/' + bundle.getSymbolicName() + '/' + path, "UTF-8");
+ XMLUtil.assertXMLEquals("XML content was not processed correctly: " + path, in, in2);
+ }
+
+ public void testExtension() throws Exception {
+ xmlProcess("data/help/dynamic/extension.xml");
+ }
+
+ public void testFilter() throws Exception {
+ xmlProcess("data/help/dynamic/filter.xml");
+ }
+
+ public void testInclude() throws Exception {
+ xmlProcess("data/help/dynamic/include.xml");
+ }
+
+ public void testIndex() throws Exception {
+ xmlProcess("data/help/dynamic/index.xml");
+ }
+
+ public void testSimple() throws Exception {
+ xmlProcess("data/help/dynamic/simple.xml");
+ }
+
+ public void testToc() throws Exception {
+ xmlProcess("data/help/dynamic/toc.xml");
+ }
+
+ public void testXhtml() throws Exception {
+ xmlProcess("data/help/dynamic/xhtml.xml");
}
}

Back to the top