Author: ozizka(a)redhat.com
Date: 2009-04-03 11:34:16 -0400 (Fri, 03 Apr 2009)
New Revision: 274
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/
Log:
WAR and EAR tests updated
EAR with WAR test added
EAR tests added for Stop-Start and Restart
WAR test added for bad extension archive
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-04-02
19:22:16 UTC (rev 273)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java 2009-04-03
15:34:16 UTC (rev 274)
@@ -115,6 +115,8 @@
public static final String BASIC_EAR = "eardeployment.ear";
public static final String EAR_UNPACKED = "unpacked-ear1.ear";
public static final String EAR_UNPACKED_ZIP = "unpacked-ear1.ear.zip";
+ public static final String EAR_WITH_WAR = "EarWithWarNB.ear";
+ public static final String EAR_WITH_WAR_COUNTER = "EarWithWar-Counter.ear";
public static final String BASIC_WAR = "hellothere.war";
public static final String BASIC_WAR_02 = "hellothere02.war";
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-04-02
19:22:16 UTC (rev 273)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java 2009-04-03
15:34:16 UTC (rev 274)
@@ -22,6 +22,7 @@
package org.jboss.jopr.jsfunit.as5;
+import com.gargoylesoftware.htmlunit.WebClient;
import org.jboss.jopr.jsfunit.util.DescribedCondition;
import org.jboss.jopr.jsfunit.util.ActiveConditionChecker;
import org.jboss.jopr.jsfunit.*;
@@ -30,10 +31,12 @@
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.jboss.jopr.jsfunit.AppConstants.DeployableTypes;
import org.jboss.jopr.jsfunit.exceptions.*;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit;
@@ -394,7 +397,7 @@
try {
ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
- waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
// Navigate to the Configuration tab
ContentTableRow earRow =
ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
@@ -447,7 +450,7 @@
try {
ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
- waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
// Navigate to the Configuration tab
ContentTableRow earRow =
ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
@@ -496,7 +499,7 @@
try {
ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
- waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
// Navigate to the Configuration tab
ContentTableRow earRow =
ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
@@ -535,7 +538,7 @@
try {
// Wait for EAR to be deployed and UP
ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
- waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
ContentTable table =
ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Resource Traits");
ContentInfoTable infoTable =
ejtt.getTabMenu().getTabContentBox().getContentInfoTable(table.getElement());
@@ -564,7 +567,7 @@
try {
ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
- waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
// Navigate to the Metrics tab
ContentTableRow earRow =
ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
@@ -605,7 +608,7 @@
try {
ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
- waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.EAR, BASIC_EAR, 3000, 15);
// Navigate to the Metrics tab
ContentTableRow earRow =
ejtt.getDefaultContentTable().getFirstRowContainingLink(BASIC_EAR);
@@ -646,7 +649,7 @@
try {
// Loop, wait for the app to appear.
log.info("Waiting for EAR to appear.");
- waitActivelyForDeployment( DeployableTypes.EAR, EAR_UNPACKED, 5000, 5 );
+ ejtt.deployment.waitActivelyForDeployment( DeployableTypes.EAR, EAR_UNPACKED, 5000, 5
);
ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
@@ -673,12 +676,246 @@
/**
+ * Deploys an EAR with WAR as a module, and checks whether the web app runs.
+ */
+ public void testEarWithWar() throws IOException, EmbJoprTestException {
+
+ final String DEPLOYABLE_NAME = EAR_WITH_WAR;
+
+ // Deploy the EAR.
+ String earFilePath = ejtt.getTestDataDir() + "/ear/"+DEPLOYABLE_NAME;
+ deployEar( earFilePath );
+
+ // Get the HTTP port and the URL of the test page.
+ HttpServletRequest tmpRequest =
(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
+ int port = tmpRequest.getLocalPort();
+ // Eventually remove ".war" suffix and add "-war" (convention)
+ String context = StringUtils.chomp( DEPLOYABLE_NAME, ".ear" )
+"-war";
+ String testPageUrl =
"http://localhost:"+port+"/"+context+"/index.jsp";
+
+ // Create web client we will use to check the web app.
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(false);
+ HtmlPage page;
+
+ try {
+
+ // Wait until the EAR is UP.
+ ejtt.getNavTree().getNodeByLabel(NAV_EAR).click();
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.EAR, DEPLOYABLE_NAME, 3000,
15, this);
+
+ // Assert that the app is running.
+ page = (HtmlPage)webClient.getPage(testPageUrl);
+ assertEquals( "HTTP status of "+testPageUrl+" should be 200", 200,
page.getWebResponse().getStatusCode() );
+ assertTrue("Page should contain 'Hello World'",
page.asText().contains("Hello World"));
+
+ }
+ finally {
+ undeployEar(BASIC_EAR);
+ }
+
+
+ }
+
+
+
+
+
+
+
+
+
+ public void testStopAndStartEar() throws IOException, EmbJoprTestException
+ {
+ final String DEPLOYABLE_NAME = EAR_WITH_WAR_COUNTER;
+
+ // Get the HTTP port and the URL of the test page.
+ HttpServletRequest tmpRequest =
(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
+ int port = tmpRequest.getLocalPort();
+ String context = StringUtils.chomp( DEPLOYABLE_NAME, ".ear"
)+"-war"; // Eventually remove ".ear" suffix.
+ String testPageUrl =
"http://localhost:"+port+"/"+context+"/hello.jsp";
+
+ // Create web client we will use to check the web app.
+ WebClient webClient = new WebClient();
+ // We'll get 404 after stopping the app.
+ webClient.setThrowExceptionOnFailingStatusCode(false);
+ HtmlPage page;
+
+
+ // Deploy the EAR.
+ String appfilePath = ejtt.getTestDataDir() + "/ear/"+DEPLOYABLE_NAME;
+ deployEar( appfilePath );
+
+ try {
+
+ // Wait until app is UP
+ ejtt.getNavTree().getNodeByLabel(DeployableTypes.EAR.getNavTreeLabel()).click();
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.EAR, DEPLOYABLE_NAME,
+ 3000, 15, this);
+
+ // Assert that the app is running.
+ page = (HtmlPage)webClient.getPage(testPageUrl);
+ assertEquals( "HTTP status of "+testPageUrl+" should be 200", 200,
page.getWebResponse().getStatusCode() );
+ assertTrue("Page should contain 'HELLO WORLD'",
page.asText().contains("HELLO WORLD"));
+
+ // Refresh the page several times to increase the counter.
+ page.refresh();
+ page.refresh();
+
+ // Get the counter number.
+ Integer count1 =
NumberUtils.createInteger(page.getBody().getHtmlElementById("count").getTextContent());
+
+
+
+ // Navigate to the web app, then to it's Control tab.
+ ContentTableRow row =
ejtt.getDefaultContentTable().getFirstRowContainingLink(DEPLOYABLE_NAME);
+ row.getLinkByLabel(DEPLOYABLE_NAME).click();
+ ejtt.getTabMenu().clickControlTab();
+
+ // Click the Stop button.
+ 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().getOperationHistoryTable().wasLastOperationSuccesful()
);
+
+
+ // Assert that the app is stopped.
+ page = (HtmlPage)webClient.getPage(testPageUrl);
+ assert( 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().getOperationHistoryTable().getElement();
+ HtmlTableRow tr = operationHistoryTable.getFirstByXPath("tr[contains(@class,
'rich-table-firstrow')]");
+ assertTrue( tr.getTextContent().contains("Success") );
+
+
+ // Assert that the app is running.
+ page = (HtmlPage)webClient.getPage(testPageUrl);
+ assert( 200 == page.getWebResponse().getStatusCode() );
+ assertTrue(page.asText().contains("HELLO WORLD"));
+
+ // Get the counter number.
+ Integer count2 =
NumberUtils.createInteger(page.getBody().getHtmlElementById("count").getTextContent());
+
+ assertTrue( "Counter is reset upon app restart, thus should be lower
after.", count1 > count2 );
+
+
+ }
+ finally {
+ undeployEar(DEPLOYABLE_NAME);
+ }
+ }
+
+
+ /**
+ * Restarts the EAR in Control tab and checks whether it was really restarted.
+ */
+ public void testRestartEar() throws IOException, EmbJoprTestException
+ {
+ final String DEPLOYABLE_NAME = EAR_WITH_WAR_COUNTER;
+
+ // Get the HTTP port and the URL of the test page.
+ HttpServletRequest tmpRequest =
(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
+ int port = tmpRequest.getLocalPort();
+ String context = StringUtils.chomp( DEPLOYABLE_NAME, ".ear"
)+"-war";
+ String testPageUrl =
"http://localhost:"+port+"/"+context+"/hello.jsp";
+
+ // Create web client we will use to check the web app.
+ WebClient webClient = new WebClient();
+ webClient.setThrowExceptionOnFailingStatusCode(false);
+ HtmlPage page;
+
+
+ // Deploy the app.
+ String appFilePath = ejtt.getTestDataDir() + "/ear/"+DEPLOYABLE_NAME;
+ deployEar( appFilePath );
+
+ try {
+
+ // Wait until app is UP
+ ejtt.getNavTree().getNodeByLabel(DeployableTypes.EAR.getNavTreeLabel()).click();
+ ejtt.deployment.waitActivelyForDeployment(DeployableTypes.EAR, DEPLOYABLE_NAME,
+ 3000, 15, this);
+
+ // Assert that the app is running.
+ page = (HtmlPage)webClient.getPage(testPageUrl);
+ assertEquals( "HTTP status of "+testPageUrl+" should be 200", 200,
page.getWebResponse().getStatusCode() );
+ assertTrue("Page should contain 'HELLO WORLD'",
page.asText().contains("HELLO WORLD"));
+
+ // Refresh the page several times to increase the counter.
+ page.refresh();
+ page.refresh();
+
+ // Get the counter number.
+ Integer count1 =
NumberUtils.createInteger(page.getBody().getHtmlElementById("count").getTextContent());
+
+
+
+ // Navigate to the web app, then to it's Control tab.
+ ContentTableRow row =
ejtt.getDefaultContentTable().getFirstRowContainingLink(DEPLOYABLE_NAME);
+ row.getLinkByLabel(DEPLOYABLE_NAME).click();
+ ejtt.getTabMenu().clickControlTab();
+
+ // Click the Restart button.
+ ejtt.tabMenu.getTabContentBox().getButtonByLabel("Restart").click();
+
+ // Check the latest message. TODO: EJTT class for ops history table?
+ HtmlTable operationHistoryTable =
ejtt.getTabMenu().getTabContentBox().getOperationHistoryTable().getElement();
+ HtmlTableRow tr = operationHistoryTable.getFirstByXPath("tr[contains(@class,
'rich-table-firstrow')]");
+ assertTrue( tr.getTextContent().contains("Success") );
+
+
+ // Assert that the app is running.
+ page = (HtmlPage)webClient.getPage(testPageUrl);
+ assert( 200 == page.getWebResponse().getStatusCode() );
+ assertTrue(page.asText().contains("HELLO WORLD"));
+
+ // Get the counter number.
+ Integer count2 =
NumberUtils.createInteger(page.getBody().getHtmlElementById("count").getTextContent());
+
+ assertTrue( "Counter is reset upon app restart, thus should be lower
after.", count1 > count2 );
+
+ }
+ finally {
+ undeployEar(DEPLOYABLE_NAME);
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ /**
* Waits for the deployable to be in the UP State.
*
* @param type Type of deployable - EAR, WAR, SAR, ...
* @param name Name of the deployable, like 'hello.war'.
+ @deprecated Moved to EJTT.Deployment.
*/
- private void waitActivelyForDeployment(
+ private void XwaitActivelyForDeployment(
final DeployableTypes type, final String name,
int intervalMS, int retries
)
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java 2009-04-02
19:22:16 UTC (rev 273)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java 2009-04-03
15:34:16 UTC (rev 274)
@@ -22,6 +22,7 @@
package org.jboss.jopr.jsfunit.as5;
+import javax.faces.application.FacesMessage.Severity;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import com.gargoylesoftware.htmlunit.WebClient;
@@ -31,6 +32,7 @@
import com.gargoylesoftware.htmlunit.html.*;
import java.io.*;
import java.util.Properties;
+import javax.faces.application.FacesMessage;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.lang.StringUtils;
@@ -989,15 +991,53 @@
+ /**
+ * Deploys a WAR with bad farchive extension (.zip)
+ * and checks whether EmbJopr reports deployment failure.
+ */
+ public void testDeployWarWithIncorrectExtension() throws IOException,
EmbJoprTestException
+ {
+ final String DEPLOYABLE_NAME = WAR_UNPACKED_ZIP;
+ // Deploy the WAR.
+ String WARFilePath = ejtt.getTestDataDir() + "/war/"+DEPLOYABLE_NAME;
+ deployWarRepeatedly( WARFilePath );
+ try {
+ assertTrue( "There should be a faces message informing about failure.",
+ server.getFacesMessages().hasNext() );
+ assertTrue( "The failure message should have ERROR severity.",
+ FacesMessage.SEVERITY_ERROR == server.getFacesMessages().next().getSeverity() );
+ assertTrue( "Page should contain 'Incorrect extension' string (deployer
message).",
+ client.getPageAsText().contains("Incorrect extension") );
+ }
+ finally {
+ // Undeploy for the case it was (errorneously) deployed.
+ try {
+ undeployWAR(DEPLOYABLE_NAME);
+ } catch( Exception ex ){
+ log.debug("Cathed an expected exception when trying to undeploy
"+DEPLOYABLE_NAME+": "+ex );
+ }
+ }
+ }
+
+
+
+
+
+
+
+
+
+
+
/**
* Deploys WAR.
*/
Property changes on: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util
___________________________________________________________________
Name: svn:ignore
+ JVMUtils.java