[jbosstools-commits] JBoss Tools SVN: r23064 - in trunk/vpe/tests/org.jboss.tools.vpe.ui.test: src/org/jboss/tools/vpe/ui/test and 1 other directory.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Mon Jun 28 12:44:09 EDT 2010
Author: yradtsevich
Date: 2010-06-28 12:44:09 -0400 (Mon, 28 Jun 2010)
New Revision: 23064
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/DOMComparisonException.java
Removed:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComparisonException.java
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/META-INF/MANIFEST.MF
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java
Log:
https://jira.jboss.org/browse/JBIDE-6543
- file name and XPath of the node where a VPE content test failed is printed now
Modified: trunk/vpe/tests/org.jboss.tools.vpe.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.test/META-INF/MANIFEST.MF 2010-06-28 14:47:10 UTC (rev 23063)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.test/META-INF/MANIFEST.MF 2010-06-28 16:44:09 UTC (rev 23064)
@@ -18,7 +18,8 @@
org.jboss.tools.common.model.ui;bundle-version="3.1.0",
org.jboss.tools.tests;bundle-version="3.1.0";visibility:=reexport,
org.jboss.tools.vpe.resref;bundle-version="3.1.0",
- javax.servlet;bundle-version="2.5.0"
+ javax.servlet;bundle-version="2.5.0",
+ org.eclipse.wst.xml.xpath.core
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .,
lib/jmock-2.5.1/jmock-2.5.1.jar,
Deleted: trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComparisonException.java
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComparisonException.java 2010-06-28 14:47:10 UTC (rev 23063)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComparisonException.java 2010-06-28 16:44:09 UTC (rev 23064)
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.ui.test;
-
-/**
- * @author Sergey Dzmitrovich
- *
- */
-public class ComparisonException extends Exception {
-
- /**
- *
- */
- private static final long serialVersionUID = 7127064462771778364L;
-
- public ComparisonException() {
- super();
- }
-
- public ComparisonException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public ComparisonException(String message) {
- super(message);
- }
-
- public ComparisonException(Throwable cause) {
- super(cause);
- }
-
-}
Modified: trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java 2010-06-28 14:47:10 UTC (rev 23063)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java 2010-06-28 16:44:09 UTC (rev 23064)
@@ -11,6 +11,7 @@
package org.jboss.tools.vpe.ui.test;
import java.io.File;
+import java.io.FileNotFoundException;
import java.util.List;
import org.eclipse.core.resources.IFile;
@@ -18,6 +19,7 @@
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.xml.xpath.core.util.XSLTXPathHelper;
import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
import org.jboss.tools.test.util.WorkbenchUtils;
import org.jboss.tools.vpe.editor.VpeController;
@@ -81,20 +83,31 @@
.getLocation().toFile();
// get document
+ compareContent(controller, xmlTestFile);
+
+ if (getException() != null) {
+ throw getException();
+ }
+
+ }
+
+ protected void compareContent(VpeController controller, File xmlTestFile)
+ throws FileNotFoundException {
Document xmlTestDocument = TestDomUtil.getDocument(xmlTestFile);
assertNotNull("Can't get test file, possibly file not exists "+xmlTestFile,xmlTestDocument); //$NON-NLS-1$
List<String> ids = TestDomUtil.getTestIds(xmlTestDocument);
for (String id : ids) {
-
- compareElements(controller, xmlTestDocument, id, id);
+ try{
+ compareElements(controller, xmlTestDocument, id, id);
+ } catch (DOMComparisonException e) {
+ String xPathToNode = XSLTXPathHelper.calculateXPathToNode(e.getNode());
+ String testFileName = xmlTestFile.getPath();
+ String message = e.getMessage();
+ fail(String.format("%s[%s]:\n%s", testFileName, xPathToNode, message)); //$NON-NLS-1$
+ }
}
-
- if (getException() != null) {
- throw getException();
- }
-
}
/**
@@ -104,12 +117,11 @@
* @param elementId
* @param xmlTestId
* @return
- * @throws ComparisonException
+ * @throws DOMComparisonException
*/
- protected void compareElements(VpeController controller,
+ private void compareElements(VpeController controller,
Document xmlTestDocument, String elementId, String xmlTestId)
- throws ComparisonException {
-
+ throws DOMComparisonException {
// get element by id
nsIDOMElement vpeElement = findElementById(controller, elementId);
assertNotNull("Cann't find element with id="+elementId,vpeElement); //$NON-NLS-1$
@@ -125,13 +137,7 @@
assertNotNull(xmlModelElement);
- // compare DOMs
- try {
- TestDomUtil.compareNodes(vpeElement, xmlModelElement);
- } catch (ComparisonException e) {
- fail(e.getMessage());
- }
-
+ TestDomUtil.compareNodes(vpeElement, xmlModelElement);
}
/**
Copied: trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/DOMComparisonException.java (from rev 23060, trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComparisonException.java)
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/DOMComparisonException.java (rev 0)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/DOMComparisonException.java 2010-06-28 16:44:09 UTC (rev 23064)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.vpe.ui.test;
+
+import org.w3c.dom.Node;
+
+/**
+ * @author Sergey Dzmitrovich
+ * @author Yahor Radtsevich (yradtsevich)
+ *
+ */
+public class DOMComparisonException extends Exception {
+ private static final long serialVersionUID = 7127064462771778364L;
+ private Node node;
+
+ public DOMComparisonException(String message, Node node) {
+ super(message);
+ this.node = node;
+ }
+
+ public Node getNode() {
+ return node;
+ }
+}
Modified: trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java
===================================================================
--- trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java 2010-06-28 14:47:10 UTC (rev 23063)
+++ trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java 2010-06-28 16:44:09 UTC (rev 23064)
@@ -18,7 +18,6 @@
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -28,13 +27,9 @@
import org.jboss.tools.common.model.util.XMLUtil;
import org.jboss.tools.jst.css.common.CSSStyleManager;
-import org.jboss.tools.jst.css.common.StyleContainer;
import org.jboss.tools.vpe.editor.util.Constants;
import org.jboss.tools.vpe.editor.util.HTML;
-import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.mozilla.interfaces.nsIDOMAttr;
-import org.mozilla.interfaces.nsIDOMCSSStyleDeclaration;
-import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNamedNodeMap;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
@@ -44,8 +39,6 @@
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.ElementCSSInlineStyle;
/**
* @author Sergey Dzmitrovich
@@ -138,23 +131,23 @@
* @param vpeNode
* @param schemeNode
* @return
- * @throws ComparisonException
+ * @throws DOMComparisonException
*/
public static void compareNodes(nsIDOMNode vpeNode, Node modelNode)
- throws ComparisonException {
+ throws DOMComparisonException {
if (!modelNode.getNodeName().equalsIgnoreCase(vpeNode.getNodeName())) {
- throw new ComparisonException("name of tag is \"" //$NON-NLS-1$
+ throw new DOMComparisonException("name of tag is \"" //$NON-NLS-1$
+ vpeNode.getNodeName() + "\"but must be \"" //$NON-NLS-1$
- + modelNode.getNodeName() + "\""); //$NON-NLS-1$
+ + modelNode.getNodeName() + "\"", modelNode); //$NON-NLS-1$
}
if ((modelNode.getNodeValue() != null)
&& (!modelNode.getNodeValue().trim().equalsIgnoreCase(
vpeNode.getNodeValue().trim()))) {
- throw new ComparisonException("value of " + vpeNode.getNodeName() //$NON-NLS-1$
+ throw new DOMComparisonException("value of " + vpeNode.getNodeName() //$NON-NLS-1$
+ " is \"" + vpeNode.getNodeValue().trim() //$NON-NLS-1$
+ "\" but must be \"" + modelNode.getNodeValue().trim() //$NON-NLS-1$
- + "\""); //$NON-NLS-1$
+ + "\"", modelNode); //$NON-NLS-1$
}
// compare node's attributes
@@ -180,10 +173,11 @@
nsIDOMNode vpeChild = vpeChildren.item(realCount++);
if (null == vpeChild) {
- throw new ComparisonException(
+ throw new DOMComparisonException(
"Child of node \"" //$NON-NLS-1$
+ vpeNode.getNodeName()
- + "\" is \"null\", but should be \"" + schemeChild.getNodeName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+ + "\" is \"null\", but should be \"" + schemeChild.getNodeName() + "\"",//$NON-NLS-1$ //$NON-NLS-2$
+ schemeChild);
}
// leave out empty text nodes in vpe dom model
@@ -192,10 +186,11 @@
.length() == 0)))) {
vpeChild = vpeChildren.item(realCount++);
if (null == vpeChild) {
- throw new ComparisonException(
+ throw new DOMComparisonException(
"Child of node \"" //$NON-NLS-1$
+ vpeNode.getNodeName()
- + "\" is \"null\", but should be \"" + schemeChild.getNodeName() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+ + "\" is \"null\", but should be \"" + schemeChild.getNodeName() + "\"",//$NON-NLS-1$ //$NON-NLS-2$
+ schemeChild);
}
}
@@ -225,7 +220,7 @@
}
private static void compareAttributes(NamedNodeMap modelAttributes,
- nsIDOMNamedNodeMap vpeAttributes) throws ComparisonException {
+ nsIDOMNamedNodeMap vpeAttributes) throws DOMComparisonException {
for (int i = 0; i < modelAttributes.getLength(); i++) {
Attr modelAttr = (Attr) modelAttributes.item(i);
@@ -241,13 +236,13 @@
ILLEGAL_ATTRIBUTES_SEPARATOR);
for (String illegalAttributeName : illegalAttributes) {
if (vpeAttributes.getNamedItem(illegalAttributeName.trim()) != null)
- throw new ComparisonException("illegal attribute :" //$NON-NLS-1$
- + illegalAttributeName);
+ throw new DOMComparisonException("illegal attribute :" //$NON-NLS-1$
+ + illegalAttributeName, modelAttr);
}
} else {
if (vpeAttributes.getNamedItem(name) == null) {
- throw new ComparisonException("there is not : \"" + name //$NON-NLS-1$
- + "\" attribute"); //$NON-NLS-1$
+ throw new DOMComparisonException("there is not : \"" + name //$NON-NLS-1$
+ + "\" attribute", modelAttr); //$NON-NLS-1$
}
nsIDOMAttr vpeAttr = queryInterface(
vpeAttributes.getNamedItem(name), nsIDOMAttr.class);
@@ -280,33 +275,35 @@
* in the style attribute of the vpe element.
*/
if (xmlStyle.size() > vpeStyle.size()) {
- throw new ComparisonException(
+ throw new DOMComparisonException(
"VPE element has less style parameters [" //$NON-NLS-1$
+ vpeStyle.size()
+ "] than was specified [" //$NON-NLS-1$
+ xmlStyle.size() + "]." //$NON-NLS-1$
+ "\n Expected: " + xmlStyle //$NON-NLS-1$
- + "\n Was: " + vpeStyle); //$NON-NLS-1$
+ + "\n Was: " + vpeStyle, //$NON-NLS-1$
+ modelAttr);
} else {
if ((xmlStyle.size() > 0) && (vpeStyle.size() > 0)) {
for (String key : xmlStyle.keySet()) {
if (vpeStyle.containsKey(key)) {
if (!xmlStyle.get(key).equalsIgnoreCase(
vpeStyle.get(key))) {
- throw new ComparisonException(
+ throw new DOMComparisonException(
"Style value for parameter [" //$NON-NLS-1$
+ key
+ "] is different. Expected [" //$NON-NLS-1$
+ xmlStyle.get(key)
+ "] but was [" //$NON-NLS-1$
+ vpeStyle.get(key)
- + "]"); //$NON-NLS-1$
+ + "]", modelAttr); //$NON-NLS-1$
}
} else {
- throw new ComparisonException(
+ throw new DOMComparisonException(
"Style parameter [" //$NON-NLS-1$
+ key
- + "] is missing in the VPE element"); //$NON-NLS-1$
+ + "] is missing in the VPE element", //$NON-NLS-1$
+ modelAttr);
}
}
}
@@ -314,31 +311,30 @@
}
}
if (performComplexStringsComparison) {
- compareComplexStrings(modelAttr.getNodeValue().trim(),
- vpeAttr.getNodeValue().trim());
+ compareComplexAttributes(modelAttr, vpeAttr);
}
}
}
}
- static private void compareComplexStrings(String modelString,
- String vpeString) throws ComparisonException {
+ static private void compareComplexAttributes(Attr modelAttr, nsIDOMAttr vpeAttr)
+ throws DOMComparisonException {
+ String modelString = modelAttr.getNodeValue().trim();
+ String vpeString = vpeAttr.getNodeValue().trim();
if (modelString.startsWith(START_REGEX)
&& modelString.endsWith(END_REGEX)) {
-
String regex = modelString.substring(START_REGEX.length(),
modelString.length() - END_REGEX.length());
Matcher matcher = Pattern.compile(regex).matcher(vpeString);
if (!matcher.find()) {
- throw new ComparisonException("string is\"" + vpeString //$NON-NLS-1$
- + "\" but pattern is \"" + regex + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new DOMComparisonException("string is\"" + vpeString //$NON-NLS-1$
+ + "\" but pattern is \"" + regex + "\"", modelAttr); //$NON-NLS-1$ //$NON-NLS-2$
}
-
} else if (!modelString.equals(vpeString)) {
- throw new ComparisonException("string is\"" + vpeString //$NON-NLS-1$
- + "\" but must be \"" + modelString + "\""); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new DOMComparisonException("string is\"" + vpeString //$NON-NLS-1$
+ + "\" but must be \"" + modelString + "\"", modelAttr); //$NON-NLS-1$ //$NON-NLS-2$
}
}
@@ -353,15 +349,11 @@
*/
static private boolean findIgnoreCase(String[] strings,
String requiredString) {
-
for (String string : strings) {
-
if (string.equalsIgnoreCase(requiredString))
return true;
-
}
return false;
}
-
}
More information about the jbosstools-commits
mailing list