Author: estherbin
Date: 2008-08-06 05:39:08 -0400 (Wed, 06 Aug 2008)
New Revision: 9559
Added:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/CommonJBIDE2010Test.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ElPreferencesTestCase.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/JBIDE2010Test.java
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/JBIDE2582Test.java
Modified:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestUtil.java
Log:
Move test cases from *.vpe.test to the vpe.ui.test package.
Copied:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/CommonJBIDE2010Test.java
(from rev 9489,
trunk/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/test/CommonJBIDE2010Test.java)
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/CommonJBIDE2010Test.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/CommonJBIDE2010Test.java 2008-08-06
09:39:08 UTC (rev 9559)
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * 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.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.core.resources.IFile;
+import org.jboss.tools.vpe.editor.css.ELReferenceList;
+import org.jboss.tools.vpe.editor.css.ResourceReference;
+
+
+/**
+ * The common test case for the all test cases related to the <a
+ * href="https://jira.jboss.com:8443/jira/browse/JBIDE-2010"
+ * >JBIDE-2010</a>issue.
+ */
+public abstract class CommonJBIDE2010Test extends VpeTest {
+
+ /** The Constant DIR_TEST_PAGE_NAME_3. */
+ protected static final String DIR_TEST_PAGE_NAME_3 =
"JBIDE/2010/page3.xhtml"; //$NON-NLS-1$
+
+ /** The Constant VALUE_5. */
+ protected static final String VALUE_5 = "world"; //$NON-NLS-1$
+
+ /** The Constant KEY_5. */
+ protected static final String KEY_5 = "#{bean1.property3}"; //$NON-NLS-1$
+
+ /** The Constant VALUE_4. */
+ protected static final String VALUE_4 = "background: red"; //$NON-NLS-1$
+
+ /** The Constant KEY_4. */
+ protected static final String KEY_4 = "#{bean1.property2}"; //$NON-NLS-1$
+
+ /** The Constant IMPORT_PROJECT_NAME. */
+ public static final String IMPORT_PROJECT_NAME = "jsfTest"; //$NON-NLS-1$
+
+ /** The Constant KEY_3. */
+ protected static final String KEY_3 = "#{facesContext.requestPath}";
//$NON-NLS-1$
+
+ /** The Constant KEY_2. */
+ protected static final String KEY_2 = "#{beanA.property2}"; //$NON-NLS-1$
+
+ /** The Constant DIR_TEST_PAGE_NAME. */
+ protected static final String DIR_TEST_PAGE_NAME_2 =
"JBIDE/2010/page2.jsp"; //$NON-NLS-1$
+
+ /** The Constant DIR_TEST_PAGE_NAME. */
+ protected static final String DIR_TEST_PAGE_NAME = "JBIDE/2010/page.jsp";
//$NON-NLS-1$
+
+ /** The Constant KEY_1. */
+ protected static final String KEY_1 = "#{beanA.property1}"; //$NON-NLS-1$
+
+ /** The Constant elValuesMap. */
+ protected static final Map<String, String> elValuesMap = new HashMap<String,
String>();
+
+ /** The file. */
+ protected IFile file;
+
+ /**
+ * The Constructor.
+ *
+ * @param name the name
+ */
+ public CommonJBIDE2010Test(String name) {
+ super(name);
+
+ }
+
+ /**
+ * Sets the up.
+ *
+ * @throws Exception the exception
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ elValuesMap.put(KEY_1, "/path/image/path/to/image/"); //$NON-NLS-1$
+ elValuesMap.put(KEY_2, "/path2/"); //$NON-NLS-1$
+ elValuesMap.put(KEY_3, "/facesContext/"); //$NON-NLS-1$
+ elValuesMap.put(KEY_4, VALUE_4);
+ elValuesMap.put(KEY_5, VALUE_5);
+ file = (IFile) TestUtil.getComponentPath(getOpenPageName(),
getOpenProjectName());
+ ResourceReference[] entries = new ResourceReference[elValuesMap.size()];
+ int i = 0;
+ for (Entry<String, String> string : elValuesMap.entrySet()) {
+
+ entries[i] = new ResourceReference(string.getKey(),
ResourceReference.PROJECT_SCOPE);
+ entries[i].setProperties(string.getValue());
+ i++;
+
+
+ }
+ setValues(entries);
+ }
+
+
+ protected String getOpenPageName(){
+ return DIR_TEST_PAGE_NAME;
+ }
+
+ protected String getOpenProjectName(){
+ return IMPORT_PROJECT_NAME;
+ }
+ /**
+ * Sets the values.
+ *
+ * @param key the key
+ * @param value the value
+ * @param scope the scope
+ * @param entries the entries
+ */
+ protected void setValues(ResourceReference[] entries) {
+ ELReferenceList.getInstance().setAllResources(file, entries);
+ }
+
+ /**
+ * Tear down.
+ *
+ * @throws Exception the exception
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ ELReferenceList.getInstance().setAllResources(this.file, new
ResourceReference[0]);
+ this.file = null;
+
+ }
+
+}
Copied:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ElPreferencesTestCase.java
(from rev 9489,
trunk/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/test/ElPreferencesTestCase.java)
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ElPreferencesTestCase.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/ElPreferencesTestCase.java 2008-08-06
09:39:08 UTC (rev 9559)
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * 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.eclipse.core.runtime.CoreException;
+import org.jboss.tools.vpe.editor.util.ElService;
+
+/**
+ * <p>
+ * Test case for testing service {@link ElService}
+ * <p>
+ * See <a
href="http://jira.jboss.com/jira/browse/JBIDE-2010">JBIDE-20...
issue
+ *
+ */
+public class ElPreferencesTestCase extends CommonJBIDE2010Test {
+
+
+ /**
+ * The Constructor.
+ *
+ * @param name the name
+ */
+ public ElPreferencesTestCase(String name) {
+ super(name);
+
+ }
+
+ /**
+ * Test replace attribute value.
+ *
+ * @throws CoreException the core exception
+ */
+ public void testReplaceAttributeValue() throws CoreException {
+ String string1 = "#{beanA.property1}/images/smalle.gif"; //$NON-NLS-1$
+ String replacedValue = ElService.getInstance().replaceEl(file, string1);
+
+ assertEquals("Should be equals " + elValuesMap.get(KEY_1) +
"/images/smalle.gif", replacedValue, elValuesMap.get(KEY_1) //$NON-NLS-1$
//$NON-NLS-2$
+ + "/images/smalle.gif"); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Test replace attribute value2.
+ *
+ * @throws CoreException the core exception
+ */
+ public void testReplaceAttributeValue2() throws CoreException {
+ String string1 =
"#{beanA.property1}/images/#{beanA.property2}/path2/#{facesContext.requestPath}/smalle.gif";
//$NON-NLS-1$
+
+ final String replacedValue = ElService.getInstance().replaceEl(file, string1);
+ final String check = elValuesMap.get(KEY_1) + "/images/" +
elValuesMap.get(KEY_2) + "/path2/" + elValuesMap.get(KEY_3) //$NON-NLS-1$
//$NON-NLS-2$
+ + "/smalle.gif"; //$NON-NLS-1$
+ assertEquals("Should be equals " + check, check, replacedValue);
//$NON-NLS-1$
+
+ }
+
+ /**
+ * Test replace not in set.
+ */
+ public void testReplaceNotInSet() {
+ String string1 = "#{requestScope}/smalle.gif"; //$NON-NLS-1$
+
+ assertEquals("Should be equals", string1,
ElService.getInstance().replaceEl(file, string1)); //$NON-NLS-1$
+ }
+}
Copied:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/JBIDE2010Test.java
(from rev 9489,
trunk/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/test/JBIDE2010Test.java)
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/JBIDE2010Test.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/JBIDE2010Test.java 2008-08-06
09:39:08 UTC (rev 9559)
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+
+package org.jboss.tools.vpe.ui.test;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.jboss.tools.vpe.editor.util.HTML;
+import org.mozilla.interfaces.nsIDOMElement;
+import org.mozilla.interfaces.nsIDOMNode;
+
+
+/**
+ * Test case for testing
https://jira.jboss.com:8443/jira/browse/JBIDE-2010
+ * issue.
+ *
+ * @author Eugeny Stherbin
+ */
+public class JBIDE2010Test extends CommonJBIDE2010Test {
+
+
+ /**
+ * The Constructor.
+ *
+ * @param name the name
+ */
+ public JBIDE2010Test(String name) {
+ super(name);
+ }
+
+ /**
+ * Test el template simple.
+ *
+ * @throws CoreException the core exception
+ * @throws Throwable the throwable
+ */
+ public void testElTemplateSimple() throws CoreException, Throwable {
+ final nsIDOMElement rst = TestUtil.performTestForRichFacesComponent((IFile)
TestUtil.getComponentPath(DIR_TEST_PAGE_NAME_2,
+ IMPORT_PROJECT_NAME));
+
+ List<nsIDOMNode> elements = new ArrayList<nsIDOMNode>();
+
+ // find "td" elements
+
+ TestUtil.findAllElementsByName(rst, elements, HTML.TAG_SPAN);
+
+ assertEquals("Count of divs should be equals 1", 1, elements.size());
//$NON-NLS-1$
+ final nsIDOMElement spanOne = (nsIDOMElement)
elements.get(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+
+ assertEquals("Style attribute should be substituted", VALUE_4,
spanOne.getFirstChild().getNodeValue()); //$NON-NLS-1$
+
+ }
+
+
+ /**
+ * Test el template simple.
+ *
+ * @throws CoreException the core exception
+ * @throws Throwable the throwable
+ */
+ public void testElTemplateSimple2() throws CoreException, Throwable {
+ final nsIDOMElement rst = TestUtil.performTestForRichFacesComponent((IFile)
TestUtil.getComponentPath(DIR_TEST_PAGE_NAME_3,
+ IMPORT_PROJECT_NAME));
+
+ List<nsIDOMNode> elements = new ArrayList<nsIDOMNode>();
+
+ // find "td" elements
+
+ TestUtil.findAllElementsByName(rst, elements, HTML.TAG_P);
+
+ assertEquals("Value should be equals", 1, elements.size());
//$NON-NLS-1$
+ final nsIDOMElement pOne = (nsIDOMElement)
elements.get(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+ // DOMTreeDumper d = new DOMTreeDumper();
+ // d.dumpToStream(System.out, rst);
+// assertEquals("Value should be equals", "Hello "+VALUE_5,
pOne.getFirstChild().getFirstChild().getNodeValue());
+ assertTrue("Value should be
contains",pOne.getAttribute(HTML.ATTR_STYLE).startsWith(VALUE_4)); //$NON-NLS-1$
+
+ }
+
+}
Copied:
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/JBIDE2582Test.java
(from rev 9511,
trunk/vpe/tests/org.jboss.tools.vpe.test/src/org/jboss/tools/vpe/test/JBIDE2582Test.java)
===================================================================
---
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/JBIDE2582Test.java
(rev 0)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/JBIDE2582Test.java 2008-08-06
09:39:08 UTC (rev 9559)
@@ -0,0 +1,184 @@
+/*******************************************************************************
+ * 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.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.editor.mapping.VpeDomMapping;
+import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.vpe.editor.util.HTML;
+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.Node;
+
+
+/**
+ * Test case for testing <a
+ *
href="https://jira.jboss.org/jira/browse/JBIDE-2582"> JBIDE-2582
</a> issue
+ *
+ * @author Evgenij Stherbin
+ */
+public class JBIDE2582Test extends CommonJBIDE2010Test {
+
+ /** The Constant DIR_TEST_PAGE_NAME_3. */
+ protected static final String PAGE_1 = "JBIDE/2582/page1.xhtml";
//$NON-NLS-1$
+
+ /** The Constant DIR_TEST_PAGE_NAME_3. */
+ protected static final String PAGE_2 = "JBIDE/2582/page2.xhtml";
//$NON-NLS-1$
+
+ /**
+ * The Constructor.
+ *
+ * @param name the name
+ */
+ public JBIDE2582Test(String name) {
+ super(name);
+
+ }
+
+ /**
+ * Test rs substitution.
+ *
+ * @throws Throwable the throwable
+ */
+ public void _testRsSubstitution() throws Throwable {
+ final nsIDOMElement rst = TestUtil.performTestForRichFacesComponent(file);
+
+ assertNotNull(rst);
+
+ final List<nsIDOMNode> elements = new ArrayList<nsIDOMNode>();
+
+ TestUtil.findAllElementsByName(rst, elements, HTML.TAG_SPAN);
+
+ assertEquals("Size should be equals 1", 1, elements.size());
//$NON-NLS-1$
+
+ final nsIDOMElement spanOne = (nsIDOMElement)
elements.get(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+
+ assertEquals("Style attribute should be substituted",
"Hello", spanOne.getFirstChild().getNodeValue()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+
+ /**
+ * _test resource substitution in text.
+ *
+ * @throws CoreException the core exception
+ * @throws Throwable the throwable
+ */
+ public void _testResourceSubstitutionInText() throws CoreException, Throwable {
+ final nsIDOMElement rst = TestUtil.performTestForRichFacesComponent((IFile)
TestUtil.getComponentPath(PAGE_2, getOpenProjectName()));
+ final List<nsIDOMNode> elements = new ArrayList<nsIDOMNode>();
+ // DOMTreeDumper dumper = new DOMTreeDumper();
+ // dumper.dumpToStream(System.out, rst);
+ TestUtil.findAllElementsByName(rst, elements, "H3"); //$NON-NLS-1$
+ assertEquals("Size should be equals 1", 1, elements.size());
//$NON-NLS-1$
+
+ final nsIDOMElement h3one = (nsIDOMElement)
elements.get(0).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID);
+
+ assertEquals("Style attribute should be substituted",
"Hello", h3one.getFirstChild().getFirstChild().getNodeValue()); //$NON-NLS-1$
//$NON-NLS-2$
+
+ // There are the label:#{msg.header}f
+
+ TestUtil.findAllElementsByName(rst, elements, "SPAN"); //$NON-NLS-1$
+ assertEquals("Size should be equals 1", 4, elements.size());
//$NON-NLS-1$
+ final nsIDOMElement pOne = ((nsIDOMElement)
elements.get(2).queryInterface(nsIDOMElement.NS_IDOMELEMENT_IID));
+
+ assertEquals(
+ "Style attribute should be substituted", "There are the
label:Hello Demo Application", pOne.getFirstChild().getNodeValue()); //$NON-NLS-1$
//$NON-NLS-2$
+
+ }
+
+ /**
+ * Test selection with resource string.
+ *
+ * @throws CoreException the core exception
+ */
+ @SuppressWarnings("restriction")
+ public void testSelectionWithResourceString() throws CoreException {
+ IFile lfile = (IFile) TestUtil.getComponentPath(PAGE_2, getOpenProjectName());
+ IEditorInput input = new FileEditorInput(lfile);
+ // open and get editor
+ JSPMultiPageEditor part = openEditor(input);
+
+ // get controller
+ VpeController controller = 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 xulrunner editor
+ XulRunnerEditor xulRunnerEditor = controller.getXulRunnerEditor();
+ assertNotNull(xulRunnerEditor);
+
+ int start =
controller.getPageContext().getSourceBuilder().getStructuredTextViewer().getTextWidget().getText().indexOf(
+ "#{msg.hello_message}"); //$NON-NLS-1$
+
+ assertTrue("Should be gt that 100", start > 100); //$NON-NLS-1$
+
+ IStructuredModel model;
+ model = StructuredModelManager.getModelManager()
+
.getExistingModelForRead(controller.getSourceEditor().getTextViewer().getDocument());
+ IDOMDocument document = null;
+ document = ((IDOMModel) model).getDocument();
+ ;
+ org.w3c.dom.NodeList nodeList =
document.getElementsByTagName("h:outputText"); //$NON-NLS-1$
+
+ assertNotNull("Can't be null", nodeList); //$NON-NLS-1$
+ assertTrue("Size should be great that 0", nodeList.getLength() > 0);
//$NON-NLS-1$
+
+ final Node elementNode = nodeList.item(0);
+
+ SelectionUtil.setSourceSelection(controller.getPageContext(), elementNode, 0,
0);
+
+ nsIDOMNode node =
SelectionUtil.getLastSelectedNode(controller.getPageContext());
+
+ assertEquals("Node names should be equals", "Hello",
node.getFirstChild().getNodeValue()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ }
+
+ /**
+ * Gets the open page name.
+ *
+ * @return the open page name
+ */
+ protected String getOpenPageName() {
+ return PAGE_1;
+ }
+
+}
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-08-06
09:38:59 UTC (rev 9558)
+++
trunk/vpe/tests/org.jboss.tools.vpe.ui.test/src/org/jboss/tools/vpe/ui/test/TestUtil.java 2008-08-06
09:39:08 UTC (rev 9559)
@@ -15,6 +15,9 @@
import java.util.ArrayList;
import java.util.List;
+import junit.framework.Assert;
+
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -22,35 +25,52 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.IOverwriteQuery;
+import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.wizards.datatransfer.ImportOperation;
import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
-import org.jboss.tools.vpe.editor.mapping.VpeNodeMapping;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+import org.jboss.tools.vpe.editor.VpeController;
+import org.jboss.tools.vpe.editor.VpeEditorPart;
import org.jboss.tools.vpe.ui.test.beans.ImportBean;
+import org.jboss.tools.vpe.xulrunner.editor.XulRunnerEditor;
+import org.mozilla.interfaces.nsIDOMDocument;
+import org.mozilla.interfaces.nsIDOMElement;
import org.mozilla.interfaces.nsIDOMNode;
import org.mozilla.interfaces.nsIDOMNodeList;
import org.mozilla.xpcom.XPCOMException;
import org.w3c.dom.Node;
/**
- * Class for importing project from jar file
+ * Class for importing project from jar file.
*
* @author sdzmitrovich
- *
*/
public class TestUtil {
+ /** The Constant COMPONENTS_PATH. */
private static final String COMPONENTS_PATH = "WebContent/pages";
//$NON-NLS-1$
+ /** The Constant WEBCONTENT_PATH. */
private static final String WEBCONTENT_PATH = "WebContent"; //$NON-NLS-1$
+
+ /** Editor in which we open visual page. */
+ protected final static String EDITOR_ID =
"org.jboss.tools.jst.jsp.jspeditor.JSPTextEditor"; //$NON-NLS-1$
+ /** The Constant MAX_IDLE. */
private static final long MAX_IDLE = 30*60*1000L;
+ /**
+ * Import project into workspace.
+ *
+ * @param path the path
+ * @param projectName the project name
+ */
static void importProjectIntoWorkspace(String path, String projectName) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
@@ -93,9 +113,14 @@
}
/**
+ * Gets the component path.
*
- * @return
- * @throws CoreException
+ * @param componentPage the component page
+ * @param projectName the project name
+ *
+ * @return the component path
+ *
+ * @throws CoreException the core exception
*/
public static IResource getComponentPath(String componentPage,
String projectName) throws CoreException {
@@ -110,9 +135,14 @@
}
/**
+ * Gets the web content path.
*
- * @return
- * @throws CoreException
+ * @param componentPage the component page
+ * @param projectName the project name
+ *
+ * @return the web content path
+ *
+ * @throws CoreException the core exception
*/
public static IResource getWebContentPath(String componentPage,
String projectName) throws CoreException {
@@ -126,8 +156,11 @@
}
/**
+ * Removes the project.
*
- * @throws CoreException
+ * @param projectName the project name
+ *
+ * @throws CoreException the core exception
*/
static void removeProject(String projectName) throws CoreException {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(
@@ -141,8 +174,7 @@
/**
* Process UI input but do not return for the specified time interval.
*
- * @param waitTimeMillis
- * the number of milliseconds
+ * @param waitTimeMillis the number of milliseconds
*/
public static void delay(long waitTimeMillis) {
Display display = Display.getCurrent();
@@ -172,6 +204,9 @@
delay(100);
}
+ /**
+ * Wait for idle.
+ */
public static void waitForIdle() {
long start = System.currentTimeMillis();
while (!Job.getJobManager().isIdle()) {
@@ -182,14 +217,14 @@
}
/**
- * find elements by name
+ * find elements by name.
*
* @param node -
- * current node
+ * current node
+ * @param name -
+ * name element
* @param elements -
- * list of found elements
- * @param name -
- * name element
+ * list of found elements
*/
static public void findElementsByName(nsIDOMNode node,
List<nsIDOMNode> elements, String name) {
@@ -214,14 +249,14 @@
}
/**
- * find all elements by name
+ * find all elements by name.
*
* @param node -
- * current node
+ * current node
+ * @param name -
+ * name element
* @param elements -
- * list of found elements
- * @param name -
- * name element
+ * list of found elements
*/
static public void findAllElementsByName(nsIDOMNode node,
List<nsIDOMNode> elements, String name) {
@@ -240,6 +275,14 @@
}
}
+ /**
+ * Creates the import bean list.
+ *
+ * @param projectName the project name
+ * @param resourcePath the resource path
+ *
+ * @return the list< import bean>
+ */
static public List<ImportBean> createImportBeanList(String projectName,
String resourcePath) {
List<ImportBean> projectToImport = new ArrayList<ImportBean>();
@@ -247,6 +290,14 @@
return projectToImport;
}
+ /**
+ * Creates the import bean.
+ *
+ * @param projectName the project name
+ * @param resourcePath the resource path
+ *
+ * @return the import bean
+ */
static public ImportBean createImportBean(String projectName,
String resourcePath) {
ImportBean importBean = new ImportBean();
@@ -254,27 +305,33 @@
importBean.setImportProjectPath(resourcePath);
return importBean;
}
+
/**
- * Utility function which returns node mapping by source position(line and position in
line)
- * @param lineIndex
- * @param linePosition
+ * Utility function which returns node mapping by source position(line and position in
line).
+ *
+ * @param linePosition the line position
+ * @param lineIndex the line index
+ * @param itextViewer the itext viewer
+ *
* @return node for specified src position
*/
- public static Node getNodeMappingBySourcePosition(ITextViewer itextViewer, int
lineIndex, int linePosition) {
+ @SuppressWarnings("restriction")
+ public static Node getNodeMappingBySourcePosition(ITextViewer itextViewer, int
lineIndex, int linePosition) {
int offset = getLinePositionOffcet(itextViewer, lineIndex, linePosition);
IndexedRegion treeNode = ContentAssistUtils.getNodeAt(itextViewer, offset);
return (Node) treeNode;
}
/**
- * Utility function which is used to calculate offcet in document by line number and
character position
+ * Utility function which is used to calculate offcet in document by line number and
character position.
*
- * @param textViewer
- * @param lineIndex
- * @param linePosition
+ * @param linePosition the line position
+ * @param textViewer the text viewer
+ * @param lineIndex the line index
+ *
* @return offcet in document
- * @throws IllegalArgumentException
- */
+ *
+ * @throws IllegalArgumentException */
public static final int getLinePositionOffcet(ITextViewer textViewer, int lineIndex, int
linePosition) {
int resultOffcet = 0;
@@ -308,4 +365,66 @@
}
return resultOffcet;
}
+
+
+ /**
+ * get xulrunner source page.
+ *
+ * @param part - JSPMultiPageEditor
+ *
+ * @return nsIDOMDocument
+ */
+ public static nsIDOMDocument getVpeVisualDocument(JSPMultiPageEditor part) {
+
+ VpeEditorPart visualEditor = (VpeEditorPart) part.getVisualEditor();
+
+ VpeController vpeController = visualEditor.getController();
+
+ // get xulRunner editor
+ XulRunnerEditor xulRunnerEditor = vpeController.getXulRunnerEditor();
+
+ // get dom document
+ nsIDOMDocument document = xulRunnerEditor.getDOMDocument();
+
+ return document;
+ }
+
+ /**
+ * Perform test for rich faces component.
+ *
+ * @param componentPage the component page
+ *
+ * @return the ns IDOM element
+ *
+ * @throws Throwable the throwable
+ */
+ public static nsIDOMElement performTestForRichFacesComponent(IFile componentPage)
throws Throwable {
+ nsIDOMElement rst = null;
+ TestUtil.waitForJobs();
+
+ // IFile file = (IFile)
+ // TestUtil.getComponentPath(componentPage,getImportProjectName());
+ IEditorInput input = new FileEditorInput(componentPage);
+
+ TestUtil.waitForJobs();
+ //
+ JSPMultiPageEditor editor = (JSPMultiPageEditor)
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(
+ input, EDITOR_ID, true);
+
+ // get dom document
+ nsIDOMDocument document = getVpeVisualDocument(editor);
+ rst = document.getDocumentElement();
+ // check that element is not null
+ Assert.assertNotNull(rst);
+ return rst;
+ }
+
+ /**
+ * Fail.
+ *
+ * @param t the t
+ */
+ public static void fail(Throwable t){
+ Assert.fail("Test case was fail "+t.getMessage()+":"+t);
+ }
}