Author: ozizka(a)redhat.com
Date: 2009-06-11 13:46:50 -0400 (Thu, 11 Jun 2009)
New Revision: 519
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/scripts/
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/scripts/ScriptsTest.java
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/war/WarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java
Log:
ScriptTest added.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-06-11
16:16:17 UTC (rev 518)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-06-11
17:46:50 UTC (rev 519)
@@ -120,6 +120,7 @@
public static final String NAV_EMB_WAR = "Embedded WARs";
public static final String NAV_EMB_RAR = "Embedded RARs";
+
public static final String EAR_MALFORMED_APP_FILENAME =
"malformed-application-xml.ear";
public static final String EAR_MALFORMED_APP_FILENAME_2 =
"malformed-application-xml-2.ear";
public static final String EAR_NOT_MALFORMED_APP_FILENAME =
"not-malformed-application-xml.ear";
@@ -184,17 +185,20 @@
public static final String WAR_VIRTUAL_HOSTS = "vhosts-test.war";
- // Virtual Ghosts
+ // RAR
+ public static final String BASIC_RAR = "jbosstestadapter.rar";
+
+
+
+ // Resource constants
+ public static final String NAV_SCRIPTS = "Scripts";
public static final String NAV_JBOSS_WEB = "JBoss Web";
- public static final String NAV_CONNECTORS = "Connectors";
- public static final String NAV_VIRTUAL_HOSTS = "Virtual Hosts";
+ public static final String NAV_CONNECTORS = "Connectors";
+ public static final String NAV_VIRTUAL_HOSTS = "Virtual Hosts";
- // RAR
- public static final String BASIC_RAR = "jbosstestadapter.rar";
-
// Defaults
public static final String[] WAR_DEFAULTS = new String[]{
"ROOT.war", "invoker.war",
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/war/WarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/war/WarTest.java 2009-06-11
16:16:17 UTC (rev 518)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/war/WarTest.java 2009-06-11
17:46:50 UTC (rev 519)
@@ -26,7 +26,6 @@
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.WebRequestSettings;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
import org.jboss.jopr.jsfunit.*;
@@ -34,17 +33,10 @@
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
-import java.net.URL;
import java.util.Properties;
import javax.faces.application.FacesMessage;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpConnection;
-import org.apache.commons.httpclient.HttpConnectionManager;
-import org.apache.commons.httpclient.SimpleHttpConnectionManager;
-import org.apache.commons.httpclient.params.HttpClientParams;
-import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;
Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/scripts/ScriptsTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/scripts/ScriptsTest.java
(rev 0)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/scripts/ScriptsTest.java 2009-06-11
17:46:50 UTC (rev 519)
@@ -0,0 +1,159 @@
+package org.jboss.jopr.jsfunit.as5.scripts;
+
+import com.gargoylesoftware.htmlunit.Page;
+import com.gargoylesoftware.htmlunit.html.HtmlDivision;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.jboss.jopr.jsfunit.ApplicationTestBaseAS5;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.jopr.jsfunit.util.ActiveConditionChecker;
+import org.jboss.jopr.jsfunit.util.DescribedCondition;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentTable;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.ContentTableRow;
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.NavTreeNode;
+import org.jboss.util.file.FilenameSuffixFilter;
+
+/**
+ *
+ * @author ondra
+ */
+public class ScriptsTest extends ApplicationTestBaseAS5 {
+
+ //public static final DeployableTypes APP_TYPE = DeployableTypes.EMB_WAR;
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite(){
+ return new TestSuite(ScriptsTest.class);
+ }
+
+
+ /**
+ * Tests whether the scripts node exists and that all the scripts are listed.
+ */
+ public void testScriptsListingTest() throws IOException, EmbJoprTestException {
+
+ ejtt.navTree.getNodeByLabel(NAV_SCRIPTS).click();
+ ContentTable scriptsListingTable = ejtt.tabMenu.getTabContentBox().getFirstTable();
+
+ // Go through the dir, and check whether each *.sh file is listed in the page.
+ File binDir = new File(ejtt.getJBossHomeDir());
+ if( !binDir.isDirectory() )
+ throw new EmbJoprTestException(binDir.getAbsolutePath()+" is not a
directory.");
+
+ // Get the list of .sh files in the <JBOSS_HOME>/bin dir.
+ File scriptFiles[] = binDir.listFiles(new FilenameSuffixFilter(".sh"));
+
+ /*
+ List<String> notListedScripts = new ArrayList();
+
+ for( File file : scriptFiles ) {
+ // Go to the scripts node.
+ ejtt.navTree.getNodeByLabel(NAV_SCRIPTS).click();
+
+ // Check whether the script is listed (on any page).
+ ContentTableRow row =
ejtt.getTabMenu().getTabContentBox().findLinkRowInDataTableUsingPagination(file.getName());
+ if( null == row )
+ notListedScripts.add("");
+ }
+ /*/
+
+ // Faster method.
+ List<String> notListedScripts = new ArrayList();
+ for( File file : scriptFiles ) {
+ notListedScripts.add(file.getName());
+ }
+
+ // Go to the scripts node.
+ ejtt.navTree.getNodeByLabel(NAV_SCRIPTS).click();
+
+ int curPage = 1;
+
+ do {
+
+ log.info("Scanning scripts listing, page "+curPage);
+
+ // Remove all scripts listed on this page from the not-listed list.
+ ContentTable scriptListingTable =
ejtt.getTabMenu().getTabContentBox().getDefaultTable();
+ for( ContentTableRow row : scriptListingTable.getRows() ) {
+ String scriptName = row.getCell(0).getTextContent();
+ notListedScripts.remove(scriptName);
+ }
+ // Go to the next page. If there's no next page, quit the loop.
+ Page originalPage = ejtt.getClient().getContentPage();
+ boolean wentNext = ejtt.getTabMenu().getTabContentBox().getPagination().goNext();
+ if( !wentNext )
+ break;
+ if( originalPage.equals( ejtt.getClient().getContentPage() ) )
+ break;
+
+ } while( true );
+ /**/
+
+
+ // If some of the scripts from the <JBOSS_HOME>/bin directory are not listed,
throw.
+ if( 0 < notListedScripts.size() ){
+ throw new EmbJoprTestException("Following <JBOSS_HOME>/bin/*.sh files are
not listed: "+notListedScripts.toArray( new String[0] ) );
+ }
+
+ }
+
+
+
+ /**
+ * Adds a test script to the /bin directory and checks that it appears in the Scripts
listing.
+ */
+ public void testScriptsAddNewShFileTest() throws IOException, EmbJoprTestException {
+
+ final String SCRIPT_FILE_NAME = "embjopr-test.sh";
+
+ // Create the script in JBOSS_HOME/bin/
+ String shFilePath = ejtt.getJBossHomeDir()+"/"+SCRIPT_FILE_NAME;
+ final File file = new File(shFilePath);
+
+ try {
+
+ if( file.exists() ){
+ log.warn(shFilePath+" already exists, thus is already visible in
EmbJopr.");
+ }
+ new FileWriter(shFilePath, false).append("echo 'Test
script.'").close();
+
+
+ // Wait for the script to appear.
+ try {
+ new ActiveConditionChecker(new DescribedCondition("Script
"+SCRIPT_FILE_NAME+" appears in Scripts listing") {
+ int count = 0;
+ public boolean isTrue() throws Exception {
+ ejtt.navTree.getNodeByLabel(NAV_SCRIPTS).click();
+ return null ==
ejtt.tabMenu.getTabContentBox().getFirstTable().findFirstRowContainingLink(SCRIPT_FILE_NAME);
+ }
+ }).throwOnTimeout().dumpPageOnTimeout(this).waitWithTimeout(3000, 20);
+ }
+ catch( EmbJoprTestException ex ){
+ throw ex;
+ }
+ catch( Exception ex ){
+ throw new EmbJoprTestException( ex.getMessage(), ex );
+ }
+ }
+ finally {
+ // Delete the test script file if it exists.
+ if( file.exists() )
+ file.delete();
+ }
+
+
+ }
+
+
+
+}// class
+
+
+
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-06-11
16:16:17 UTC (rev 518)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-06-11
17:46:50 UTC (rev 519)
@@ -7,7 +7,6 @@
import java.net.UnknownHostException;
import java.util.*;
-import java.util.logging.Level;
import org.jboss.jopr.jsfunit.exceptions.*;
import com.gargoylesoftware.htmlunit.html.*;
import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
@@ -18,9 +17,7 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
-import java.net.Inet4Address;
import java.net.InetAddress;
-import java.net.InetSocketAddress;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -114,6 +111,10 @@
return System.getProperty(AppConstants.SYSPROP_JBOSS_CONFIG);
}
+ /**
+ * @returns the directory in wich the AS instance for cargo is located.
+ * THIS IS NOT WHERE THE AS CONFIG DIR (with deploy/ etc.) ARE.
+ */
public String getJBossHomeDir() {
return System.getProperty(AppConstants.SYSPROP_CARGO_JBOSS_HOME_DIR);
}
@@ -815,6 +816,8 @@
/**
* Tries to find a data table row with given deployable, using pagination if needed.
* @returns The row wrapper if found, or null.
+ *
+ * TODO: Get to the first page at the beginning.
*/
public ContentTableRow findLinkRowInDataTableUsingPagination(String label)
throws HtmlElementNotFoundException, IOException
@@ -1337,8 +1340,9 @@
*
* TODO: May throw IndexOutOfBoundsException - leave unchecked?
*
- * @param index
- * @return
+ * @param index the 0-based index
+ * @return the cell at the given index
+ * @throws IndexOutOfBoundsException if there is no cell at the given index
*/
public HtmlTableCell getCell( int index ){
HtmlTableCell cell = this.element.getCell(index);
@@ -1461,9 +1465,14 @@
return !"".equals(
((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
}
+ /** Clicks the "Next" link of the pagination controls.
+ * @returns true if the "Next" link will not bring us to a new page (has no
onClick handler).
+ */
public boolean goNext() throws IOException, HtmlElementNotFoundException{
+ //Page originalPage = client.getContentPage();
HtmlSpan goSpan = getGoSpan("Next");
goSpan.click();
+ //originalPage.equals( ejtt.getClient().getContentPage() )
return !"".equals(
((HtmlTableCell)goSpan.getParentNode()).getOnClickAttribute() );
}
Show replies by date