Author: ozizka(a)redhat.com
Date: 2009-03-10 19:04:57 -0400 (Tue, 10 Mar 2009)
New Revision: 201
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ActiveConditionChecker.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/Condition.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/DescribedCondition.java
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
Log:
util package created, ActiveConditionChecker moved there
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-03-10
20:08:00 UTC (rev 200)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-03-10
23:04:57 UTC (rev 201)
@@ -28,31 +28,49 @@
public static final String SYSPROP_TESTDATA_DIR = "jsfunit.testdata";
+ /**
+ * Information about deployable types -
+ * navigation tree labels, archive extensions, and XML descriptor suffixes.
+ */
public enum DeployableTypes {
- EAR(AppConstants.NAV_EAR),
- WAR(AppConstants.NAV_WAR),
- EJB(AppConstants.NAV_EJB),
- SAR(AppConstants.NAV_SAR),
- RAR(AppConstants.NAV_RAR),
- MC_BEAN(AppConstants.NAV_MC);
+ EAR(AppConstants.NAV_EAR, ".ear", null),
+ WAR(AppConstants.NAV_WAR, ".war", null),
+ EJB(AppConstants.NAV_EJB, ".jar", null),
+ SAR(AppConstants.NAV_SAR, ".sar", "-service.xml"),
+ RAR(AppConstants.NAV_RAR, ".rar", null),
+ MC_BEAN(AppConstants.NAV_MC, "", null);
protected final String navTreeLabel;
public String getNavTreeLabel() { return navTreeLabel; }
- DeployableTypes( String navTreeLabel ){
+ protected final String extension;
+ public String getExtension() { return extension; }
+
+ protected final String suffix;
+ public String getSuffix() { return suffix; }
+
+
+ private DeployableTypes(String navTreeLabel, String extension, String suffix) {
this.navTreeLabel = navTreeLabel;
+ this.extension = extension;
+ this.suffix = suffix;
}
- }
+ }// enum DeployableTypes
+
+
public enum DeploymentMeans {
VIA_EMBJOPR,
VIA_FILESYSTEM,
VIA_JMX
}
+
+
// Navigation
+ public static final String NAV_APPLICATIONS = "Applications";
public static final String NAV_EJB = "EJB Application (EJB JAR)s";
public static final String NAV_EAR = "Enterprise Application (EAR)s";
public static final String NAV_SAR = "JBoss Service (SAR)s";
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-10
20:08:00 UTC (rev 200)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java 2009-03-10
23:04:57 UTC (rev 201)
@@ -33,10 +33,12 @@
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.math.NumberUtils;
import org.w3c.dom.Element;
@@ -221,6 +223,13 @@
}
+ public void waitForNavTreeLoaded(){
+ sleep(1500);///
+ // TODO: Use ActiveConditionChecker
+
+ }
+
+
/**
* Finds the nav tree node by it's link label.
*
@@ -480,7 +489,23 @@
return new ContentTable(tableElement);
}
+ /**
+ * Returns first table in the content box.
+ * @param headerText
+ * @return
+ * @throws org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException
+ */
+ public ContentTable getFirstTable() throws ActionOutOfSyncException
+ {
+ checkIfStillValid();
+ String xPath = ".//form//table[contains( normalize-space(@id),
':dataTable'))]";
+ // [@id='resourceSummaryForm:dataTable'] - is this reliable?
+ HtmlTable tableElement = (HtmlTable) element.getFirstByXPath(xPath);
+ return new ContentTable(tableElement);
+ }
+
+
/**
* Finds first button with given label inside this box.
* @param label
@@ -597,6 +622,19 @@
return new ContentTableRow(elm, this);
}
+ public List<ContentTableRow> getRows(){
+ if( 0 == element.getRowCount() )
+ return Collections.EMPTY_LIST;
+
+ String xPath = "./tbody/tr";
+ List<HtmlTableRow> trList = (List) element.getByXPath(xPath);
+ List<ContentTableRow> rows = new ArrayList(trList.size());
+ for (HtmlTableRow tr : trList) {
+ rows.add( new ContentTableRow(tr, this));
+ }
+ return rows;
+ }
+
/**
* Returns wrapper of the table row which contains a link with given label.
* @throws org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException
@@ -825,17 +863,19 @@
+
/**
* Pagination control
* Not tested yet.
*/
- protected class ContentBoxPagination {
+ public class ContentBoxPagination {
//private HtmlElement element;
//public HtmlElement getElement() { return element; }
private static final String ID_PAGE_CONTROLS =
"categorySummaryForm:dataTableScroller";
private static final String ID_PAGE_SIZE_SELECT =
"categorySummaryForm:currentPageSize";
+ private static final String ID_PAGINATION_TOTAL_ITEMS =
"paginationTotalItems";
protected HtmlDivision getPageContols(){
return (HtmlDivision) client.getElement(ID_PAGE_CONTROLS);
@@ -845,6 +885,18 @@
return (HtmlSelect) client.getElement(ID_PAGE_SIZE_SELECT);
}
+ public int getTotalItemsCount() throws ActionNotAvailableException {
+ Element e = client.getElement(ID_PAGINATION_TOTAL_ITEMS);
+ String textContent = e.getTextContent();
+ String[] parts = textContent.split(":");
+ if( parts.length < 2 )
+ throw new ActionNotAvailableException("Total pagination items count expected
after 'Total:' or similar.");
+ try{
+ return NumberUtils.createInteger(parts[1]);
+ }catch(NumberFormatException ex ){
+ throw new ActionNotAvailableException("Can't parse pagination items count
from '"+parts[1]+"'", ex);
+ }
+ }
protected HtmlSpan getGoSpan( String spanLabel ){
String xPath = ".//span[normalize-string() =
'"+spanLabel+"']";
@@ -861,20 +913,28 @@
}
- public void goFirst() throws IOException{
- getGoSpan("First").click();
+ public boolean goFirst() throws IOException{
+ HtmlSpan goSpan = getGoSpan("First");
+ goSpan.click();
+ return !"".equals(
((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
}
- public void goPrev() throws IOException{
- getGoSpan("Prev").click();
+ public boolean goPrev() throws IOException{
+ HtmlSpan goSpan = getGoSpan("Prev");
+ goSpan.click();
+ return !"".equals(
((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
}
- public void goNext() throws IOException{
- getGoSpan("Next").click();
+ public boolean goNext() throws IOException{
+ HtmlSpan goSpan = getGoSpan("Next");
+ goSpan.click();
+ return !"".equals(
((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
}
- public void goLast() throws IOException{
- getGoSpan("Last").click();
+ public boolean goLast() throws IOException{
+ HtmlSpan goSpan = getGoSpan("Last");
+ goSpan.click();
+ return !"".equals(
((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
}
public void goPage( int pageNumber ) throws IOException, HtmlElementNotFoundException{
@@ -892,7 +952,16 @@
return elements.size();
}
- public void setItemsPerPage( int num ) throws HtmlElementNotFoundException{
+ public int getItemsPerPage() throws HtmlElementNotFoundException,
ActionNotAvailableException {
+ String selectText = getPageSizeSelect().asText();
+ try {
+ return NumberUtils.createInteger( selectText );
+ }
+ catch( NumberFormatException ex ){
+ throw new ActionNotAvailableException("Can't parse 'items per page'
from '"+selectText+"'.", ex);
+ }
+ }
+ public void setItemsPerPage( int num ) throws HtmlElementNotFoundException {
String optionValue = ""+num;
HtmlSelect pageSizeSelect = getPageSizeSelect();
@@ -918,8 +987,18 @@
+ /** Calls Thread.sleep(ms), ignores the InterruptedException. */
+ @SuppressWarnings("empty-statement")
+ public static void sleep( int ms ) {
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException ex) {
+ ; // We don't care, that's the purpose of this method.
+ }
+ }
+
// TODO
protected class JMXDeploymentInfo {
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java 2009-03-10 20:08:00
UTC (rev 200)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java 2009-03-10 23:04:57
UTC (rev 201)
@@ -35,17 +35,21 @@
public static void writeFile( String sFilePath, String content ) throws
FileNotFoundException, IOException{
-
// TODO: Do this better... Maven surely provides target path.
//sFilePath = "target/"+sFilePath;
+ /*FileWriter fileWriter = new FileWriter(sFilePath);
+ fileWriter.write(content);
+ fileWriter.close();/**/
+ FileOutputStream fileOutputStream = new FileOutputStream(sFilePath);
+ fileOutputStream.write(content.getBytes());
+ fileOutputStream.close();
- //new FileWriter(sFilePath).write(content);
- new FileOutputStream(sFilePath).write(content.getBytes());
-
}
static void writeFile(String sToPath, byte[] bytes) throws FileNotFoundException,
IOException {
- new FileOutputStream(sToPath).write(bytes);
+ FileOutputStream fileOutputStream = new FileOutputStream(sToPath);
+ fileOutputStream.write(bytes);
+ fileOutputStream.close();
}
public static String readFileAsString(String filePath) throws java.io.IOException {
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-03-10
20:08:00 UTC (rev 200)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-03-10
23:04:57 UTC (rev 201)
@@ -22,33 +22,20 @@
package org.jboss.jopr.jsfunit.as5;
-import java.io.FileNotFoundException;
-import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.zip.ZipEntry;
+import org.jboss.jopr.jsfunit.util.DescribedCondition;
+import org.jboss.jopr.jsfunit.util.ActiveConditionChecker;
import org.jboss.jopr.jsfunit.*;
import com.gargoylesoftware.htmlunit.html.*;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.io.*;
+import java.util.*;
+import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.faces.application.FacesMessage;
-import javax.faces.application.FacesMessage.Severity;
import junit.framework.Test;
-import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.commons.lang.StringUtils;
import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
-import org.jboss.jopr.jsfunit.exceptions.ActionNotAvailableException;
-import org.jboss.jopr.jsfunit.exceptions.ActionOutOfSyncException;
-import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
-import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
+import org.jboss.jopr.jsfunit.exceptions.*;
import org.w3c.dom.Node;
@@ -466,87 +453,8 @@
}
- /**
- * Actively waits for a given condition.
- * @see Condition
- */
- private class ActiveConditionChecker {
- Condition condition;
- private boolean dumpPageOnTimout = false;
- private boolean throwExceptionOnTimout = false;
- private EmbjoprTestCase test;
- public ActiveConditionChecker(Condition condition) {
- this.condition = condition;
- }
-
- @SuppressWarnings("empty-statement")
- public boolean waitWithTimeout( int msInterval, int retries ) throws Exception {
-
- while( retries-- > 0 ){
- if( this.condition.isTrue() )
- return true;
- try {
- Thread.sleep(msInterval);
- } catch (InterruptedException ex){
- ;
- }
- }
-
- // While ended, thus we reached the "timeout".
-
- if( this.dumpPageOnTimout ){
- try {
- // Since this is still inner class, we could use 'this'.
- //DebugUtils.writeFile(test.getName() + ".html",
test.getClient().getPageAsText());///
- } catch (Exception ex) { log.error("Can't dump page.", ex); }
- }
-
- if( this.throwExceptionOnTimout ){
- String message = "Timeout expired while waiting for condition:
"+condition.getDescription();
- throw new EmbJoprTestException(message);
- }
-
- return false;
- }
-
- /** If called, exception is thrown if the timeout expires. */
- private ActiveConditionChecker throwOnTimeout( /*String conditionDesc*/ ){
- this.throwExceptionOnTimout = true;
- //this.conditionDesc = conditionDesc;
- return this;
- }
-
- // This has nothing to do with condition checking, but is convenient shorthand...
- private ActiveConditionChecker dumpPageOnTimeout(EmbjoprTestCase test) {
- this.dumpPageOnTimout = true;
- this.test = test;
- return this;
- }
-
- }
-
- /** Condition for ActiveConditionChecker */
- public interface Condition {
- public String getDescription();
- public boolean isTrue() throws Exception;
- }
-
- /** Half-implementation of Condition - takes care of the description. */
- public abstract class DescribedCondition implements Condition {
- private String description;
- public DescribedCondition( String description ){
- this.description = StringUtils.defaultIfEmpty(description,
"(undescribed)");
- }
- public String getDescription() { return this.description; }
- }
-
-
-
-
-
-
/**
* Utilities for performing and checking deployment.
* In the future, it should be general interface like
@@ -781,15 +689,6 @@
}
}
- /** Calls Thread.sleep(ms), ignores the InterruptedException. */
- @SuppressWarnings("empty-statement")
- private void sleep( int ms ) {
- try {
- Thread.sleep(3000);
- } catch (InterruptedException ex) {
- ; // We don't care, that's the purpose of this method.
- }
- }
}// class EarTest
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ActiveConditionChecker.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ActiveConditionChecker.java
(rev 0)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/ActiveConditionChecker.java 2009-03-10
23:04:57 UTC (rev 201)
@@ -0,0 +1,75 @@
+package org.jboss.jopr.jsfunit.util;
+
+import org.jboss.jopr.jsfunit.*;
+import org.apache.commons.lang.StringUtils;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.logging.*;
+
+
+/**
+ * Actively waits for a given condition.
+ * @see Condition
+ */
+public class ActiveConditionChecker {
+
+ protected final Logger log = Logger.getLogger(this.getClass().getName());
+
+ Condition condition;
+ private boolean dumpPageOnTimout = false;
+ private boolean throwExceptionOnTimout = false;
+ private EmbjoprTestCase test;
+
+
+ public ActiveConditionChecker(Condition condition) {
+ this.condition = condition;
+ }
+
+
+ @SuppressWarnings("empty-statement")
+ public boolean waitWithTimeout( int msInterval, int retries ) throws Exception {
+
+ while( retries-- > 0 ){
+ if( this.condition.isTrue() )
+ return true;
+ try {
+ Thread.sleep(msInterval);
+ } catch (InterruptedException ex){
+ ;
+ }
+ }
+
+ // While ended, thus we reached the "timeout".
+
+ if( this.dumpPageOnTimout ){
+ try {
+ // Since this is still inner class, we could use 'this'.
+ //DebugUtils.writeFile(test.getName() + ".html",
test.getClient().getPageAsText());///
+ } catch (Exception ex) { log.error("Can't dump page.", ex); }
+ }
+
+ if( this.throwExceptionOnTimout ){
+ String message = "Timeout expired while waiting for condition:
"+condition.getDescription();
+ throw new EmbJoprTestException(message);
+ }
+
+ return false;
+ }
+
+ /** If called, exception is thrown if the timeout expires. */
+ public ActiveConditionChecker throwOnTimeout( /*String conditionDesc*/ ){
+ this.throwExceptionOnTimout = true;
+ //this.conditionDesc = conditionDesc;
+ return this;
+ }
+
+ // This has nothing to do with condition checking, but is convenient shorthand...
+ public ActiveConditionChecker dumpPageOnTimeout(EmbjoprTestCase test) {
+ this.dumpPageOnTimout = true;
+ this.test = test;
+ return this;
+ }
+
+
+}// class
+
+
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/Condition.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/Condition.java
(rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/Condition.java 2009-03-10
23:04:57 UTC (rev 201)
@@ -0,0 +1,14 @@
+package org.jboss.jopr.jsfunit.util;
+
+
+
+/**
+ * Condition for ActiveConditionChecker.
+ */
+public interface Condition {
+
+ public String getDescription();
+
+ public boolean isTrue() throws Exception;
+
+}// class
\ No newline at end of file
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/DescribedCondition.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/DescribedCondition.java
(rev 0)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/DescribedCondition.java 2009-03-10
23:04:57 UTC (rev 201)
@@ -0,0 +1,15 @@
+
+package org.jboss.jopr.jsfunit.util;
+
+import org.apache.commons.lang.StringUtils;
+
+/**
+ * Half-implementation of Condition - takes care of the description.
+ */
+public abstract class DescribedCondition implements Condition {
+ private String description;
+ public DescribedCondition( String description ){
+ this.description = StringUtils.defaultIfEmpty(description, "(undescribed)");
+ }
+ public String getDescription() { return this.description; }
+}// class
\ No newline at end of file