Author: sdzmitrovich
Date: 2008-01-04 09:43:36 -0500 (Fri, 04 Jan 2008)
New Revision: 5514
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfJbideTest.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1501
was added junit
Modified:
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfJbideTest.java
===================================================================
---
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfJbideTest.java 2008-01-04
14:40:22 UTC (rev 5513)
+++
trunk/jsf/tests/org.jboss.tools.jsf.vpe.jsf.test/src/org/jboss/tools/jsf/vpe/jsf/test/JsfJbideTest.java 2008-01-04
14:43:36 UTC (rev 5514)
@@ -1,13 +1,14 @@
-/*******************************************************************************
- * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
+/*******************************************************************************
+ * 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:
- * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ * Red Hat, Inc. - initial API and implementation
******************************************************************************/
+
package org.jboss.tools.jsf.vpe.jsf.test;
import java.util.ArrayList;
@@ -46,10 +47,9 @@
// type of input tag
private static final String ATTR_TYPE_VALUE = "radio";
- // $NON-NLS-1$
-
// check warning log
private final static boolean checkWarning = false;
+
private Throwable exception;
public JsfJbideTest(String name) {
@@ -65,13 +65,12 @@
*/
protected void setUp() throws Exception {
+
super.setUp();
Platform.addLogListener(this);
- TestJsfUtil.waitForJobs();
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
- .closeAllEditors(true);
+ closeEditors();
}
/**
@@ -82,13 +81,12 @@
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
+
super.tearDown();
+
Platform.removeLogListener(this);
- TestJsfUtil.waitForJobs();
-
- PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
- .closeAllEditors(true);
+ closeEditors();
}
/*
@@ -98,42 +96,33 @@
/**
* test for
http://jira.jboss.com/jira/browse/JBIDE-1467
*
- * REQUIREMENT :test page must have only one <h:selectOneRadio > tag
+ * the cause of bug : <input type=radio > tags ( which vpe template forms
+ * when process "selectOneRadio" jsf tag ) didn't have equal
"name"
+ * attribute
*
- * test check that all "radio" elements ( of xulRunner DOMDocument ) have
+ * REQUIREMENT :test page must has only one <h:selectOneRadio > tag
+ *
+ * test checks that all "radio" elements ( of xulRunner DOMDocument ) have
* equal "name" attributes
*/
public void testJBIDE_1467() throws PartInitException, Throwable {
- // path to test page
- String path = "JBIDE/JBIDE-1467.jsp";
+
// wait
TestJsfUtil.waitForJobs();
// set exception
exception = null;
// get test page path
- IFile file = (IFile) TestJsfUtil.getComponentPath(path);
+ IFile file = (IFile) TestJsfUtil
+ .getComponentPath("JBIDE/1467/JBIDE-1467.jsp");
IEditorInput input = new FileEditorInput(file);
- // get editor
- JSPMultiPageEditor part = (JSPMultiPageEditor) PlatformUI
- .getWorkbench().getActiveWorkbenchWindow().getActivePage()
- .openEditor(input, EDITOR_ID, true);
+ // open and get editor
+ JSPMultiPageEditor part = openEditor(input);
- // wait for jobs
- TestJsfUtil.waitForJobs();
- // wait full initialization of vpe
- TestJsfUtil.delay(3000);
-
- VpeEditorPart visualEditor = (VpeEditorPart) part.getVisualEditor();
- VpeController vpeController = visualEditor.getController();
-
- // get xulRunner editor
- XulRunnerEditor xulRunnerEditor = vpeController.getXulRunnerEditor();
-
// get dom document
- nsIDOMDocument document = xulRunnerEditor.getDOMDocument();
+ nsIDOMDocument document = getVpePageSource(part);
nsIDOMElement element = document.getDocumentElement();
if (element != null) {
@@ -149,7 +138,7 @@
// check that "radio" elements have equal names
// (size of list of names == 1 )
- assertEquals(getRadioNames(elements).size(), 1);
+ assertEquals(1, getRadioNames(elements).size());
}
@@ -161,6 +150,131 @@
}
/**
+ * test for
http://jira.jboss.com/jira/browse/JBIDE-1467
+ *
+ * the cause of bug :
+ *
+ * 1. <select ... > tag ( which vpe template forms when process
+ * "selectManyMenu" and "selectManyListbox" jsf tags ) didn't
have
+ * multiple="multiple" attribute
+ *
+ * 2. <select ... > tag ( which vpe template forms when process
+ * "selectOneListbox" and "selectManyListbox" jsf tags ) sometimes
had
+ * incorrect "size" attribute
+ *
+ * DISCRIPTION: test consist of two part
+ *
+ * 1. The first page (JBIDE-1501_multiple.jsp) has "selectManyMenu" and
+ * "selectManyListbox" jsf tags. And test checks that all "select"
elements
+ * have "multiple" attribute
+ *
+ * 2. The second page (JBIDE-1501_size.jsp) has "selectOneListbox" and
+ * "selectManyListbox" jsf tags and they was formed so that all
"select"
+ * elements must have size="2" attribute . And test checks "size"
attribute
+ */
+ public void testJBIDE_1501() throws PartInitException, Throwable {
+
+ // wait
+ TestJsfUtil.waitForJobs();
+ // set exception
+ exception = null;
+
+ // _____1st Part____//
+
+ // get test page path
+ IFile file = (IFile) TestJsfUtil
+ .getComponentPath("JBIDE/1501/JBIDE-1501_multiple.jsp");
+
+ IEditorInput input = new FileEditorInput(file);
+
+ // open and get editor
+ JSPMultiPageEditor part = openEditor(input);
+
+ // get dom document
+ nsIDOMDocument document = getVpePageSource(part);
+ assertNotNull(document);
+
+ // get dom element
+ nsIDOMElement element = document.getDocumentElement();
+ assertNotNull(element);
+
+ // get root node
+ nsIDOMNode node = (nsIDOMNode) element
+ .queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+
+ List<nsIDOMNode> elements = new ArrayList<nsIDOMNode>();
+
+ // find "select" elements
+ findElementsByName(node, elements, HTML.TAG_SELECT);
+
+ System.out.print("\n1:" + elements.size());
+ for (nsIDOMNode select : elements) {
+
+ // get attributes
+ nsIDOMNamedNodeMap attributes = select.getAttributes();
+
+ // "select" must have attributes
+ assertNotNull(attributes);
+
+ // select must have "multiple" attribute
+ assertNotNull(attributes.getNamedItem(HTML.ATTR_MULTIPLE));
+
+ }
+
+ // _____2nd Part____//
+
+ // get test page path
+ file = (IFile) TestJsfUtil
+ .getComponentPath("JBIDE/1501/JBIDE-1501_size.jsp");
+
+ input = new FileEditorInput(file);
+
+ // open and get editor
+ part = openEditor(input);
+
+ // get dom document
+ document = getVpePageSource(part);
+ assertNotNull(document);
+
+ // get dom element
+ element = document.getDocumentElement();
+ assertNotNull(element);
+
+ // get root node
+ node = (nsIDOMNode) element.queryInterface(nsIDOMNode.NS_IDOMNODE_IID);
+
+ elements = new ArrayList<nsIDOMNode>();
+
+ // find "select" elements
+ findElementsByName(node, elements, HTML.TAG_SELECT);
+
+ System.out.print("\n2:" + elements.size());
+
+ for (nsIDOMNode select : elements) {
+
+ // get attributes
+ nsIDOMNamedNodeMap attributes = select.getAttributes();
+
+ // "select" must have attributes
+ assertNotNull(attributes);
+
+ // select must have "size" attribute
+ nsIDOMNode size = attributes.getNamedItem(HTML.ATTR_SIZE);
+ assertNotNull(size);
+
+ //
+ assertEquals(2, Integer.parseInt(size.getNodeValue()));
+
+ }
+
+ // check exception
+ if (exception != null) {
+ throw exception;
+ }
+
+ }
+
+ /**
* find elements by name
*
* @param node -
@@ -170,7 +284,7 @@
* @param name -
* name element
*/
- void findElementsByName(nsIDOMNode node, List<nsIDOMNode> elements,
+ private void findElementsByName(nsIDOMNode node, List<nsIDOMNode> elements,
String name) {
// get children
@@ -182,15 +296,22 @@
if (name.equalsIgnoreCase((child.getNodeName()))) {
elements.add(child);
- return;
+
+ } else {
+
+ findElementsByName(child, elements, name);
+
}
- // if current child is not required
- findElementsByName(child, elements, name);
-
}
}
+ /**
+ *
+ * @param elements
+ * list of "input" elements
+ * @return list of names
+ */
private List<String> getRadioNames(List<nsIDOMNode> elements) {
// list of "name" of "radio" elements
@@ -200,12 +321,12 @@
// attributes
nsIDOMNamedNodeMap attributes = element.getAttributes();
- if (null != attributes) {
+ if (attributes != null) {
// get type of element
nsIDOMNode type = attributes.getNamedItem(HTML.ATTR_TYPE);
// if type is "radio"
- if ((null != type)
+ if ((type != null)
&& (ATTR_TYPE_VALUE.equalsIgnoreCase(type
.getNodeValue()))) {
@@ -227,6 +348,65 @@
}
+ /**
+ * close all opened editors
+ */
+ private void closeEditors() {
+
+ // wait
+ TestJsfUtil.waitForJobs();
+
+ // close
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .closeAllEditors(true);
+
+ }
+
+ /**
+ * Open JSPMultiPageEditor editor
+ *
+ * @param input
+ * @return
+ * @throws PartInitException
+ */
+ private JSPMultiPageEditor openEditor(IEditorInput input)
+ throws PartInitException {
+
+ // get editor
+ JSPMultiPageEditor part = (JSPMultiPageEditor) PlatformUI
+ .getWorkbench().getActiveWorkbenchWindow().getActivePage()
+ .openEditor(input, EDITOR_ID, true);
+
+ // wait for jobs
+ TestJsfUtil.waitForJobs();
+ // wait full initialization of vpe
+ TestJsfUtil.delay(3000);
+
+ return part;
+
+ }
+
+ /**
+ * get xulrunner source page
+ *
+ * @param part -
+ * JSPMultiPageEditor
+ * @return nsIDOMDocument
+ */
+ private nsIDOMDocument getVpePageSource(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;
+ }
+
public void logging(IStatus status, String plugin) {
switch (status.getSeverity()) {
case IStatus.ERROR: