Author: snjeza
Date: 2008-10-23 18:12:59 -0400 (Thu, 23 Oct 2008)
New Revision: 11129
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/TestUtil.java
Log:
Fixing errors in the org.jboss.tools.jsf.vpe.jsf.test tests
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 2008-10-23
22:06:47 UTC (rev 11128)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java 2008-10-23
22:12:59 UTC (rev 11129)
@@ -1,346 +1,350 @@
-/*******************************************************************************
- * 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.List;
-
-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.VpeDebug;
-import org.jboss.tools.vpe.editor.VpeController;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
-import org.jboss.tools.vpe.xulrunner.browser.util.DOMTreeDumper;
-import org.mozilla.interfaces.nsIDOMElement;
-import org.mozilla.interfaces.nsIDOMNode;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-/**
- * @author Sergey Dzmitrovich
- *
- */
-public abstract class ComponentContentTest extends VpeTest {
-
- public static final String XML_FILE_EXTENSION = ".xml"; //$NON-NLS-1$
-
- public ComponentContentTest(String name) {
- super(name);
- }
-
- /**
- *
- * there are several conditions:
- *
- * 1) xml file which contain tests must be named 'name of test page' +
- * '.xml'
- *
- * Example: test.jsp and test.jsp.xml
- *
- * 2) a tag <test> in xml file and required element in test page must have
- * the same attribute "id"
- *
- * Example: <tests>... <test id="testId" > ...<tests> - in
xml file and
- * <html>... <x:testElement id="testId" > ... </html> - in
test page
- *
- * @param elementPagePath
- * - path to test page
- * @throws Throwable
- */
- protected void performContentTest(String elementPagePath) 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();
-
- TestUtil.delay(2000);
- VpeController controller = getVpeController((JSPMultiPageEditor) editor);
-
- // get xml test file
- File xmlTestFile = TestUtil.getComponentPath(
- elementPagePath + XML_FILE_EXTENSION, getTestProjectName())
- .getLocation().toFile();
-
- // get document
- Document xmlTestDocument = TestDomUtil.getDocument(xmlTestFile);
- assertNotNull(xmlTestDocument);
-
- List<String> ids = TestDomUtil.getTestIds(xmlTestDocument);
-
- for (String id : ids) {
-
- compareElements(controller, xmlTestDocument, id, id);
- }
-
- if (getException() != null) {
- throw getException();
- }
-
- }
-
- /**
- *
- * @param controller
- * @param xmlTestDocument
- * @param elementId
- * @param xmlTestId
- * @return
- * @throws ComparisonException
- */
- protected void compareElements(VpeController controller,
- Document xmlTestDocument, String elementId, String xmlTestId)
- throws ComparisonException {
-
- // get element by id
- nsIDOMElement vpeElement = findElementById(controller, elementId);
- assertNotNull(vpeElement);
-
- DOMTreeDumper dumper = new DOMTreeDumper(
- VpeDebug.VISUAL_DUMP_PRINT_HASH);
- dumper.dumpToStream(System.out, 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
- TestDomUtil.compareNodes(vpeElement, xmlModelElement);
-
- }
-
- /**
- * test for invisible tags
- *
- * @param elementPagePath
- * - path to test page
- * @param elementId
- * - id of element on page
- * @throws Throwable
- */
- protected void performInvisibleTagTest(String elementPagePath,
- String elementId) 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);
-
- // find source element and check if it is not null
- Element sourceELement = findSourceElementById(controller, elementId);
- assertNotNull(sourceELement);
-
- // find visual element and check if it is null
- nsIDOMElement visualElement = findElementById(controller, elementId);
- assertNull(visualElement);
-
- // set show invisible tag's flag to true
- controller.getVisualBuilder().setShowInvisibleTags(true);
- controller.visualRefresh();
-
- TestUtil.waitForIdle();
-
- // find visual element and check if it is not null
- visualElement = findElementById(controller, elementId);
- assertNotNull(visualElement);
-
- // generate text for invisible tag
- String modelInvisibleTagText = generateInvisibleTagText(sourceELement
- .getNodeName());
-
- // generate dom document and get root element
- Element modelElement = TestDomUtil.getDocument(modelInvisibleTagText)
- .getDocumentElement();
- assertNotNull(modelElement);
-
- TestDomUtil.compareNodes(visualElement, modelElement);
-
- if (getException() != null) {
- throw getException();
- }
-
- }
-
- /**
- * test for invisible tags which can have visible children
- *
- * @param elementPagePath
- * - path to test page
- * @param elementId
- * - id of element on page
- * @throws Throwable
- */
- protected void performInvisibleWrapperTagTest(String elementPagePath,
- String elementId) 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);
-
- // find source element and check if it is not null
- Element sourceELement = findSourceElementById(controller, elementId);
- assertNotNull(sourceELement);
-
- // find visual element and check if it is null
- nsIDOMElement visualElement = findElementById(controller, elementId);
- assertNull(visualElement);
-
- // check children of non-visual
- NodeList children = sourceELement.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- Node child = children.item(i);
- assertNotNull(findNode(controller, child));
- }
-
- // set show invisible tag's flag to true
- controller.getVisualBuilder().setShowInvisibleTags(true);
- controller.visualRefresh();
-
- TestUtil.waitForIdle();
-
- // find visual element and check if it is not null
- visualElement = findElementById(controller, elementId);
- assertNotNull(visualElement);
-
- // generate text for invisible tag
- String modelInvisibleTagText = generateInvisibleTagText(sourceELement
- .getNodeName());
-
- // generate dom document and get root element
- Element modelElement = TestDomUtil.getDocument(modelInvisibleTagText)
- .getDocumentElement();
- assertNotNull(modelElement);
-
- // compare elements
- TestDomUtil.compareNodes(visualElement, modelElement);
-
- if (getException() != null) {
- throw getException();
- }
-
- }
-
- /**
- *
- * @param tagName
- * @return
- */
- private String generateInvisibleTagText(String tagName) {
- return "<span style=\"border: 1px dashed GREY; color: GREY; font-size:
12px;\" >" //$NON-NLS-1$
- + tagName + "</span>"; //$NON-NLS-1$
- }
-
- /**
- * 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 = findSourceElementById(controller, elementId);
-
- VpeNodeMapping nodeMapping = controller.getDomMapping().getNodeMapping(
- sourceElement);
-
- if (nodeMapping == null)
- return null;
-
- return (nsIDOMElement) nodeMapping.getVisualNode();
- }
-
- /**
- * find visual element by "id" entered in source part of vpe
- *
- * @param controller
- * @param elementId
- * @return
- */
- protected nsIDOMNode findNode(VpeController controller, Node node) {
-
- VpeNodeMapping nodeMapping = controller.getDomMapping().getNodeMapping(
- node);
-
- if (nodeMapping == null)
- return null;
-
- return nodeMapping.getVisualNode();
- }
-
- /**
- * find source element by "id"
- *
- * @param controller
- * @param elementId
- * @return
- */
- protected Element findSourceElementById(VpeController controller,
- String elementId) {
-
- return getSourceDocument(controller).getElementById(elementId);
- }
-
- /**
- *
- * @return
- */
- abstract protected String getTestProjectName();
-
-}
+/*******************************************************************************
+ * 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.List;
+
+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.VpeDebug;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.xulrunner.browser.util.DOMTreeDumper;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @author Sergey Dzmitrovich
+ *
+ */
+public abstract class ComponentContentTest extends VpeTest {
+
+ public static final String XML_FILE_EXTENSION = ".xml"; //$NON-NLS-1$
+
+ public ComponentContentTest(String name) {
+ super(name);
+ }
+
+ /**
+ *
+ * there are several conditions:
+ *
+ * 1) xml file which contain tests must be named 'name of test page' +
+ * '.xml'
+ *
+ * Example: test.jsp and test.jsp.xml
+ *
+ * 2) a tag <test> in xml file and required element in test page must have
+ * the same attribute "id"
+ *
+ * Example: <tests>... <test id="testId" > ...<tests> - in
xml file and
+ * <html>... <x:testElement id="testId" > ... </html> - in
test page
+ *
+ * @param elementPagePath
+ * - path to test page
+ * @throws Throwable
+ */
+ protected void performContentTest(String elementPagePath) 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();
+
+ TestUtil.delay(2000);
+ VpeController controller = getVpeController((JSPMultiPageEditor) editor);
+
+ // get xml test file
+ File xmlTestFile = TestUtil.getComponentPath(
+ elementPagePath + XML_FILE_EXTENSION, getTestProjectName())
+ .getLocation().toFile();
+
+ // get document
+ Document xmlTestDocument = TestDomUtil.getDocument(xmlTestFile);
+ assertNotNull(xmlTestDocument);
+
+ List<String> ids = TestDomUtil.getTestIds(xmlTestDocument);
+
+ for (String id : ids) {
+
+ compareElements(controller, xmlTestDocument, id, id);
+ }
+
+ if (getException() != null) {
+ throw getException();
+ }
+
+ }
+
+ /**
+ *
+ * @param controller
+ * @param xmlTestDocument
+ * @param elementId
+ * @param xmlTestId
+ * @return
+ * @throws ComparisonException
+ */
+ protected void compareElements(VpeController controller,
+ Document xmlTestDocument, String elementId, String xmlTestId)
+ throws ComparisonException {
+
+ // get element by id
+ nsIDOMElement vpeElement = findElementById(controller, elementId);
+ assertNotNull(vpeElement);
+
+ DOMTreeDumper dumper = new DOMTreeDumper(
+ VpeDebug.VISUAL_DUMP_PRINT_HASH);
+ dumper.dumpToStream(System.out, 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
+ try {
+ TestDomUtil.compareNodes(vpeElement, xmlModelElement);
+ } catch (ComparisonException e) {
+ fail(e.getMessage());
+ }
+
+ }
+
+ /**
+ * test for invisible tags
+ *
+ * @param elementPagePath
+ * - path to test page
+ * @param elementId
+ * - id of element on page
+ * @throws Throwable
+ */
+ protected void performInvisibleTagTest(String elementPagePath,
+ String elementId) 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);
+
+ // find source element and check if it is not null
+ Element sourceELement = findSourceElementById(controller, elementId);
+ assertNotNull(sourceELement);
+
+ // find visual element and check if it is null
+ nsIDOMElement visualElement = findElementById(controller, elementId);
+ assertNull(visualElement);
+
+ // set show invisible tag's flag to true
+ controller.getVisualBuilder().setShowInvisibleTags(true);
+ controller.visualRefresh();
+
+ TestUtil.waitForIdle();
+
+ // find visual element and check if it is not null
+ visualElement = findElementById(controller, elementId);
+ assertNotNull(visualElement);
+
+ // generate text for invisible tag
+ String modelInvisibleTagText = generateInvisibleTagText(sourceELement
+ .getNodeName());
+
+ // generate dom document and get root element
+ Element modelElement = TestDomUtil.getDocument(modelInvisibleTagText)
+ .getDocumentElement();
+ assertNotNull(modelElement);
+
+ TestDomUtil.compareNodes(visualElement, modelElement);
+
+ if (getException() != null) {
+ throw getException();
+ }
+
+ }
+
+ /**
+ * test for invisible tags which can have visible children
+ *
+ * @param elementPagePath
+ * - path to test page
+ * @param elementId
+ * - id of element on page
+ * @throws Throwable
+ */
+ protected void performInvisibleWrapperTagTest(String elementPagePath,
+ String elementId) 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);
+
+ // find source element and check if it is not null
+ Element sourceELement = findSourceElementById(controller, elementId);
+ assertNotNull(sourceELement);
+
+ // find visual element and check if it is null
+ nsIDOMElement visualElement = findElementById(controller, elementId);
+ assertNull(visualElement);
+
+ // check children of non-visual
+ NodeList children = sourceELement.getChildNodes();
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ assertNotNull(findNode(controller, child));
+ }
+
+ // set show invisible tag's flag to true
+ controller.getVisualBuilder().setShowInvisibleTags(true);
+ controller.visualRefresh();
+
+ TestUtil.waitForIdle();
+
+ // find visual element and check if it is not null
+ visualElement = findElementById(controller, elementId);
+ assertNotNull(visualElement);
+
+ // generate text for invisible tag
+ String modelInvisibleTagText = generateInvisibleTagText(sourceELement
+ .getNodeName());
+
+ // generate dom document and get root element
+ Element modelElement = TestDomUtil.getDocument(modelInvisibleTagText)
+ .getDocumentElement();
+ assertNotNull(modelElement);
+
+ // compare elements
+ TestDomUtil.compareNodes(visualElement, modelElement);
+
+ if (getException() != null) {
+ throw getException();
+ }
+
+ }
+
+ /**
+ *
+ * @param tagName
+ * @return
+ */
+ private String generateInvisibleTagText(String tagName) {
+ return "<span style=\"border: 1px dashed GREY; color: GREY; font-size:
12px;\" >" //$NON-NLS-1$
+ + tagName + "</span>"; //$NON-NLS-1$
+ }
+
+ /**
+ * 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 = findSourceElementById(controller, elementId);
+
+ VpeNodeMapping nodeMapping = controller.getDomMapping().getNodeMapping(
+ sourceElement);
+
+ if (nodeMapping == null)
+ return null;
+
+ return (nsIDOMElement) nodeMapping.getVisualNode();
+ }
+
+ /**
+ * find visual element by "id" entered in source part of vpe
+ *
+ * @param controller
+ * @param elementId
+ * @return
+ */
+ protected nsIDOMNode findNode(VpeController controller, Node node) {
+
+ VpeNodeMapping nodeMapping = controller.getDomMapping().getNodeMapping(
+ node);
+
+ if (nodeMapping == null)
+ return null;
+
+ return nodeMapping.getVisualNode();
+ }
+
+ /**
+ * find source element by "id"
+ *
+ * @param controller
+ * @param elementId
+ * @return
+ */
+ protected Element findSourceElementById(VpeController controller,
+ String elementId) {
+
+ return getSourceDocument(controller).getElementById(elementId);
+ }
+
+ /**
+ *
+ * @return
+ */
+ abstract protected String getTestProjectName();
+
+}
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-10-23
22:06:47 UTC (rev 11128)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestUtil.java 2008-10-23
22:12:59 UTC (rev 11129)
@@ -193,14 +193,18 @@
/**
* Wait for idle.
*/
- public static void waitForIdle() {
+ public static void waitForIdle(long maxIdle) {
long start = System.currentTimeMillis();
while (!Job.getJobManager().isIdle()) {
delay(500);
- if ( (System.currentTimeMillis()-start) > MAX_IDLE )
+ if ( (System.currentTimeMillis()-start) > maxIdle )
throw new RuntimeException("A long running task detected"); //$NON-NLS-1$
}
}
+
+ public static void waitForIdle() {
+ waitForIdle(MAX_IDLE);
+ }
/**
* find elements by name.