Author: sdzmitrovich
Date: 2008-09-18 04:48:34 -0400 (Thu, 18 Sep 2008)
New Revision: 10349
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/commandButton.xml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/commandLink.xml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/dataTable.xml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/form.xml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/inputText.xml
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfComponentContentTest.java
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
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestUtil.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2781
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/commandButton.xml
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/commandButton.xml
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/commandButton.xml 2008-09-18
08:48:34 UTC (rev 10349)
@@ -0,0 +1,17 @@
+<tests
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <test id="commandButton1">
+ <input type="submit" />
+ </test>
+ <test id="commandButton2">
+ <input type="button" />
+ </test>
+ <test id="commandButton3">
+ <input type="reset" />
+ </test>
+ <test id="commandButton4">
+ <input type="submit" />
+ </test>
+ <test id="commandButton5">
+ <input type="image" />
+ </test>
+</tests>
\ No newline at end of file
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/commandLink.xml
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/commandLink.xml
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/commandLink.xml 2008-09-18
08:48:34 UTC (rev 10349)
@@ -0,0 +1,8 @@
+<tests
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <test id="commandLink1">
+ <span>commandLink1</span>
+ </test>
+ <test id="commandLink2">
+ <a>commandLink2</a>
+ </test>
+</tests>
\ No newline at end of file
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/dataTable.xml
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/dataTable.xml
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/dataTable.xml 2008-09-18
08:48:34 UTC (rev 10349)
@@ -0,0 +1,81 @@
+<tests
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <test id="1">
+ <TABLE>
+ <TR>
+ <TD>
+ <DIV>
+ <TABLE>
+ <CAPTION>
+ <BR />
+ </CAPTION>
+ <THEAD>
+ <TR>
+ <TH>
+ <BR />
+ </TH>
+ </TR>
+ </THEAD>
+ <TFOOT>
+ <TR>
+ <TD>
+ <BR />
+ </TD>
+ </TR>
+ </TFOOT>
+ <TBODY>
+ <TR>
+ <TD>
+ <TABLE WIDTH="100%" BORDER="0">
+ <THEAD>
+ <TR>
+ <TH>
+ <DIV>
+ <SPAN> Last Name </SPAN>
+ </DIV>
+ </TH>
+ <TH>
+ <DIV>
+ <SPAN> First Name </SPAN>
+ </DIV>
+ </TH>
+ </TR>
+ </THEAD>
+ <TFOOT>
+ <TR>
+ <TD>
+ <DIV>
+ <SPAN> footer </SPAN>
+ </DIV>
+ </TD>
+ <TD>
+ <DIV>
+ <SPAN> footer </SPAN>
+ </DIV>
+ </TD>
+ </TR>
+ </TFOOT>
+ <TBODY>
+ <TR>
+ <TD>
+ <SPAN> Dupont </SPAN>
+ </TD>
+ <TD>
+ <SPAN> William </SPAN>
+ </TD>
+ </TR>
+ </TBODY>
+ <COLGROUP>
+ <COL />
+ <COL />
+ </COLGROUP>
+ </TABLE>
+ </TD>
+ </TR>
+ </TBODY>
+ </TABLE>
+ </DIV>
+ </TD>
+ </TR>
+ </TABLE>
+ </test>
+</tests>
\ No newline at end of file
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/form.xml
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/form.xml
(rev 0)
+++ trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/form.xml 2008-09-18
08:48:34 UTC (rev 10349)
@@ -0,0 +1,14 @@
+<tests
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <test id="form">
+ <TABLE
+ STYLE="border: 1px dotted rgb(255, 102, 0); padding: 5px; width: 100%;">
+ <TR>
+ <TD>
+ <DIV>
+ </DIV>
+ <BR />
+ </TD>
+ </TR>
+ </TABLE>
+ </test>
+</tests>
\ No newline at end of file
Added: trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/inputText.xml
===================================================================
--- trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/inputText.xml
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/resources/tests/inputText.xml 2008-09-18
08:48:34 UTC (rev 10349)
@@ -0,0 +1,5 @@
+<tests
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <test id="inputText">
+ <input />
+ </test>
+</tests>
\ No newline at end of file
Added:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfComponentContentTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfComponentContentTest.java
(rev 0)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfComponentContentTest.java 2008-09-18
08:48:34 UTC (rev 10349)
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * 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.jsf.vpe.jsf.test;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.tools.vpe.ui.test.ComponentContentTest;
+
+/**
+ * Class for testing all jsf components
+ *
+ * @author sdzmitrovich
+ *
+ */
+public class JsfComponentContentTest extends ComponentContentTest {
+
+ // import project name
+ public static final String IMPORT_PROJECT_NAME = "jsfTest"; //$NON-NLS-1$
+
+ public static final String TESTS_ROOT_NAME = "tests"; //$NON-NLS-1$
+
+ public JsfComponentContentTest(String name) {
+ super(name);
+ setCheckWarning(false);
+ }
+
+ public void testCommandButton() throws Throwable {
+
+ Map<String, String> mapIds = new HashMap<String, String>();
+ mapIds.put("commandButton1", "commandButton1");
+ mapIds.put("commandButton2", "commandButton2");
+ mapIds.put("commandButton3", "commandButton3");
+ mapIds.put("commandButton4", "commandButton4");
+ mapIds.put("commandButton5", "commandButton5");
+ performContentTest("components/commandButton.jsp", //$NON-NLS-1$
+ "commandButton.xml", mapIds); //$NON-NLS-1$
+ }
+
+ public void testCommandLink() throws Throwable {
+ Map<String, String> mapIds = new HashMap<String, String>();
+ mapIds.put("commandLink1", "commandLink1");
+ mapIds.put("commandLink2", "commandLink2");
+ performContentTest("components/commandLink.jsp", //$NON-NLS-1$
+ "commandLink.xml", mapIds); //$NON-NLS-1$
+ }
+
+ public void testDataTable() throws Throwable {
+ performContentTest("components/dataTable.jsp", "dataTable",
"dataTable.xml");
+ }
+
+ public void testForm() throws Throwable {
+ performContentTest("components/form.jsp", "form",
"form.xml");
+ }
+
+ public void _testGraphicImage() throws Throwable {
+ // -1$
+ }
+
+ public void _testInputHidden() throws Throwable {
+ }
+
+ public void _testInputSecret() throws Throwable {
+ }
+
+ public void testInputText() throws Throwable {
+
+ performContentTest("components/inputText.jsp", "inputText",
//$NON-NLS-1$ //$NON-NLS-2$
+ "inputText.xml"); //$NON-NLS-1$
+
+ }
+
+ public void _testInputTextArea() throws Throwable {
+ }
+
+ public void _testMessage() throws Throwable {
+ }
+
+ public void _testMessages() throws Throwable {
+ }
+
+ public void _testOutputFormat() throws Throwable {
+ }
+
+ public void _testOutputLabel() throws Throwable {
+ }
+
+ public void _testOutputLink() throws Throwable {
+ }
+
+ public void _testOutputText() throws Throwable {
+ }
+
+ public void _testPanelGrid() throws Throwable {
+ }
+
+ public void _testPanelGroup() throws Throwable {
+ }
+
+ public void _testSelectBooleanCheckbox() throws Throwable {
+ }
+
+ public void _testSelectManyCheckbox() throws Throwable {
+ }
+
+ public void _testSelectManyListbox() throws Throwable {
+ }
+
+ public void _testSelectManyMenu() throws Throwable {
+ }
+
+ public void _testSelectOneListbox() throws Throwable {
+ }
+
+ public void _testSelectOneMenu() throws Throwable {
+ }
+
+ public void _testSelectOneRadio() throws Throwable {
+ }
+
+ /*
+ * JSF Core test cases
+ */
+
+ public void _testActionListener() throws Throwable {
+ }
+
+ public void _testAttribute() throws Throwable {
+ }
+
+ public void _testConvertDateTime() throws Throwable {
+ }
+
+ public void _testConvertNumber() throws Throwable {
+ }
+
+ public void _testConverter() throws Throwable {
+ }
+
+ public void _testFacet() throws Throwable {
+ }
+
+ public void _testLoadBundle() throws Throwable {
+ }
+
+ public void _testParam() throws Throwable {
+ }
+
+ public void _testPhaseListener() throws Throwable {
+ }
+
+ public void _testSelectItem() throws Throwable {
+ }
+
+ public void _testSelectItems() throws Throwable {
+ }
+
+ public void _testSetPropertyActionListener() throws Throwable {
+ }
+
+ public void _testSubview() throws Throwable {
+ }
+
+ public void _testValidateDoubleRange() throws Throwable {
+ }
+
+ public void _testValidateLength() throws Throwable {
+ }
+
+ public void _testValidateLongRange() throws Throwable {
+ }
+
+ public void _testValidator() throws Throwable {
+ }
+
+ public void _testValueChangeListener() throws Throwable {
+ }
+
+ public void _testVerbatim() throws Throwable {
+ }
+
+ public void _testView() throws Throwable {
+ }
+
+ protected String getTestProjectName() {
+ return IMPORT_PROJECT_NAME;
+ }
+
+ @Override
+ protected String getTestsRoot() {
+ return JsfTestPlugin.getPluginResourcePath() + File.separator
+ + TESTS_ROOT_NAME;
+ }
+}
Added:
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
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java 2008-09-18
08:48:34 UTC (rev 10349)
@@ -0,0 +1,315 @@
+/*******************************************************************************
+ * 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 java.io.File;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.part.FileEditorInput;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public abstract class ComponentContentTest extends VpeTest {
+
+ public ComponentContentTest(String name) {
+ super(name);
+ }
+
+ /**
+ *
+ * @param elementPagePath
+ * - path to test page
+ * @param elementId
+ * - id of element which will be tested
+ * @param XmlSchemeContent
+ * - probable content of test element
+ *
+ * @throws Throwable
+ */
+ protected void performContentTestByContent(String elementPagePath,
+ String elementId, String xmlTestContent) throws Throwable {
+ setException(null);
+
+ IFile elementPageFile = (IFile) TestUtil.getComponentPath(
+ elementPagePath, getTestProjectName());
+
+ IEditorInput input = new FileEditorInput(elementPageFile);
+
+ TestUtil.waitForJobs();
+
+ IEditorPart editor = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().openEditor(input,
+ EDITOR_ID, true);
+
+ assertNotNull(editor);
+
+ TestUtil.waitForJobs();
+
+ // get element by id
+ nsIDOMElement vpeElement = findElementById(
+ getVpeController((JSPMultiPageEditor) editor), elementId);
+ assertNotNull(vpeElement);
+
+ // get document
+ Document modelDocument = TestDomUtil.getDocument(xmlTestContent);
+ assertNotNull(modelDocument);
+
+ // get element
+ Element modelElement = modelDocument.getDocumentElement();
+ assertNotNull(modelElement);
+
+ assertEquals(true, TestDomUtil.compareNodes(vpeElement, modelElement));
+
+ if (getException() != null) {
+ throw getException();
+ }
+
+ }
+
+ /**
+ * use if xml file contain only one test
+ *
+ * @param elementPagePath
+ * - path to test page
+ * @param elementId
+ * - id of element which will be tested
+ * @param xmlTestPath
+ * - path to xml file which contains tests of content
+ * @param xmlTestId
+ * - current id of test in xml file
+ * @throws Throwable
+ */
+ protected void performContentTest(String elementPagePath, String elementId,
+ String xmlTestPath) throws Throwable {
+ setException(null);
+
+ IFile elementPageFile = (IFile) TestUtil.getComponentPath(
+ elementPagePath, getTestProjectName());
+
+ IEditorInput input = new FileEditorInput(elementPageFile);
+
+ TestUtil.waitForJobs();
+
+ IEditorPart editor = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().openEditor(input,
+ EDITOR_ID, true);
+
+ assertNotNull(editor);
+
+ TestUtil.waitForJobs();
+
+ // get xml test file
+ File xmlTestFile = TestUtil.getXmlTestFile(xmlTestPath, getTestsRoot());
+
+ // get document
+ Document xmlTestDocument = TestDomUtil.getDocument(xmlTestFile);
+ assertNotNull(xmlTestDocument);
+
+ // compare DOMs
+ assertEquals(true, compareElements(
+ getVpeController((JSPMultiPageEditor) editor), xmlTestDocument,
+ elementId));
+
+ if (getException() != null) {
+ throw getException();
+ }
+
+ }
+
+ /**
+ *
+ * use if xml file contain several tests
+ *
+ * @param elementPagePath
+ * - path to test page
+ * @param elementId
+ * - id of element which will be tested
+ * @param xmlTestPath
+ * - path to xml file which contains tests of content
+ * @param xmlTestId
+ * - current id of test in xml file
+ * @throws Throwable
+ */
+ protected void performContentTest(String elementPagePath, String elementId,
+ String xmlTestPath, String xmlTestId) throws Throwable {
+ setException(null);
+
+ IFile elementPageFile = (IFile) TestUtil.getComponentPath(
+ elementPagePath, getTestProjectName());
+
+ IEditorInput input = new FileEditorInput(elementPageFile);
+
+ TestUtil.waitForJobs();
+
+ IEditorPart editor = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().openEditor(input,
+ EDITOR_ID, true);
+
+ assertNotNull(editor);
+
+ TestUtil.waitForJobs();
+
+ VpeController controller = getVpeController((JSPMultiPageEditor) editor);
+
+ // get xml test file
+ File xmlTestFile = TestUtil.getXmlTestFile(xmlTestPath, getTestsRoot());
+
+ // get document
+ Document xmlTestDocument = TestDomUtil.getDocument(xmlTestFile);
+ assertNotNull(xmlTestDocument);
+
+ assertEquals(true, compareElements(controller, xmlTestDocument,
+ elementId, xmlTestId));
+
+ if (getException() != null) {
+ throw getException();
+ }
+
+ }
+
+ /**
+ * use if it is necessary to check several elements at the same time
+ *
+ * @param elementPagePath
+ * - path to test page
+ * @param xmlTestPath
+ * - path to xml file which contains tests of content
+ * @param mapId
+ * - key is id of element which will be tested, value is
+ * corresponding id of test in xml file
+ * @throws Throwable
+ */
+ protected void performContentTest(String elementPagePath,
+ String xmlTestPath, Map<String, String> mapId) throws Throwable {
+ setException(null);
+
+ IFile elementPageFile = (IFile) TestUtil.getComponentPath(
+ elementPagePath, getTestProjectName());
+
+ IEditorInput input = new FileEditorInput(elementPageFile);
+
+ TestUtil.waitForJobs();
+
+ IEditorPart editor = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow().getActivePage().openEditor(input,
+ EDITOR_ID, true);
+
+ assertNotNull(editor);
+
+ TestUtil.waitForJobs();
+
+ VpeController controller = getVpeController((JSPMultiPageEditor) editor);
+
+ // get xml test file
+ File xmlTestFile = TestUtil.getXmlTestFile(xmlTestPath, getTestsRoot());
+
+ // get document
+ Document xmlTestDocument = TestDomUtil.getDocument(xmlTestFile);
+ assertNotNull(xmlTestDocument);
+
+ for (String elementId : mapId.keySet()) {
+
+ assertEquals(true, compareElements(controller, xmlTestDocument,
+ elementId, mapId.get(elementId)));
+ }
+
+ if (getException() != null) {
+ throw getException();
+ }
+
+ }
+
+ protected boolean compareElements(VpeController controller,
+ Document xmlTestDocument, String elementId, String xmlTestId) {
+
+ // get element by id
+ nsIDOMElement vpeElement = findElementById(controller, elementId);
+ assertNotNull(vpeElement);
+
+ // get test element by id - get <test id="..." > element and get his
+ // first child
+ Element xmlModelElement = TestDomUtil.getFirstChildElement(TestDomUtil
+ .getElemenById(xmlTestDocument, xmlTestId));
+
+ assertNotNull(xmlModelElement);
+
+ // compare DOMs
+ return TestDomUtil.compareNodes(vpeElement, xmlModelElement);
+
+ }
+
+ protected boolean compareElements(VpeController controller,
+ Document xmlTestDocument, String elementId) {
+
+ // get element by id
+ nsIDOMElement vpeElement = findElementById(controller, elementId);
+ assertNotNull(vpeElement);
+
+ // get test element, get the first <test> tag in file
+ Element xmlTestElement = TestDomUtil
+ .getFirstChildElement(xmlTestDocument.getDocumentElement());
+ assertNotNull(xmlTestElement);
+
+ // model element is the first child of <test> tag
+ Element xmlModelElement = TestDomUtil
+ .getFirstChildElement(xmlTestElement);
+
+ assertNotNull(xmlModelElement);
+
+ // compare DOMs
+ return TestDomUtil.compareNodes(vpeElement, xmlModelElement);
+
+ }
+
+ /**
+ * find visual element by "id" entered in source part of vpe
+ *
+ * @param controller
+ * @param elementId
+ * @return
+ */
+ protected nsIDOMElement findElementById(VpeController controller,
+ String elementId) {
+
+ Element sourceElement = getSourceDocument(controller).getElementById(
+ elementId);
+
+ VpeElementMapping elementMapping = controller.getDomMapping()
+ .getNearElementMapping(sourceElement);
+
+ return elementMapping.getVisualElement();
+ }
+
+ /**
+ *
+ * @return
+ */
+ abstract protected String getTestProjectName();
+
+ /**
+ *
+ * @return
+ */
+ abstract protected String getTestsRoot();
+
+}
Added:
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
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java 2008-09-18
08:48:34 UTC (rev 10349)
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * 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 java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.StringReader;
+
+import org.jboss.tools.common.model.util.XMLUtil;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.mozilla.interfaces.nsIDOMNodeList;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public class TestDomUtil {
+
+ public static String ID_ATTRIBUTE = "id";
+
+ public static Document getDocument(File file) throws FileNotFoundException {
+ // create reader
+ FileReader reader = new FileReader(file);
+
+ // return document
+ return XMLUtil.getDocument(reader);
+ }
+
+ public static Document getDocument(String content)
+ throws FileNotFoundException {
+ // create reader
+ StringReader reader = new StringReader(content);
+
+ // return document
+ return XMLUtil.getDocument(reader);
+ }
+
+ /**
+ *
+ * @param document
+ * @param elementId
+ * @return
+ */
+ public static Element getElemenById(Document document, String elementId) {
+
+ Element element = document.getDocumentElement();
+
+ NodeList children = element.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if ((child.getNodeType() == Node.ELEMENT_NODE)
+ && elementId.equals(((Element) child)
+ .getAttribute(ID_ATTRIBUTE)))
+ return (Element) child;
+
+ }
+
+ return null;
+
+ }
+
+ /**
+ *
+ * @param element
+ * @return
+ */
+ public static Element getFirstChildElement(Element element) {
+
+ if (element != null) {
+ NodeList children = element.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+
+ if (child.getNodeType() == Node.ELEMENT_NODE)
+ return (Element) child;
+
+ }
+ }
+ return null;
+
+ }
+
+ /**
+ *
+ * @param vpeNode
+ * @param schemeNode
+ * @return
+ */
+ public static boolean compareNodes(nsIDOMNode vpeNode, Node schemeNode) {
+
+ // compare node's features
+ if ((schemeNode.getNodeType() != vpeNode.getNodeType())
+ || (!schemeNode.getNodeName().equalsIgnoreCase(
+ vpeNode.getNodeName()))
+ || ((schemeNode.getNodeValue() != null) && (!schemeNode
+ .getNodeValue().trim()
+ .equalsIgnoreCase(vpeNode.getNodeValue().trim()))))
+ return false;
+
+ // compare node's attributes
+ if (schemeNode.getNodeType() == Node.ELEMENT_NODE) {
+
+ NamedNodeMap attributes = schemeNode.getAttributes();
+ nsIDOMElement vpeElement = (nsIDOMElement) vpeNode
+ .queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ if (attributes != null) {
+ for (int i = 0; i < attributes.getLength(); i++) {
+ Attr attr = (Attr) attributes.item(i);
+ if ((!vpeElement.hasAttribute(attr.getName()))
+ || (!attr.getNodeValue().equals(
+ vpeElement.getAttributeNode(attr.getName())
+ .getNodeValue())))
+ return false;
+ }
+ }
+ }
+
+ // compare children
+ nsIDOMNodeList vpeChildren = vpeNode.getChildNodes();
+ NodeList schemeChildren = schemeNode.getChildNodes();
+ int realCount = 0;
+ for (int i = 0; i < schemeChildren.getLength(); i++) {
+
+ Node schemeChild = schemeChildren.item(i);
+
+ // leave out empty text nodes in test dom model
+ if ((schemeChild.getNodeType() == Node.TEXT_NODE)
+ && ((schemeChild.getNodeValue() == null) || (schemeChild
+ .getNodeValue().trim().length() == 0)))
+ continue;
+
+ nsIDOMNode vpeChild = vpeChildren.item(realCount++);
+
+ // leave out empty text nodes in vpe dom model
+ while (((vpeChild.getNodeType() == Node.TEXT_NODE) && ((vpeChild
+ .getNodeValue() == null) || (vpeChild.getNodeValue().trim()
+ .length() == 0)))) {
+ vpeChild = vpeChildren.item(realCount++);
+
+ }
+
+ if (!compareNodes(vpeChild, schemeChild))
+ return false;
+
+ }
+
+ return true;
+
+ }
+}
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestUtil.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestUtil.java 2008-09-18
07:50:01 UTC (rev 10348)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestUtil.java 2008-09-18
08:48:34 UTC (rev 10349)
@@ -154,6 +154,16 @@
return null;
}
+
+
+ /**
+ * @param xmlScheme
+ * @param xmlSchemesRoot
+ * @return
+ */
+ public static File getXmlTestFile(String xmlTestPath, String xmlTestsRoot) {
+ return new File(xmlTestsRoot + File.separator + xmlTestPath);
+ }
/**
* Removes the project.