Author: ozizka(a)redhat.com
Date: 2009-03-13 12:03:15 -0400 (Fri, 13 Mar 2009)
New Revision: 218
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
Toolkit update
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-03-13
15:53:07 UTC (rev 217)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java 2009-03-13
16:03:15 UTC (rev 218)
@@ -40,6 +40,7 @@
import org.jboss.profileservice.spi.NoSuchDeploymentException;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import org.apache.commons.lang.StringUtils;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.managed.api.*;
import org.jboss.metatype.api.values.MetaValue;
@@ -267,7 +268,65 @@
setFormInput(input, properties.get(propertyName));
}
}
-
+
+ /** Convert Properties to Map and call fillOutForm(Map). */
+ public void fillOutForm(Properties props) {
+ Map<String,String> map = new HashMap<String,String>(props.size());
+ for( String propName : props.stringPropertyNames() ) {
+ map.put(propName, props.getProperty(propName));
+ }
+ fillOutForm(map);
+ }
+
+ /** Check if the form is filled according to given Properties. */
+ public void checkForm(Properties props)
+ {
+ boolean foundNonMatching = false;
+ StringBuilder sb = new StringBuilder("Non-matching properties: \n");
+
+ for( String propName : props.stringPropertyNames() ) {
+ HtmlInput input = getConfigFormInput(propName);
+ String expected = props.getProperty(propName);
+ String actual = getFormInputValueAsText(input);
+ if( StringUtils.equals(expected, actual) ) continue;
+ foundNonMatching = true;
+ sb.append( propName+": expected '"+expected+"', found
'"+actual+"'\n");
+ }
+ if( foundNonMatching ){
+ fail( sb.toString() );
+ }
+ }
+
+ /** Looks for a form input of given property. */
+ public HtmlInput getConfigFormInput( String propertyName )
+ {
+ HtmlForm form = (HtmlForm)client.getElement("resourceConfigurationForm");
+ HtmlInput input =
(HtmlInput)form.getFirstByXPath(".//input[@ondblclick='//"
+ + propertyName + "']");
+
+ assertNotNull("Form input for property '"+ propertyName +"' not
found.", input);
+ return input;
+ }
+
+ /** Looks for an enable/disable checkbox corresponding to this input element. */
+ public HtmlCheckBoxInput getCheckBoxForInput( HtmlInput input ){
+ boolean isRadioButton = input.getTypeAttribute().equals("radio");
+ String id = input.getId();
+ String xpath;
+ if(isRadioButton) {
+ xpath =
".//input[(a)onchange=\"setInputUnset(document.getElementById('"+ id
+ + "'), this.checked);setInputUnset(document.getElementById('"
+ + id.substring(0, id.lastIndexOf(":")) + ":1'),
this.checked);\"]";
+ } else {
+ xpath =
".//input[(a)onchange=\"setInputUnset(document.getElementById('"
+ + id + "'), this.checked);\"]";
+ }
+
+ HtmlCheckBoxInput checkBox =
(HtmlCheckBoxInput)input.getEnclosingForm().getFirstByXPath(xpath);
+ return (HtmlCheckBoxInput) checkBox;
+ }
+
+
/**
* Attempt to enable or disable the given input box or "Yes/No" radio
button
* that corresponds to the given property name on a resource configuration
@@ -350,6 +409,43 @@
/**
+ * Returns the value of HTML input.
+ * @returns
+ * If the input is marked as unset, returns "unset".
+ * For radios, returns the value of the checked radio.
+ * For others, simply returns value attribute.
+ */
+ public String getFormInputValueAsText(HtmlInput input) {
+
+ HtmlCheckBoxInput checkbox = getCheckBoxForInput(input);
+ if( checkbox.isChecked() )
+ return "unset";
+
+ boolean isRadioButton = input.getTypeAttribute().equals("radio");
+ if(!isRadioButton){
+ return input.getValueAttribute();
+ }
+ else {
+
+ HtmlRadioButtonInput radio = (HtmlRadioButtonInput)input;
+
+ // Multiple choices - find the appropriate radio button.
+ String inputName = input.getNameAttribute();
+ String xPath = ".//input[@name='"+ inputName +"']";
+ List<HtmlInput> radios = (List<HtmlInput>)
input.getEnclosingForm().getByXPath(xPath);
+
+ for (HtmlInput htmlInput : radios) {
+ if( htmlInput.isChecked() ){
+ return htmlInput.getValueAttribute();
+ }
+ }
+ return null;
+
+ }
+ }
+
+
+ /**
* Check that the given messages occur on the client side and server side.
*/
public void checkClientAndServerMessages(String expectedClientMsg,
@@ -675,7 +771,7 @@
actualProperties.get(propertyName));
}
}
-
+
/**
* Create a map of property names to property values for a particular
* component.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-13
15:53:07 UTC (rev 217)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-03-13
16:03:15 UTC (rev 218)
@@ -69,10 +69,17 @@
+
+ public String getTestDataDir() {
+ return System.getProperty(AppConstants.SYSPROP_TESTDATA_DIR);
+ }
+
+
+
/**
* Reloads the current page.
*/
- private void refreshPage() throws IOException {
+ public void refreshPage() throws IOException {
((HtmlPage)client.getContentPage()).refresh();
}
@@ -290,7 +297,7 @@
return new TabContentBox(tabContentBox);
}
- public ClickableElement getTab( String label ) throws HtmlElementNotFoundException {
+ public ClickableElement getTabByLabel( String label ) throws
HtmlElementNotFoundException {
DomElement element = (DomElement)client.getElement("tabmenu");
String xPath =
"ul/li/span[normalize-space(string())='"+label+"'] |
ul/li/a[normalize-space(string())='"+label+"']";
@@ -304,17 +311,31 @@
}
+ public ClickableElement getTabByID( String tabID ) throws HtmlElementNotFoundException
{
+ ClickableElement element = (ClickableElement)client.getElement(tabID);
+ if( null == element )
+ throw new HtmlElementNotFoundException("Tab with id
'"+tabID+"' not found, perhaps disabled?");
+
+ return element;
+ }
+
+ public void clickSummaryTab() throws HtmlElementNotFoundException, IOException{
getTabByID("summaryTab").click(); }
+ public void clickConfigurationTab() throws HtmlElementNotFoundException, IOException{
getTabByID("configurationTab").click(); }
+ public void clickMetricsTab() throws HtmlElementNotFoundException, IOException{
getTabByID("metricsTab").click(); }
+ public void clickControlTab() throws HtmlElementNotFoundException, IOException{
getTabByID("controlTab").click(); }
+ public void clickContentTab() throws HtmlElementNotFoundException, IOException{
getTabByID("contentTab").click(); }
+
/** Returns true if the tab with given label is active (it's content is shown). */
public boolean isTabActive( String label ) throws IOException,
HtmlElementNotFoundException {
- StyledElement tabContent = getTab(label);
+ StyledElement tabContent = getTabByLabel(label);
return "span".equals( tabContent.getTagName() )
&& tabContent.getClassAttribute().contains("active");
}
/** Returns true if the tab with given label is disabled (grayed and can't be
activated). */
public boolean isTabDisabled( String label ) throws HtmlElementNotFoundException {
- StyledElement tabContent = getTab(label);
+ StyledElement tabContent = getTabByLabel(label);
return "span".equals( tabContent.getTagName() )
&& tabContent.getClassAttribute().contains("disabled");
}
@@ -322,7 +343,7 @@
/** Shotcut - getTab(label).click(); Not necesarilly clicks an anchor. */
public void clickTab( String label ) throws IOException, ActionNotAvailableException,
HtmlElementNotFoundException {
- StyledElement tabContent = getTab(label);
+ StyledElement tabContent = getTabByLabel(label);
if( !( tabContent instanceof ClickableElement ) )
throw new ActionNotAvailableException("Tab element
<"+tabContent.getTagName()+"> is not clickable: "+label);
@@ -1014,6 +1035,29 @@
}
+ /**
+ * Finds element by ID and returns retyped as HTML button.
+ */
+ public HtmlButtonInput getButtonByID( String id ) throws HtmlElementNotFoundException {
+ HtmlButtonInput button = (HtmlButtonInput) client.getElement( id );
+ if( null == button )
+ throw new HtmlElementNotFoundException("Can't find button with ID:
"+button);
+ return button;
+ }
+
+
+ /** Converts java.util.Properties to java.util.Map. */
+ public static Map<String,String> propertiesAsMap( Properties props )
+ {
+ Map<String,String> map = new HashMap<String,String>(props.size());
+ for( String propName : props.stringPropertyNames() ) {
+ map.put(propName, props.getProperty(propName));
+ }
+ return map;
+ }
+
+
+
// TODO
protected class JMXDeploymentInfo {