Bug 313992: [xpath] [patch] XPath evaluation does not show results which are atomic https://bugs.eclipse.org/bugs/show_bug.cgi?id=313992
diff --git a/tests/org.eclipse.wst.xml.xpath.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.wst.xml.xpath.ui.tests/META-INF/MANIFEST.MF index 9e7625b..9214bba 100644 --- a/tests/org.eclipse.wst.xml.xpath.ui.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.wst.xml.xpath.ui.tests/META-INF/MANIFEST.MF
@@ -2,16 +2,18 @@ Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.wst.xml.xpath.ui.tests -Bundle-Version: 1.0.0.qualifier +Bundle-Version: 1.0.100.qualifier Bundle-Activator: org.eclipse.wst.xml.xpath.ui.tests.XPathUITestPlugin Bundle-Vendor: %Bundle-Vendor -Require-Bundle: org.eclipse.wst.xml.xpath.core;bundle-version="1.1.0", - org.eclipse.wst.xml.xpath.ui;bundle-version="1.1.0", +Require-Bundle: org.eclipse.wst.xml.xpath.core;bundle-version="1.1.100", + org.eclipse.wst.xml.xpath.ui;bundle-version="1.1.100", org.eclipse.core.runtime, org.junit;bundle-version="3.8.2", org.eclipse.ui;bundle-version="3.5.0", + org.eclipse.wst.xml.core;bundle-version="[1.1.0,2.0.0)", org.eclipse.wst.xml.xpath2;bundle-version="1.1.0", - org.eclipse.core.runtime.compatibility;bundle-version="3.2.0" + org.eclipse.core.runtime.compatibility;bundle-version="3.2.0", + org.eclipse.wst.sse.core;bundle-version="1.1.500" Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.wst.xml.xpath.ui.internal.hander.tests;x-internal:=true,
diff --git a/tests/org.eclipse.wst.xml.xpath.ui.tests/src/org/eclipse/wst/xml/xpath/ui/internal/views/tests/TestXPathComputer.java b/tests/org.eclipse.wst.xml.xpath.ui.tests/src/org/eclipse/wst/xml/xpath/ui/internal/views/tests/TestXPathComputer.java new file mode 100644 index 0000000..621a9c8 --- /dev/null +++ b/tests/org.eclipse.wst.xml.xpath.ui.tests/src/org/eclipse/wst/xml/xpath/ui/internal/views/tests/TestXPathComputer.java
@@ -0,0 +1,213 @@ +/******************************************************************************* + * Copyright (c) 2010 Jesper Steen Moller - jesper@selskabet.org + * 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: + * Jesper Steen Moller - initial API and implementation + *******************************************************************************/ + +package org.eclipse.wst.xml.xpath.ui.internal.views.tests; + +import java.lang.reflect.InvocationTargetException; + +import javax.xml.xpath.XPathExpressionException; + +import junit.framework.TestCase; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.operation.IRunnableContext; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IKeyBindingService; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.progress.IWorkbenchSiteProgressService; +import org.eclipse.wst.xml.core.internal.document.DOMModelImpl; +import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel; +import org.eclipse.wst.xml.xpath.core.XPathProcessorPreferences; +import org.eclipse.wst.xml.xpath.core.util.XPathCoreHelper; +import org.eclipse.wst.xml.xpath.ui.internal.hander.tests.StubXPathProcessorHandler; +import org.eclipse.wst.xml.xpath.ui.internal.views.XPathComputer; +import org.eclipse.wst.xml.xpath.ui.internal.views.XPathView; +import org.osgi.service.prefs.Preferences; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.Text; + +@SuppressWarnings("deprecation") +public class TestXPathComputer extends TestCase { + + private final class MockXPathView extends XPathView { + + private NodeList lastList = null; + + public NodeList getLastList() { + return lastList; + } + + protected void xpathRecomputed(NodeList nodeList) { + this.lastList = nodeList; + } + + @Override + public IWorkbenchPartSite getSite() { + return new IWorkbenchPartSite() { + + public boolean hasService(Class api) { return IWorkbenchSiteProgressService.class.equals(api);} + + public Object getService(Class api) { + if (IWorkbenchSiteProgressService.class.equals(api)) { + return new IWorkbenchSiteProgressService() { + + public int getLongOperationTime() { return 0; } + + public void registerIconForFamily( + ImageDescriptor icon, Object family) { } + + public void runInUI(IRunnableContext context, + IRunnableWithProgress runnable, + ISchedulingRule rule) + throws InvocationTargetException, + InterruptedException { runnable.run(new NullProgressMonitor()); } + + public Image getIconFor(Job job) { return null; } + + public void busyCursorWhile( + IRunnableWithProgress runnable) + throws InvocationTargetException, + InterruptedException { } + + public void run(boolean fork, boolean cancelable, + IRunnableWithProgress runnable) + throws InvocationTargetException, + InterruptedException { runnable.run(new NullProgressMonitor()); } + + public void showInDialog(Shell shell, Job job) { } + + public void schedule(Job job, long delay, + boolean useHalfBusyCursor) { + this.schedule(job, delay); + } + + public void schedule(Job job, long delay) { + job.schedule(delay); + try { + job.join(); + } catch (InterruptedException e) { + } + } + + public void schedule(Job job) { job.schedule(); } + + public void showBusyForFamily(Object family) { } + + public void warnOfContentChange() { } + + public void incrementBusy() { } + + public void decrementBusy() { } + + }; + } else return null; + } + + public Object getAdapter(Class adapter) { return null; } + public void setSelectionProvider(ISelectionProvider provider) { } + public IWorkbenchWindow getWorkbenchWindow() { return null; } + public Shell getShell() { return null; } + public ISelectionProvider getSelectionProvider() { return null; } + public IWorkbenchPage getPage() { return null; } + public void registerContextMenu(String menuId, MenuManager menuManager, + ISelectionProvider selectionProvider) { } + public void registerContextMenu(MenuManager menuManager, + ISelectionProvider selectionProvider) { } + public String getRegisteredName() { return null; } + public String getPluginId() { return null; } + public IWorkbenchPart getPart() { return null; } + @SuppressWarnings("deprecation") + public IKeyBindingService getKeyBindingService() { return null; } + public String getId() { return null; } + }; + } + } + + Preferences prefs = null; + StubXPathProcessorHandler handler = null; + + @Override + protected void setUp() throws Exception { + super.setUp(); + prefs = XPathCoreHelper.getPreferences(); + prefs.putBoolean(XPathProcessorPreferences.XPATH_1_0_PROCESSOR, false); + prefs.putBoolean(XPathProcessorPreferences.XPATH_2_0_PROCESSOR, false); + prefs.flush(); + handler = new StubXPathProcessorHandler(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + prefs = null; + handler = null; + } + + + public Document createSimpleDocument() throws Exception { + IDOMModel domImpl = new DOMModelImpl(); + domImpl.setId("dummy"); + Document document = domImpl.getDocument(); + document.appendChild(document.createElement("test")); + + Element rootelem = document.getDocumentElement(); + Element elem1 = document.createElement("testNode1"); + Element elem2 = document.createElement("testNode1"); + rootelem.appendChild(elem1); + rootelem.appendChild(elem2); + + return document; + } + + public void testComputeNodeXpath10() throws Exception { + handler.toggleState("xpath10"); + + NodeList nl = computeXPathInView("string(count(//*)) < '04'", createSimpleDocument()); + assertEquals(1, nl.getLength()); + assertEquals("true", ((Text)nl.item(0)).getTextContent()); + } + + public void testComputeNodeXpath2() throws Exception { + handler.toggleState("xpath2"); + + NodeList nl = computeXPathInView("'2' > '04'", createSimpleDocument()); + assertEquals(1, nl.getLength()); + assertEquals("true", ((Text)nl.item(0)).getTextContent()); + } + + private NodeList computeXPathInView(String xpathExpression, Node node) throws Exception, XPathExpressionException { + MockXPathView myMockView = new MockXPathView(); + XPathComputer pathComputer = new XPathComputer(myMockView); + pathComputer.setSelectedNode(node); + pathComputer.setText(xpathExpression); + pathComputer.compute(); + NodeList nl = myMockView.getLastList(); + return nl; + } + + public void testToggleStateXpath2() throws Exception { + handler.toggleState("xpath2"); + + } +}