Author: ozizka(a)redhat.com
Date: 2009-05-18 08:25:53 -0400 (Mon, 18 May 2009)
New Revision: 433
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/EarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/rar/RarTest.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:
EarTest, WarTest - now waiting for an operation to finish; EJTT updated.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/EarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/EarTest.java 2009-05-18
02:54:06 UTC (rev 432)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ear/EarTest.java 2009-05-18
12:25:53 UTC (rev 433)
@@ -43,6 +43,7 @@
import org.apache.commons.lang.math.RandomUtils;
import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
import org.jboss.jopr.jsfunit.exceptions.*;
+import org.jboss.jopr.jsfunit.util.Condition;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
import org.w3c.dom.Node;
@@ -841,37 +842,58 @@
ejtt.tabMenu.getTabContentBox().getButtonByLabel("Stop").click();
// Check the latest message.
- /*
- HtmlTable operationHistoryTable =
ejtt.getTabMenu().getTabContentBox().getOperationHistoryTable().getElement();
- HtmlTableRow tr =
operationHistoryTable.getFirstByXPath("tbody/tr[contains(@class,
'rich-table-firstrow')]");
- assertTrue( tr.getTextContent().contains("Success") );
- /**/
- DebugUtils.writeFile("target/testStopAndStartEar-opsTable.html",
client.getPageAsText() );///
- OperationStatusType status =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getLastOperationStatus();
- assertEquals("Stop operation did not succeed, the status is: "+status,
OperationStatusType.SUCCESS, status);
+ //DebugUtils.writeFile("target/testStopAndStartEar-opsTable.html",
client.getPageAsText() );///
+ //OperationStatusType status =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getLastOperationStatus();
+ //assertEquals("Stop operation did not succeed, the status is: "+status,
OperationStatusType.SUCCESS, status);
//assertTrue(
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful()
);
+ /*try {
+ new ActiveConditionChecker( new DescribedCondition("Stop operation status
changes from 'In Progreess'.") {
+ int calls = 0;
+ public boolean isTrue() throws Exception {
+ if( ++calls > 1 ) ((HtmlPage)client.getContentPage()).refresh();
+ OperationStatusType status =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getLastOperationStatus();
+ return ! OperationStatusType.IN_PROGRESS.equals( status );
+ }
+ }).dumpPageOnTimeout(this).throwOnTimeout().waitWithTimeout(1500, 5);
+ }
+ catch(Exception ex){
+ throw new EmbJoprTestException(ex.getMessage(), ex.getCause());
+ }/**/
+ ejtt.operations.waitActivelyForOperationToFinish("Stop", 1500, 5);
+
// Assert that the app is stopped.
page = (HtmlPage)webClient.getPage(testPageUrl);
assertTrue( 200 != page.getWebResponse().getStatusCode() );
+
// Click the Start button.
ejtt.tabMenu.getTabContentBox().getButtonByLabel("Start").click();
// Check the latest message. TODO: EJTT class for ops history table?
- /*
- HtmlTable operationHistoryTable =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getElement();
- HtmlTableRow tr =
operationHistoryTable.getFirstByXPath("tbody/tr[contains(@class,
'rich-table-firstrow')]");
- assertTrue( tr.getTextContent().contains("Success") );
- */
- DebugUtils.writeFile("target/testStopAndStartEar-opsTable2.html",
client.getPageAsText() );///
- status =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getLastOperationStatus();
- assertEquals("Start operation did not succeed, the status is: "+status,
OperationStatusType.SUCCESS, status);
+ //DebugUtils.writeFile("target/testStopAndStartEar-opsTable2.html",
client.getPageAsText() );///
+ //status =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getLastOperationStatus();
+ //assertEquals("Start operation did not succeed, the status is: "+status,
OperationStatusType.SUCCESS, status);
//assertTrue(
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful()
);
+ /*try {
+ new ActiveConditionChecker( new DescribedCondition("Start operation status
changes from 'In Progreess'.") {
+ int calls = 0;
+ public boolean isTrue() throws Exception {
+ if( ++calls > 1 ) ((HtmlPage)client.getContentPage()).refresh();
+ OperationStatusType status =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getLastOperationStatus();
+ return ! OperationStatusType.IN_PROGRESS.equals( status );
+ }
+ }).dumpPageOnTimeout(this).throwOnTimeout().waitWithTimeout(1500, 5);
+ }
+ catch(Exception ex){
+ throw new EmbJoprTestException(ex.getMessage(), ex.getCause());
+ }/**/
+ ejtt.operations.waitActivelyForOperationToFinish("Start", 1500, 5);
+
// Assert that the app is running.
page = (HtmlPage)webClient.getPage(testPageUrl);
assertTrue( 200 == page.getWebResponse().getStatusCode() );
@@ -949,14 +971,9 @@
ejtt.tabMenu.getTabContentBox().getButtonByLabel("Restart").click();
// Check the latest message. TODO: EJTT class for ops history table?
- /*
- HtmlTable operationHistoryTable =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getElement();
- HtmlTableRow tr =
operationHistoryTable.getFirstByXPath("tbody/tr[contains(@class,
'rich-table-firstrow')]");
- assertTrue( tr.getTextContent().contains("Success") );
- */
- //assertTrue(
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful()
);
- OperationStatusType status =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getLastOperationStatus();
- assertEquals("Stop operation did not succeed, the status is: "+status,
OperationStatusType.SUCCESS, status);
+ //OperationStatusType status =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getLastOperationStatus();
+ //assertEquals("Stop operation did not succeed, the status is: "+status,
OperationStatusType.SUCCESS, status);
+ ejtt.operations.waitActivelyForOperationToFinish("Restart", 1500, 5);
@@ -1264,17 +1281,6 @@
}
- /**
- * Returns true if there's a file of the given name in server's deploy dir;
- * false otherwise.
- */
- private boolean isDeployedAccordingToFileSystem( DeployableTypes type, String name )
- {
- String deployPath = System.getProperty(SYSPROP_DEPLOY_DIR);
- String fileName = deployPath+"/"+name;
- return (new File(fileName)).exists();
- }
-
private void undeployViaFileSystem( String name ) throws EmbJoprTestException{
String deployPath = System.getProperty(SYSPROP_DEPLOY_DIR);
String fileName = deployPath+"/"+name;
@@ -1415,6 +1421,8 @@
undeletableFiles.add( path.getAbsolutePath() );
}
+
+
private void deployEar( String earFilePath ) throws IOException,
HtmlElementNotFoundException
{
if( !(new File(earFilePath)).exists())
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/rar/RarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/rar/RarTest.java 2009-05-18
02:54:06 UTC (rev 432)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/rar/RarTest.java 2009-05-18
12:25:53 UTC (rev 433)
@@ -23,26 +23,18 @@
package org.jboss.jopr.jsfunit.as5.app.rar;
import com.gargoylesoftware.htmlunit.Page;
-import com.gargoylesoftware.htmlunit.WebClient;
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.*;
import java.util.*;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.lang.math.RandomUtils;
import org.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
import org.jboss.jopr.jsfunit.exceptions.*;
-import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
import org.w3c.dom.Node;
@@ -336,18 +328,20 @@
*/
public void DISABLEDtestRarConfigurationTab() throws IOException, EmbJoprTestException
{
+ final String DEPLOYABLE_NAME = BASIC_RAR;
+
// Deploy the RAR.
- String rarFilePath = ejtt.getTestDataDir() +"/rar/"+ BASIC_RAR;
+ String rarFilePath = ejtt.getTestDataDir() +"/rar/"+ DEPLOYABLE_NAME;
deployRar( rarFilePath );
try {
- ejtt.getNavTree().getNodeByLabel(NAV_RAR).click();
- ejtt.deployment.waitActivelyForDeployment(DeployableTypes.RAR, BASIC_RAR, 3000, 15);
+ ejtt.getNavTree().getNodeByLabel(APP_TYPE.getNavTreeLabel()).click();
+ ejtt.deployment.waitActivelyForDeployment(APP_TYPE, DEPLOYABLE_NAME, 3000, 15);
// Navigate to the Configuration tab
- ContentTableRow rarRow =
ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_RAR);
- rarRow.getLinkByLabel(BASIC_RAR).click();
+ ContentTableRow rarRow =
ejtt.getDefaultContentTable().getFirstRowContainingLink(DEPLOYABLE_NAME);
+ rarRow.getLinkByLabel(DEPLOYABLE_NAME).click();
Page prevPage = client.getContentPage();
ejtt.tabMenu.clickConfigurationTab();
@@ -380,7 +374,7 @@
}
finally {
try {
- undeployRar(BASIC_RAR);
+ undeployRar(DEPLOYABLE_NAME);
}catch( Exception ex ){
log.error("Caught exception when undeploying: "+ex, ex);
}
@@ -390,115 +384,11 @@
- /**
- * Redeploys RAR.
- *
- */
- public void testRarRedeployment() throws IOException, EmbJoprTestException {
- final String DEPLOYABLE_NAME = BASIC_RAR;
+ // Utils
- // Deploy the RAR.
- String appFilePath = ejtt.getTestDataDir() +
"/"+DeployableTypes.RAR.getDataDir()+"/"+DEPLOYABLE_NAME;
- deployRar( appFilePath );
-
- try {
-
- ejtt.getNavTree().getNodeByLabel(NAV_RAR).click();
- ejtt.deployment.waitActivelyForDeployment(DeployableTypes.RAR, DEPLOYABLE_NAME, 3000,
15);
-
- // Navigate to the Configuration tab
- ContentTableRow rarRow =
ejtt.getDefaultContentTable().getFirstRowContainingLink(DEPLOYABLE_NAME);
- rarRow.getLinkByLabel(DEPLOYABLE_NAME).click();
- ejtt.tabMenu.clickContentTab();
-
- String xPath = ".//table//input[@type='file']";
- HtmlFileInput fileInput =
ejtt.tabMenu.getTabContentBox().getElement().getFirstByXPath(xPath);
- fileInput.setValueAttribute(appFilePath);
- xPath = ".//table//input[@type='submit']";
- HtmlSubmitInput submit =
ejtt.tabMenu.getTabContentBox().getElement().getFirstByXPath(xPath);
- submit.click();
-
-
-
- }
- finally {
- try {
- undeployRar(DEPLOYABLE_NAME);
- }catch( Exception ex ){
- log.error("Caught exception when undeploying: "+ex, ex);
- }
- }
-
- }
-
- /**
- * Utilities for performing and checking deployment.
- * In the future, it should be general interface like
- * boolean isDeployed( DeployableType type, String name ).
- */
- protected class DeploymentUtils {
-
- /**
- * Returns true if EmbJopr lists a deployable of given type and name,
- * and it's State is UP; false otherwise.
- */
- private boolean isDeployedAccordingToEmbJopr( DeployableTypes type, String
deployableName )
- throws HtmlElementNotFoundException, IOException
- {
- // Refresh / go to the appropriate page.
- ejtt.getNavTree().getNodeByLabel( type.getNavTreeLabel() ).click();
- ContentTableRow rarRow =
ejtt.getDefaultContentTable().findFirstRowContainingLink(deployableName);
- if( null == rarRow ){
- log.debug("Row with "+deployableName+" not present.");
- return false;
- }
-
- String statusText = rarRow.getCellTextByColumnName("Status");
- if( "UP".equals(statusText) ){
- return true;
- }else{
- log.debug("Row with "+deployableName+" has Status ==
'"+statusText+"' != UP.");
- return false;
- }
- }
-
-
- /**
- * Returns true if there's a file of the given name in server's deploy dir;
- * false otherwise.
- */
- private boolean isDeployedAccordingToFileSystem( DeployableTypes type, String name )
- {
- String deployPath = System.getProperty(SYSPROP_DEPLOY_DIR);
- String fileName = deployPath+"/"+name;
- return (new File(fileName)).exists();
- }
-
- private void undeployViaFileSystem( String name ) throws EmbJoprTestException{
- String deployPath = System.getProperty(SYSPROP_DEPLOY_DIR);
- String fileName = deployPath+"/"+name;
- File fileToDelete = new File(fileName);
-
- if( !fileToDelete.exists() )
- throw new EmbJoprTestException("Deployable doesn't exist: "+fileName);
-
- if(fileToDelete.isFile()){
- if( !fileToDelete.delete() ){
- throw new EmbJoprTestException("Unable to delete: "+fileName);
- }
- }else if(fileToDelete.isDirectory()){
- deleteDirectory(fileToDelete);
- }
-
- }// isDeployedAccordingToFileSystem()
-
-
- }// class DeploymentUtils
-
-
-
+
private void deployRar( String rarFilePath ) throws IOException,
HtmlElementNotFoundException
{
if( !(new File(rarFilePath)).exists())
@@ -551,34 +441,4 @@
}
- public static void deleteDirectory(File path) throws EmbJoprTestException
- {
- List<String> undeletableFiles = new ArrayList();
- deleteDirectory(path, undeletableFiles);
- if( !undeletableFiles.isEmpty() ){
- throw new EmbJoprTestException("Couldn't delete
following files: \n "+
-
StringUtils.join(undeletableFiles, "\n ") + "\n");
- }
- }
-
- public static void deleteDirectory(File path, List<String> undeletableFiles)
- {
- if( path.exists() ) {
- File[] files = path.listFiles();
- for(int i=0; i<files.length; i++) {
- if(files[i].isDirectory()) {
- deleteDirectory(files[i], undeletableFiles );
- } else {
- if( !files[i].delete() ){
- undeletableFiles.add(files[i].getAbsolutePath());
- }
- }
- }
- }
-
- if( ! path.delete() )
- undeletableFiles.add( path.getAbsolutePath() );
- }
-
-
}// class RarTest
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-05-18
02:54:06 UTC (rev 432)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/war/WarTest.java 2009-05-18
12:25:53 UTC (rev 433)
@@ -23,7 +23,6 @@
package org.jboss.jopr.jsfunit.as5.app.war;
import com.gargoylesoftware.htmlunit.Page;
-import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import com.gargoylesoftware.htmlunit.WebClient;
@@ -897,14 +896,11 @@
ejtt.tabMenu.getTabContentBox().getButtonByLabel("Stop").click();
// Check the latest message.
- /*
- HtmlTable operationHistoryTable =
ejtt.getTabMenu().getTabContentBox().getOperationHistoryTable().getElement();
- HtmlTableRow tr = operationHistoryTable.getFirstByXPath("tr[contains(@class,
'rich-table-firstrow')]");
- assertTrue( tr.getTextContent().contains("Success") );
- /**/
assertTrue(
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful()
);
+ ejtt.operations.waitActivelyForOperationToFinish("Stop", 1500, 5);
+
// Assert that the app is stopped.
page = (HtmlPage)webClient.getPage(testPageUrl);
assertTrue( 200 != page.getWebResponse().getStatusCode() );
@@ -914,12 +910,8 @@
ejtt.tabMenu.getTabContentBox().getButtonByLabel("Start").click();
// Check the latest message. TODO: EJTT class for ops history table?
- /*
- HtmlTable operationHistoryTable =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getElement();
- HtmlTableRow tr =
operationHistoryTable.getFirstByXPath("tbody/tr[contains(@class,
'rich-table-firstrow')]");
- assertTrue( tr.getTextContent().contains("Success") );
- */
- assertTrue(
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful()
);
+ //assertTrue(
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful()
);
+ ejtt.operations.waitActivelyForOperationToFinish("Start", 1500, 5);
// Assert that the app is running.
@@ -999,12 +991,8 @@
ejtt.tabMenu.getTabContentBox().getButtonByLabel("Restart").click();
// Check the latest message. TODO: EJTT class for ops history table?
- /*
- HtmlTable operationHistoryTable =
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getElement();
- HtmlTableRow tr =
operationHistoryTable.getFirstByXPath("tbody/tr[contains(@class,
'rich-table-firstrow')]");
- assertTrue( tr.getTextContent().contains("Success") );
- */
- assertTrue(
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful()
);
+ //assertTrue(
ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful()
);
+ ejtt.operations.waitActivelyForOperationToFinish("Restart", 1500, 5);
// Assert that the app is running.
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-05-18
02:54:06 UTC (rev 432)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java 2009-05-18
12:25:53 UTC (rev 433)
@@ -1542,8 +1542,55 @@
}
+
+
+
+ public final Operations operations = new Operations();
+
+ /**
+ * Operations
+ */
+ public class Operations {
+
+ /**
+ * Checks whether the status of the last operation on current page (must be on
operations page)
+ * is "In Progress". If true, waits for it to change. If false,
+ *
+ * @param opName Operation name - only for log purposes.
+ * @param interval Millisecons between retries (page refreshes).
+ * @param retries Number of retries.
+ * @throws org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException
+ */
+ public void waitActivelyForOperationToFinish( String opName, int interval, int retries
) throws EmbJoprTestException
+ {
+ try {
+ new ActiveConditionChecker( new
DescribedCondition("'"+opName+"' operation status changes from
'"+OperationStatusType.IN_PROGRESS.getStatusText()+"'.") {
+ int calls = 0;
+ public boolean isTrue() throws Exception {
+ if( ++calls > 1 ) ((HtmlPage)client.getContentPage()).refresh();
+ OperationStatusType status =
selfEjtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().getLastOperationStatus();
+ return ! OperationStatusType.IN_PROGRESS.equals( status );
+ }
+ }).dumpPageOnTimeout(selfEjtt.currentTest).throwOnTimeout().waitWithTimeout(1500,
5);
+ }
+ catch(Exception ex){
+ throw new EmbJoprTestException(ex.getMessage(), ex.getCause());
+ }
+
+ }
+
+ }// class Operations
+
+
+
+
+
+
public final Deployment deployment = new Deployment();
+ /**
+ * Deployment
+ */
public class Deployment {
// TODO: Shortcuts:
@@ -1742,6 +1789,7 @@
+
/**
* Waits for the deployable to be in the UP State.
*