Author: dgolovin
Date: 2011-09-15 14:09:30 -0400 (Thu, 15 Sep 2011)
New Revision: 34783
Removed:
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/DOMComparisonException.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/OpenOnUtil.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ProjectsLoader.java
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/TestUtil.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTest.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTestSetup.java
Log:
removing files from vpe.ui.test that were moved to vpe.base.test.
Deleted:
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 2011-09-15
17:49:22 UTC (rev 34782)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ComponentContentTest.java 2011-09-15
18:09:30 UTC (rev 34783)
@@ -1,372 +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;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-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.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;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
-import org.jboss.tools.vpe.editor.util.SourceDomUtil;
-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:
- * <p>
- * 1) xml file which contain tests must be named 'name of test page' +
- * '.xml'
- * <br>
- * Example: test.jsp and test.jsp.xml
- * <p>
- * 2) a tag <test> in xml file and required element in test page must have
- * the same attribute "id"
- * <br>
- * Example: <tests>... <test id="testId" > ...<tests> - in
xml file and
- * <br>
- * <html>... <x:testElement id="testId" > ... </html> - in
test page
- *
- * @param elementPagePath
- * - path to test page
- * @throws Throwable
- */
- protected void performContentTest(String elementPagePath) throws Throwable {
- performContentTestByFullPath(TestUtil.COMPONENTS_PATH + elementPagePath);
- }
-
- protected void performContentTestByFullPath(String elementPagePath) throws Throwable {
- setException(null);
- IFile elementPageFile = (IFile) TestUtil.getComponentFileByFullPath(
- elementPagePath, getTestProjectName());
- TestUtil.waitForIdle();
- /*
- * Test that test file was found and exists
- */
- assertNotNull("Could not find component file
'"+elementPagePath+"'", elementPageFile); //$NON-NLS-1$
//$NON-NLS-2$
-
- IEditorPart editor = WorkbenchUtils.openEditor(elementPageFile,getEditorID());
- assertNotNull("Editor should be opened.", editor); //$NON-NLS-1$
- VpeController controller = TestUtil.getVpeController((JSPMultiPageEditor) editor);
- /*
- * Get xml test file
- */
- File xmlTestFile = TestUtil.getComponentFileByFullPath(
- elementPagePath + XML_FILE_EXTENSION, getTestProjectName())
- .getLocation().toFile();
- /*
- * Test that XML test file was found and exists
- */
- assertNotNull("Could not find XML component file '"+elementPagePath +
XML_FILE_EXTENSION+"'", elementPageFile); //$NON-NLS-1$ //$NON-NLS-2$
- /*
- * 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) {
- try{
- compareElements(controller, xmlTestDocument, id, id);
- } catch (DOMComparisonException e) {
- String xPathToNode = SourceDomUtil.getXPath(e.getNode());
- String testFileName = xmlTestFile.getPath();
- String message = e.getMessage();
- fail(String.format("%s[%s]:\n%s", testFileName, xPathToNode, message));
//$NON-NLS-1$
- }
- }
- }
-
- /**
- *
- * @param controller
- * @param xmlTestDocument
- * @param elementId
- * @param xmlTestId
- * @return
- * @throws DOMComparisonException
- */
- private void compareElements(VpeController controller,
- Document xmlTestDocument, String elementId, String xmlTestId)
- throws DOMComparisonException {
- // get element by id
- nsIDOMElement vpeElement = findElementById(controller, elementId);
- assertNotNull("Cann't find element with id="+elementId,vpeElement);
//$NON-NLS-1$
-
- // 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);
-
- 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 {
- performInvisibleTagTestByFullPath(TestUtil.COMPONENTS_PATH
- + elementPagePath, elementId);
- }
-
- /**
- * test for invisible tags
- *
- * @param elementPagePath
- * - path to test page
- * @param elementId
- * - id of element on page
- * @throws Throwable
- */
- protected void performInvisibleTagTestByFullPath(String elementPagePath,
- String elementId) throws Throwable {
- setException(null);
-
- IFile elementPageFile = (IFile) TestUtil.getComponentFileByFullPath(
- elementPagePath, getTestProjectName());
- /*
- * Test that test file was found and exists
- */
- assertNotNull("Could not find component file
'"+elementPagePath+"'", elementPageFile); //$NON-NLS-1$
//$NON-NLS-2$
- /*
- * Open the editor
- */
- IEditorInput input = new FileEditorInput(elementPageFile);
- TestUtil.waitForJobs();
- IEditorPart editor = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage().openEditor(input,
- getEditorID(), true);
- assertNotNull("Editor should be opened.", editor); //$NON-NLS-1$
- TestUtil.waitForJobs();
- /*
- * Get the controller
- */
- VpeController controller = TestUtil.getVpeController((JSPMultiPageEditor) editor);
- /*
- * Find source element and check if it is not null
- */
- Element sourceElement = findSourceElementById(controller, elementId);
- assertNotNull("Source node with id '" + elementId + "' was not
found.", sourceElement); //$NON-NLS-1$ //$NON-NLS-2$
- /*
- * Find visual element and check if it is null
- */
- nsIDOMElement visualElement = findElementById(controller, elementId);
- assertNull("Source node with id '" + elementId + "' has visual
representation.", visualElement); //$NON-NLS-1$ //$NON-NLS-2$
-
- /*
- * Set show invisible tag's flag to true
- */
- controller.getVisualBuilder().setShowInvisibleTags(true);
- controller.visualRefresh();
-
- /*
- * Find visual element and check if it is not null
- */
- visualElement = findElementById(controller, elementId,TestUtil.MAX_IDLE);
- 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,
- getEditorID(), true);
-
- assertNotNull(editor);
-
- TestUtil.waitForJobs();
-
- VpeController controller = TestUtil.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
- * @param idle try element for some time period, for example when we need
- * to wait for refresh job
- * @return
- */
- protected nsIDOMElement findElementById(VpeController controller,
- String elementId, long idle) {
- long start = System.currentTimeMillis();
- nsIDOMElement result = null;
- while (result==null) {
- result = findElementById(controller, elementId);
- TestUtil.delay(50);
- if (result==null && ((System.currentTimeMillis()-start) > idle) )
- throw new RuntimeException("A long running task detected"); //$NON-NLS-1$
- }
- return result;
- }
- /**
- * 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();
- }
-
- /**
- *
- * @return
- */
- abstract protected String getTestProjectName();
-
-}
Deleted:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/DOMComparisonException.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/DOMComparisonException.java 2011-09-15
17:49:22 UTC (rev 34782)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/DOMComparisonException.java 2011-09-15
18:09:30 UTC (rev 34783)
@@ -1,32 +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;
-
-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;
- }
-}
Deleted:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/OpenOnUtil.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/OpenOnUtil.java 2011-09-15
17:49:22 UTC (rev 34782)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/OpenOnUtil.java 2011-09-15
18:09:30 UTC (rev 34783)
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2009 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.ui.test;
-
-import java.lang.reflect.Method;
-import static junit.framework.Assert.assertEquals;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.hyperlink.IHyperlink;
-import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.MultiPageEditorPart;
-import org.eclipse.ui.texteditor.AbstractTextEditor;
-import org.eclipse.wst.sse.ui.StructuredTextEditor;
-import org.jboss.tools.common.model.ui.editor.EditorPartWrapper;
-import org.jboss.tools.common.model.ui.texteditors.XMLTextEditorStandAlone;
-import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlink;
-import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
-
-/**
- * @author Sergey Dzmitrovich
- *
- */
-public class OpenOnUtil {
-
- /**
- * method does open on action in editor
- *
- * @param textEditor
- * @param lineNumber
- * @param lineOffset
- * @throws Throwable
- */
- public static final void performOpenOnAction(
- StructuredTextEditor textEditor, int offset) throws Throwable {
-
- // hack to get hyperlinks detectors, no other was have been founded
- Method method = AbstractTextEditor.class
- .getDeclaredMethod("getSourceViewerConfiguration"); //$NON-NLS-1$
- method.setAccessible(true);
- SourceViewerConfiguration sourceViewerConfiguration = (SourceViewerConfiguration)
method
- .invoke(textEditor);
- IHyperlinkDetector[] hyperlinkDetectors = sourceViewerConfiguration
- .getHyperlinkDetectors(textEditor.getTextViewer());
-
- for (IHyperlinkDetector iHyperlinkDetector : hyperlinkDetectors) {
- IHyperlink[] hyperLinks = iHyperlinkDetector.detectHyperlinks(
- textEditor.getTextViewer(), new Region(offset, 0), false);
- if (hyperLinks != null && hyperLinks.length > 0
- && hyperLinks[0] instanceof AbstractHyperlink) {
- AbstractHyperlink abstractHyperlink = (AbstractHyperlink) hyperLinks[0];
- abstractHyperlink.open();
- break;
- }
- }
-
- }
-
- /**
- * Function for checking openOn functionality
- *
- * @param editorInput
- * @param editorId
- * @param lineNumber
- * @param lineOffset
- * @param openedOnFileName
- * @throws Throwable
- *
- * @author mareshkau
- */
-
- public static final void checkOpenOnInEditor(IEditorInput editorInput,String
editorId,int lineNumber, int lineOffset, String openedOnFileName) throws Throwable {
- StructuredTextEditor textEditor = getStructuredTextEditorPart(editorInput, editorId);
-
- int openOnPosition = TestUtil.getLinePositionOffcet(textEditor
- .getTextViewer(),lineNumber, lineOffset);
- // hack to get hyperlinks detectors, no other was have been founded
- Method method = AbstractTextEditor.class
- .getDeclaredMethod("getSourceViewerConfiguration"); //$NON-NLS-1$
- method.setAccessible(true);
- SourceViewerConfiguration sourceViewerConfiguration = (SourceViewerConfiguration)
method
- .invoke(textEditor);
- IHyperlinkDetector[] hyperlinkDetectors = sourceViewerConfiguration
- .getHyperlinkDetectors(textEditor.getTextViewer());
- for (IHyperlinkDetector iHyperlinkDetector : hyperlinkDetectors) {
- IHyperlink[] hyperLinks = iHyperlinkDetector.detectHyperlinks(
- textEditor.getTextViewer(), new Region(openOnPosition, 0),
- false);
- if (hyperLinks != null && hyperLinks.length > 0
- && hyperLinks[0] instanceof AbstractHyperlink) {
- AbstractHyperlink abstractHyperlink = (AbstractHyperlink) hyperLinks[0];
- abstractHyperlink.open();
- break;
- }
- }
- IEditorPart activeEditor = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
- assertEquals(
- "Active page should be ", openedOnFileName,
activeEditor.getEditorInput().getName()); //$NON-NLS-1$
- }
-
- private static StructuredTextEditor getStructuredTextEditorPart(IEditorInput
editorInput,String editorId) throws PartInitException{
- IEditorPart editorPart = PlatformUI
- .getWorkbench().getActiveWorkbenchWindow().getActivePage()
- .openEditor(editorInput, editorId);
- StructuredTextEditor textEditor = null;
- if(editorPart instanceof MultiPageEditorPart){
- StructuredTextEditor structuredTextEditor =
findStructEditor((MultiPageEditorPart)editorPart, editorInput);
- ((MultiPageEditorPart)editorPart).setActiveEditor(structuredTextEditor);
- textEditor = structuredTextEditor;
- } else if(editorPart instanceof JSPMultiPageEditor) {
- textEditor = ((JSPMultiPageEditor)editorPart).getSourceEditor();
- } else if(editorPart instanceof EditorPartWrapper
- &&(((EditorPartWrapper)editorPart).getEditor()) instanceof
MultiPageEditorPart) {
- StructuredTextEditor structuredTextEditor =
findStructEditor((MultiPageEditorPart)((EditorPartWrapper)editorPart).getEditor(),
editorInput);
- ((MultiPageEditorPart)((EditorPartWrapper)editorPart).getEditor()).setActiveEditor(structuredTextEditor);
- textEditor = structuredTextEditor;
- } else if(editorPart instanceof EditorPartWrapper &&
- (((EditorPartWrapper)editorPart).getEditor()) instanceof StructuredTextEditor){
- textEditor = (StructuredTextEditor) (((EditorPartWrapper)editorPart).getEditor());
- }
- return textEditor;
- }
-
- private static StructuredTextEditor findStructEditor (MultiPageEditorPart part,
IEditorInput input){
- IEditorPart[] editorParts = part.findEditors(input);
- for (int i = 0; i < editorParts.length; i++) {
- if (editorParts[i] instanceof StructuredTextEditor) {
- return (StructuredTextEditor) editorParts[i];
- }
- }
- return null;
- }
-
-}
Deleted:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ProjectsLoader.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ProjectsLoader.java 2011-09-15
17:49:22 UTC (rev 34782)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ProjectsLoader.java 2011-09-15
18:09:30 UTC (rev 34783)
@@ -1,200 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2010 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.ui.test;
-
-import java.io.IOException;
-import java.lang.reflect.InvocationTargetException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.Assert;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Platform;
-import org.jboss.tools.test.util.JobUtils;
-import org.jboss.tools.test.util.ResourcesUtils;
-import org.osgi.framework.Bundle;
-
-/**
- * Singleton class to operate on test projects.
- *
- * @see {@code org.jboss.tools.vpe.ui.tests} extension point
- * @author Yahor Radtsevich (yradtsevich)
- */
-public class ProjectsLoader {
- private static final String TEST_PROJECT_ELEMENT = "testProject";
- private static final String TEST_PROJECT_PATH_ATTRIBUTE = "path";
- private static final String TEST_PROJECT_NAME_ATTRIBUTE = "name";
- private Map<String, ProjectLocation> projectNameToLocation;
- private static ProjectsLoader instance = null;
-
- private ProjectsLoader() {
- /*
- * Load project names and paths to them from the extensions of
- * {@link VpeAllTests#VPE_TEST_EXTENTION_POINT_ID}. And store
- * loaded data in {@link #projectNameToLocation}.
- */
- projectNameToLocation = new HashMap<String, ProjectLocation>();
- IExtension[] extensions = VPETestPlugin.getDefault().getVpeTestExtensions();
- for (IExtension extension : extensions) {
- IConfigurationElement[] confElements = extension
- .getConfigurationElements();
- for (IConfigurationElement configurationElement : confElements) {
- if (TEST_PROJECT_ELEMENT.equals(
- configurationElement.getName())) {
- Bundle bundle = Platform.getBundle(
- configurationElement.getNamespaceIdentifier());
- String name = configurationElement.getAttribute(
- TEST_PROJECT_NAME_ATTRIBUTE);
- String path = configurationElement.getAttribute(
- TEST_PROJECT_PATH_ATTRIBUTE);
-
- projectNameToLocation.put(name,
- new ProjectLocation(bundle, path));
- }
- }
- }
- }
-
- /**
- * Returns the instance of {@link ProjectsLoader}
- */
- public static ProjectsLoader getInstance() {
- if (instance == null) {
- instance = new ProjectsLoader();
- }
-
- return instance;
- }
-
- /**
- * Returns instance of {@link IProject} by {@code projectName}.
- * If the project does not exist in the workspace, imports it from the
- * resources specified by extensions of {@code org.jboss.tools.vpe.ui.tests}
- * extension point.
- * <p>
- * This method has <i>fail-fast</i> behavior. It never returns {@code
null}.
- * It throws exceptions in the cases if the project is not defined,
- * can not be opened, etc.
- */
- public IProject getProject(String projectName) throws IOException {
- IProject project = getExistingProject(projectName);
-
- if (!project.isAccessible()) {
- ProjectLocation location = projectNameToLocation.get(projectName);
- if (location == null) {
- throw new RuntimeException(
- "Project '" + project + "' is not defined.");
- }
-
- try {
- project = ResourcesUtils.importProject(location.getBundle(), location.getPath(),
projectName, new NullProgressMonitor());
- } catch (CoreException e) {
- throw new RuntimeException("Project by the path='" +
location.getPath()
- + "' cannot be imported.",e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException("Project by the path='" +
location.getPath()
- + "' cannot be imported.",e);
- } catch (InterruptedException e) {
- throw new RuntimeException("Project by the path='" +
location.getPath()
- + "' cannot be imported.",e);
- }
- }
-
- return project;
- }
-
- /**
- * Returns a workspace project by its {@code projectName}, or {@code null}
- * if there is no project with this name in the workspace.
- */
- public static IProject getExistingProject(String projectName) {
- return ResourcesPlugin.getWorkspace().getRoot()
- .getProject(projectName);
- }
-
- /**
- * Removes the project with the {@code projectName} from the workspace.
- *
- * @param projectName the project name
- * @throws CoreException the core exception
- */
- static public void removeProject(String projectName) throws CoreException {
- IProject project = ProjectsLoader.getExistingProject(projectName);
- removeProject(project);
- }
-
- /**
- * Removes given {@code project} from the workspace
- *
- * @param project project to remove
- * @throws CoreException
- */
- private static void removeProject(IProject project) throws CoreException {
- boolean saveAutoBuild = ResourcesUtils.setBuildAutomatically(false);
- try {
- if (project != null) {
- project.delete(IResource.ALWAYS_DELETE_PROJECT_CONTENT,
- new NullProgressMonitor());
- JobUtils.waitForIdle();
- }
- } finally {
- ResourcesUtils.setBuildAutomatically(saveAutoBuild);
- }
- }
-
- /**
- * Removes all projects from the workspace
- *
- * @throws CoreException
- */
- static public void removeAllProjects() throws CoreException {
- IProject[] projects = ResourcesPlugin.getWorkspace().getRoot()
- .getProjects();
- for (IProject project: projects) {
- removeProject(project);
- }
- }
-
- /**
- * Stores the {@code path} to a project and the owning {@code bundle}.
- *
- * @author Yahor Radtsevich (yradtsevich)
- */
- private class ProjectLocation {
- private Bundle bundle;
- private String path;
-
- public ProjectLocation(Bundle bundle, String path) {
- this.bundle = bundle;
- this.path = path;
- }
- public Bundle getBundle() {
- return bundle;
- }
- public String getPath() {
- return path;
- }
-
- public String toString() {
- return String.format("(%s, %s)",
- bundle == null ? null : bundle.getLocation(), path);
- }
- }
-}
Deleted:
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 2011-09-15
17:49:22 UTC (rev 34782)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestDomUtil.java 2011-09-15
18:09:30 UTC (rev 34783)
@@ -1,381 +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;
-
-import static org.jboss.tools.vpe.xulrunner.util.XPCOM.queryInterface;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-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;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.jboss.tools.common.model.util.XMLUtil;
-import org.jboss.tools.jst.css.common.CSSStyleManager;
-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;
-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;
-import org.w3c.dom.css.CSSStyleDeclaration;
-import org.w3c.dom.css.ElementCSSInlineStyle;
-
-/**
- * @author Sergey Dzmitrovich
- *
- */
-public class TestDomUtil {
- /**
- * Attributes names that will be skipped in attribute comparison.
- */
- public static final Set<String> skippedAtributes = new HashSet<String>();
- static {
- // Add here all attributes names to be skipped (IN UPPER CASE!)
- skippedAtributes.addAll(Arrays.asList("DIR"));//$NON-NLS-1$
- }
-
- final public static String ID_ATTRIBUTE = "id"; //$NON-NLS-1$
-
- final public static String ILLEGAL_ATTRIBUTES = "illegalAttributes";
//$NON-NLS-1$
-
- final public static String ILLEGAL_ATTRIBUTES_SEPARATOR = Constants.COMMA;
-
- final public static String START_REGEX = "/"; //$NON-NLS-1$
-
- final public static String END_REGEX = "/"; //$NON-NLS-1$
-
- 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
- * @throws DOMComparisonException
- */
- public static void compareNodes(nsIDOMNode vpeNode, Node modelNode)
- throws DOMComparisonException {
-
- if (!modelNode.getNodeName().equalsIgnoreCase(vpeNode.getNodeName())) {
- throw new DOMComparisonException("name of tag is \"" //$NON-NLS-1$
- + vpeNode.getNodeName() + "\"but must be \"" //$NON-NLS-1$
- + modelNode.getNodeName() + "\"", modelNode); //$NON-NLS-1$
- }
- if ((modelNode.getNodeValue() != null)
- && (!modelNode.getNodeValue().trim().equalsIgnoreCase(
- vpeNode.getNodeValue().trim()))) {
- 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$
- + "\"", modelNode); //$NON-NLS-1$
- }
-
- // compare node's attributes
- if (modelNode.getNodeType() == Node.ELEMENT_NODE) {
- compareAttributes(modelNode.getAttributes(), vpeNode
- .getAttributes());
- }
-
- // compare children
- nsIDOMNodeList vpeChildren = vpeNode.getChildNodes();
- NodeList schemeChildren = modelNode.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++);
-
- if (null == vpeChild) {
- throw new DOMComparisonException(
- "Child of node \"" //$NON-NLS-1$
- + vpeNode.getNodeName()
- + "\" is \"null\", but should be \"" +
schemeChild.getNodeName() + "\"",//$NON-NLS-1$ //$NON-NLS-2$
- schemeChild);
- }
-
- // 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 (null == vpeChild) {
- throw new DOMComparisonException(
- "Child of node \"" //$NON-NLS-1$
- + vpeNode.getNodeName()
- + "\" is \"null\", but should be \"" +
schemeChild.getNodeName() + "\"",//$NON-NLS-1$ //$NON-NLS-2$
- schemeChild);
- }
- }
-
- compareNodes(vpeChild, schemeChild);
-
- }
-
- }
-
- /**
- * get ids of tests
- *
- * @param testDocument
- * @return
- */
- public static List<String> getTestIds(Document testDocument) {
- Element rootElement = testDocument.getDocumentElement();
- List<String> ids = new ArrayList<String>();
- NodeList children = rootElement.getChildNodes();
- for (int i = 0; i < children.getLength(); i++) {
- Node child = children.item(i);
- if (child.getNodeType() == Node.ELEMENT_NODE)
- ids.add(((Element) child).getAttribute(ID_ATTRIBUTE));
-
- }
- return ids;
- }
-
- private static void compareAttributes(NamedNodeMap modelAttributes,
- nsIDOMNamedNodeMap vpeAttributes) throws DOMComparisonException {
-
- for (int i = 0; i < modelAttributes.getLength(); i++) {
- Attr modelAttr = (Attr) modelAttributes.item(i);
- String name = modelAttr.getName();
- // if the attribute has to be skipped, then do it
- if ( name != null
- && skippedAtributes.contains(name.toUpperCase()) ) {
- continue;
- }
- // if there are limitation of attributes
- if (ILLEGAL_ATTRIBUTES.equals(name)) {
- String[] illegalAttributes = modelAttr.getNodeValue().split(
- ILLEGAL_ATTRIBUTES_SEPARATOR);
- for (String illegalAttributeName : illegalAttributes) {
- if (vpeAttributes.getNamedItem(illegalAttributeName.trim()) != null)
- throw new DOMComparisonException("illegal attribute :" //$NON-NLS-1$
- + illegalAttributeName, modelAttr);
- }
- } else {
- if (vpeAttributes.getNamedItem(name) == null) {
- throw new DOMComparisonException("there is not : \"" + name
//$NON-NLS-1$
- + "\" attribute", modelAttr); //$NON-NLS-1$
- }
- nsIDOMAttr vpeAttr = queryInterface(
- vpeAttributes.getNamedItem(name), nsIDOMAttr.class);
- /*
- * By default every attribute show pass through
- * compareComplexStrings(..) method.
- * For "style" attribute there is a separate comparison.
- */
- boolean performComplexStringsComparison = true;
- if (HTML.ATTR_STYLE.equalsIgnoreCase(name)) {
- String xmlAttrValue = modelAttr.getNodeValue();
- /*
- * Check if it is not a regular expression.
- * Otherwise perform Complex Strings Comparison
- * as usual.
- */
- if (!(xmlAttrValue.startsWith(START_REGEX)
- && xmlAttrValue.endsWith(END_REGEX))) {
- performComplexStringsComparison = false;
- /*
- * Parse style attribute value
- */
- Map<String, String> vpeStyle = CSSStyleManager
- .getStyleAttributes(vpeAttr.getNodeValue());
- Map<String, String> xmlStyle = CSSStyleManager
- .getStyleAttributes(xmlAttrValue);
- /*
- * Major condition is that
- * all styles from the xml file should present
- * in the style attribute of the vpe element.
- */
- if (xmlStyle.size() > vpeStyle.size()) {
- 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$
- 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 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)
- + "]", modelAttr); //$NON-NLS-1$
- }
- } else {
- throw new DOMComparisonException(
- "Style parameter [" //$NON-NLS-1$
- + key
- + "] is missing in the VPE element", //$NON-NLS-1$
- modelAttr);
- }
- }
- }
- }
- }
- }
- if (performComplexStringsComparison) {
- compareComplexAttributes(modelAttr, vpeAttr);
- }
- }
- }
- }
-
- 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());
- int firstPos = regex.indexOf("url\\("); //$NON-NLS-1$
- if (firstPos > -1) {
- String subString = regex.substring(firstPos + 5, firstPos + 5 + 2);
- if (!"\"?".equalsIgnoreCase(subString)) { //$NON-NLS-1$
- String firstPart = regex.substring(0, firstPos + 5);
- String secondPart = regex.substring(firstPos + 5, regex.length());
- int lastPos = secondPart.indexOf("\\)"); //$NON-NLS-1$
- if (lastPos > -1) {
- String subs = secondPart.substring(lastPos - 2, lastPos);
- if (!"\"?".equalsIgnoreCase(subs)) { //$NON-NLS-1$
- String fpart = secondPart.substring(0, lastPos);
- String spart = secondPart.substring(lastPos, secondPart.length());
- regex = firstPart + "\"?" + fpart + "\"?" + spart;
//$NON-NLS-1$ //$NON-NLS-2$
- }
- }
- }
- }
- Matcher matcher = Pattern.compile(regex).matcher(vpeString);
- if (!matcher.find()) {
- 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 DOMComparisonException("string is\"" + vpeString
//$NON-NLS-1$
- + "\" but must be \"" + modelString + "\"",
modelAttr); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- }
-
- /**
- * is created to be sure that attributes/parameters will be correctly
- * compared ( ignore case )
- *
- * @param list
- * @param string
- * @return
- */
- static private boolean findIgnoreCase(String[] strings,
- String requiredString) {
- for (String string : strings) {
- if (string.equalsIgnoreCase(requiredString))
- return true;
- }
-
- return false;
- }
-}
Deleted:
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 2011-09-15
17:49:22 UTC (rev 34782)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestUtil.java 2011-09-15
18:09:30 UTC (rev 34783)
@@ -1,46 +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;
-
-import org.jboss.tools.test.util.JobUtils;
-
-/**
- * Class for importing project from jar file.
- *
- * @author sdzmitrovich
- */
-public class TestUtil extends org.jboss.tools.vpe.base.test.TestUtil {
-
- /**
- * Wait until all background tasks are complete.
- */
- public static void waitForJobs() {
- //commented by Maksim Areshkau
- //because this method wait only for jobs which has been runned in current thread,
- //and don't wait for others. It can cause
https://jira.jboss.org/jira/browse/JBIDE-5820
- //https://jira.jboss.org/jira/browse/JBIDE-5821
-// while (Job.getJobManager().currentJob() != null)
-// delay(100);
- waitForIdle();
- }
-
- /**
- * Wait for idle.
- */
- public static void waitForIdle(long maxIdle) {
- JobUtils.waitForIdle(500, maxIdle);
- }
-
- public static void waitForIdle() {
- waitForIdle(MAX_IDLE);
- }
-
-}
Deleted:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTest.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTest.java 2011-09-15
17:49:22 UTC (rev 34782)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTest.java 2011-09-15
18:09:30 UTC (rev 34783)
@@ -1,438 +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;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.ILogListener;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.jboss.tools.jst.jsp.JspEditorPlugin;
-import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
-import org.jboss.tools.jst.jsp.preferences.IVpePreferencesPage;
-import org.jboss.tools.vpe.editor.VpeController;
-import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
-import org.jboss.tools.vpe.editor.mapping.VpeElementMapping;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
-import org.jboss.tools.vpe.editor.util.SelectionUtil;
-import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
-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;
-
-/**
- * The Class VpeTest.
- *
- * @author Max Areshkau
- *
- * Base Class for VPE tests
- */
-public class VpeTest extends TestCase implements ILogListener {
-
- /** Editor in which we open visual page. */
- protected final static String EDITOR_ID =
"org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor"; //$NON-NLS-1$
-
- /** Collects exceptions. */
- private Throwable exception;
-
- /** check warning log. */
- private boolean checkWarning = false;
-
- // FIX for JBIDE-1628
- static {
- JspEditorPlugin
- .getDefault()
- .getPreferenceStore()
- .setValue(
- IVpePreferencesPage.INFORM_WHEN_PROJECT_MIGHT_NOT_BE_CONFIGURED_PROPERLY_FOR_VPE,
- false);
- }
-
- /**
- * The Constructor.
- *
- * @param importProjectName
- * * @param name the name
- */
-
- public VpeTest(String name) {
- super(name);
-
- }
-
- /**
- * Perform pre-test initialization.
- *
- * @throws Exception
- * the exception
- *
- * @see TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- Platform.addLogListener(this);
- // String jbossPath = System.getProperty(
- // "jbosstools.test.jboss.home.4.2", "C:\\java\\jboss-4.2.2.GA");
- // JBossASAdapterInitializer.initJBossAS(jbossPath, new
- // NullProgressMonitor());
- closeEditors();
- }
-
- /**
- * Perform post-test cleanup.
- *
- * @throws Exception
- * the exception
- *
- * @see TestCase#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
-//Has been commented by Maksim Areshkau,
-//this lines was a fix for JBIDE-6197 and not needed under eclipse 3.6
-// boolean isJobsCheck = true;
-// while (isJobsCheck) {
-// isJobsCheck = false;
-// Job[] jobs = Job.getJobManager().find(null);
-// for (Job job : jobs) {
-// if (job instanceof StructuredRegionProcessor) {
-// TestUtil.delay(50);
-// isJobsCheck = true;
-// break;
-// }
-// }
-// }
-
- closeEditors();
-
- Platform.removeLogListener(this);
-
- if (getException() != null) {
- throw new Exception(getException());
- }
-
- super.tearDown();
-
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.eclipse.core.runtime.ILogListener#logging(org.eclipse.core.runtime
- * .IStatus, java.lang.String)
- */
- /**
- * Logging.
- *
- * @param status
- * the status
- * @param plugin
- * the plugin
- */
- public void logging(IStatus status, String plugin) {
- switch (status.getSeverity()) {
- case IStatus.ERROR:
- setException(status.getException());
- break;
- case IStatus.WARNING:
- if (isCheckWarning())
- setException(status.getException());
- break;
- default:
- break;
- }
-
- }
-
- /**
- * close all opened editors.
- */
- protected void closeEditors() {
-
- // wait
- // TestUtil.waitForJobs();
- IWorkbenchPage page = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage();
- IWorkbenchPart part = page.getActivePart();
- page.activate(part);
- // close
- page.closeAllEditors(false);
-
- }
-
- /**
- *
- * @return source document
- */
- protected Document getSourceDocument(VpeController controller) {
-
- return controller.getSourceBuilder().getSourceDocument();
-
- }
-
- /**
- * Perfoms test for some page.
- *
- * @param componentPage
- * the component page
- *
- * @throws Throwable
- * the throwable
- * @throws PartInitException
- * the part init exception
- */
- protected void performTestForVpeComponent(IFile componentPage)
- throws PartInitException, Throwable {
- TestUtil.waitForJobs();
-
- setException(null);
-
- // IFile file = (IFile)
- // TestUtil.getComponentPath(componentPage,getImportProjectName());
- IEditorInput input = new FileEditorInput(componentPage);
-
- TestUtil.waitForJobs();
-
- IEditorPart editor = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage().openEditor(input,
- getEditorID(), true);
- // here we wait for inintialization VPE controller
- TestUtil.getVpeController((JSPMultiPageEditor) editor);
-
- assertNotNull(editor);
-
- TestUtil.waitForJobs();
- // JBIDE-1628
- // TestUtil.delay(1000);
-
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
- .closeAllEditors(true);
-
- if (getException() != null) {
- throw getException();
- }
- }
-
- /**
- * Open JSPMultiPageEditor editor.
- *
- * @param input
- * the input
- *
- * @return the JSP multi page editor
- *
- * @throws PartInitException
- * the part init exception
- */
- protected JSPMultiPageEditor openEditor(IEditorInput input)
- throws PartInitException {
-
- // get editor
- JSPMultiPageEditor part = (JSPMultiPageEditor) PlatformUI
- .getWorkbench().getActiveWorkbenchWindow().getActivePage()
- .openEditor(input, getEditorID(), true);
-
- assertNotNull(part);
- return part;
-
- }
-
- /**
- * Gets the exception.
- *
- * @return the exception
- */
- protected Throwable getException() {
- return exception;
- }
-
- /**
- * Sets the exception.
- *
- * @param exception
- * the exception to set
- */
- protected void setException(Throwable exception) {
- this.exception = exception;
- }
-
- /**
- * Checks if is check warning.
- *
- * @return the checkWarning
- */
- protected boolean isCheckWarning() {
- return checkWarning;
- }
-
- /**
- * Sets the check warning.
- *
- * @param checkWarning
- * the checkWarning to set
- */
- protected void setCheckWarning(boolean checkWarning) {
- this.checkWarning = checkWarning;
- }
-
- /**
- * Compares source nodes selection and visual selection
- *
- * @param VPE
- * Editor part
- */
- protected void checkSourceSelection(JSPMultiPageEditor part) {
- // get controller
- VpeController controller = TestUtil.getVpeController(part);
- assertNotNull(controller);
-
- // get dommapping
- VpeDomMapping domMapping = controller.getDomMapping();
-
- assertNotNull(domMapping);
-
- // get source map
- Map<Node, VpeNodeMapping> sourceMap = domMapping.getSourceMap();
- assertNotNull(sourceMap);
-
- // get collection of VpeNodeMapping
- Collection<VpeNodeMapping> mappings = sourceMap.values();
- assertNotNull(mappings);
-
- // get editor control
- StyledText styledText = part.getSourceEditor().getTextViewer()
- .getTextWidget();
- assertNotNull(styledText);
-
- // get xulrunner editor
- XulRunnerEditor xulRunnerEditor = controller.getXulRunnerEditor();
- assertNotNull(xulRunnerEditor);
-
- for (VpeNodeMapping nodeMapping : mappings) {
-
- /**
- * exclude out DomDocument ( it is added to mapping specially ) and
- * nodes without visual representation
- */
- if (!(nodeMapping.getSourceNode() instanceof IDOMDocument)
- && (nodeMapping.getVisualNode() != null)) {
-
- SelectionUtil.setSourceSelection(controller.getPageContext(),
- nodeMapping.getSourceNode(), 1, 0);
-
- TestUtil.delay(50);
-
- assertNotNull(xulRunnerEditor.getSelectedElement());
-
- nsIDOMNode sample;
- if (nodeMapping.getSourceNode().getNodeType() == Node.TEXT_NODE
- && ((VpeElementMapping) nodeMapping).getElementData() != null) {
-
- sample = ((VpeElementMapping) nodeMapping).getElementData()
- .getNodesData().get(0).getVisualNode();
- } else {
- sample = nodeMapping.getVisualNode();
- }
-
- assertEquals(sample, xulRunnerEditor.getSelectedElement());
- }
- }
- }
-
- /**
- * Opens specified file in the VPE editor.
- *
- * @param projectName
- * the name of the project
- * @param fileName
- * the name of the file
- *
- * @return VpeController
- * @throws CoreException
- * @throws IOException
- */
- protected VpeController openInVpe(String projectName, String fileName)
- throws CoreException, IOException {
- // get test page path
- final IFile file = (IFile) TestUtil.getComponentPath(fileName,
- projectName);
- assertNotNull("Could not open specified file." //$NON-NLS-1$
- + " componentPage = " + fileName //$NON-NLS-1$
- + ";projectName = " + projectName, file); //$NON-NLS-1$
-
- final IEditorInput input = new FileEditorInput(file);
- assertNotNull("Editor input is null", input); //$NON-NLS-1$
-
- // open and get the editor
- final JSPMultiPageEditor part = openEditor(input);
-
- final VpeController vpeController = TestUtil.getVpeController(part);
- return vpeController;
- }
-
- /**
- * find source element by "id"
- *
- * @param controller
- * @param elementId
- * @return
- */
- protected Element findSourceElementById(VpeController controller,
- String elementId) {
-
- return getSourceDocument(controller).getElementById(elementId);
- }
-
- /**
- * 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();
- }
-
- protected String getEditorID(){
- return EDITOR_ID;
- }
-}
Deleted:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTestSetup.java
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTestSetup.java 2011-09-15
17:49:22 UTC (rev 34782)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/VpeTestSetup.java 2011-09-15
18:09:30 UTC (rev 34783)
@@ -1,55 +0,0 @@
-/*******************************************************************************
-* Copyright (c) 2007-2010 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.eclipse.ui.IViewReference;
-import org.eclipse.ui.PlatformUI;
-
-import junit.extensions.TestSetup;
-import junit.framework.TestSuite;
-
-/**
- * @author Max Areshkau
- * @author Yahor Radtsevich (yradtsevich)
- *
- * Class for tear down JUnit tests (remove projects from workspace)
- *
- */
-public class VpeTestSetup extends TestSetup {
- private static final String CONTENT_OUTLINE_VIEW_ID =
"org.eclipse.ui.views.ContentOutline";
-
- public VpeTestSetup(TestSuite test) {
- super(test);
- }
-
- /* (non-Javadoc)
- * @see junit.extensions.TestSetup#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- //added by Maksim Areshkau, Fix for
https://jira.jboss.org/jira/browse/JBIDE-5820
https://jira.jboss.org/jira/browse/JBIDE-5821
- //remove this code when we will move on wtp 3.2
- IViewReference[] iviewReferences=
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
- for (IViewReference iViewReference : iviewReferences) {
-
if(VpeTestSetup.CONTENT_OUTLINE_VIEW_ID.equalsIgnoreCase(iViewReference.getId())){
-
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(iViewReference);
- }
- }
- }
-
- /* (non-Javadoc)
- * @see junit.extensions.TestSetup#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
- ProjectsLoader.removeAllProjects();
- }
-}