Author: ozizka(a)redhat.com
Date: 2009-06-04 13:22:59 -0400 (Thu, 04 Jun 2009)
New Revision: 494
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ejb/Ejb20Test.java
Log:
(EJB2 test code format)
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ejb/Ejb20Test.java
===================================================================
---
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ejb/Ejb20Test.java 2009-06-03
17:17:52 UTC (rev 493)
+++
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ejb/Ejb20Test.java 2009-06-04
17:22:59 UTC (rev 494)
@@ -19,7 +19,6 @@
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
*/
-
package org.jboss.jopr.jsfunit.as5.app.ejb;
import org.jboss.jopr.jsfunit.*;
@@ -32,11 +31,8 @@
import javax.faces.application.FacesMessage;
import org.apache.commons.io.FileUtils;
import org.jboss.jopr.jsfunit.exceptions.*;
-import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit;
import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
-
-
/**
* This class contains tests for testing the EmbJopr Application
* Management Functions for Enterprise JavaBean archives with JBoss AS 5.
@@ -48,28 +44,24 @@
public static final DeployableTypes APP_TYPE = DeployableTypes.EJB2;
-
/**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
+ * @return the suite of tests being tested
+ */
+ public static Test suite() {
return new TestSuite(Ejb20Test.class);
}
- /*
- * testName: testBasicEjbDeployment
- * assertion: verify basic deployment of an EJB JAR.
- * test Strategy: Navigate to EJB Applications.
- * Add a new resource. Verify the resource was successfully
- * deployed. Undeploy the archive.
- *
- */
+ /*
+ * testName: testBasicEjbDeployment
+ * assertion: verify basic deployment of an EJB JAR.
+ * test Strategy: Navigate to EJB Applications.
+ * Add a new resource. Verify the resource was successfully
+ * deployed. Undeploy the archive.
+ *
+ */
+ public void testBasicEjbDeployment() throws IOException, EmbJoprTestException {
- public void testBasicEjbDeployment() throws IOException, EmbJoprTestException
- {
-
final String DEPLOYABLE_NAME = BASIC_EJB2;
// Navigate to EJB Applications
@@ -82,31 +74,30 @@
// TODO: "/ejb/BASIC_JAR" causes exceptions in seam:
//
http://wwwapps.rdu.redhat.com/w3xpastebin/pastebin.php?show=9842
- String filePath = ejtt.getTestDataDir() +
"/"+APP_TYPE.getDataDir()+"/"+DEPLOYABLE_NAME;
- log.info("Uploading EJB2 archive: "+filePath);
+ String filePath = ejtt.getTestDataDir() + "/" + APP_TYPE.getDataDir() +
"/" + DEPLOYABLE_NAME;
+ log.info("Uploading EJB2 archive: " + filePath);
File uploadFile = new File(filePath);
- if( !uploadFile.exists() )
- throw new EmbJoprTestException("Can't find EJB2 file to upload:
'"+filePath+"'");
+ if (!uploadFile.exists()) {
+ throw new EmbJoprTestException("Can't find EJB2 file to upload: '" +
filePath + "'");
+ }
// upload ejb
- HtmlFileInput fileInput =
(HtmlFileInput)client.getElement("createContentForm:file");
+ HtmlFileInput fileInput = (HtmlFileInput)
client.getElement("createContentForm:file");
fileInput.setContentType("application/ejb");
fileInput.setValueAttribute(filePath);
client.click("createContentForm:addButton");
- log.info("HTTP status after EJB2 upload:
"+client.getContentPage().getWebResponse().getStatusCode());
- log.info("renderResponse() called: " +
server.getFacesContext().getRenderResponse() );
- log.info("responseComplete() called: " +
server.getFacesContext().getResponseComplete() );
+ log.info("HTTP status after EJB2 upload: " +
client.getContentPage().getWebResponse().getStatusCode());
+ log.info("renderResponse() called: " +
server.getFacesContext().getRenderResponse());
+ log.info("responseComplete() called: " +
server.getFacesContext().getResponseComplete());
- String errorMessage =
- ( server.getFacesMessages().hasNext()
- && server.getFacesMessages().next().getSeverity() !=
FacesMessage.SEVERITY_INFO ) ?
- " Faces message: "+server.getFacesMessages().next()
- : ""; // Awful code
+ String errorMessage =
+ (server.getFacesMessages().hasNext() &&
server.getFacesMessages().next().getSeverity() != FacesMessage.SEVERITY_INFO) ? "
Faces message: " + server.getFacesMessages().next()
+ : ""; // Awful code
// FAILS because of NPE and HTTP 500.
// assert that the success message appeared on the client side
- assertTrue("Success message not found."+errorMessage,
client.getPageAsText().contains("Resource " + DEPLOYABLE_NAME + " created
successfully!"));
+ assertTrue("Success message not found." + errorMessage,
client.getPageAsText().contains("Resource " + DEPLOYABLE_NAME + " created
successfully!"));
// assert text and severity level for FacesMessage on server side
assertTrue(server.getFacesMessages().hasNext());
@@ -114,7 +105,7 @@
assertTrue(FacesMessage.SEVERITY_INFO.equals(successMessage.getSeverity()));
assertTrue(successMessage.getDetail().contains("Resource " + DEPLOYABLE_NAME
+ " created successfully!"));
- assertFalse("Page contains 'Total: 0', EJBs probably not listed.",
client.getPageAsText().contains("Total: 0"));
+ assertFalse("Page contains 'Total: 0', EJBs probably not listed.",
client.getPageAsText().contains("Total: 0"));
// Use JMX to assert that the EJB components really did deploy successfully
@@ -124,39 +115,38 @@
HtmlButtonInput deleteButton = getAppDeleteButton(DEPLOYABLE_NAME);
deleteButton.click();
- assertTrue("Page doesn't contain success message.",
client.getPageAsText().contains(EJB2_DEL_MSG + " '" + DEPLOYABLE_NAME
+"'."));
+ assertTrue("Page doesn't contain success message.",
client.getPageAsText().contains(EJB2_DEL_MSG + " '" + DEPLOYABLE_NAME +
"'."));
- assertFalse("Deployable seems not to be deployed: "+DEPLOYABLE_NAME,
isEJBDeployed(DEPLOYABLE_NAME));
-
+ assertFalse("Deployable seems not to be deployed: " + DEPLOYABLE_NAME,
isEJBDeployed(DEPLOYABLE_NAME));
+
}// testBasicEjbDeployment()
+ /**
+ *
+ test Strategy:
- /**
- *
- test Strategy:
-
- Deploy an ejb-jar that is known to have a bad deployment
- descriptor. Verify the console shows deployment failed.
- Upload the fixed the achive, redeploy and
- verify the archive has been successfully deployed.
-
- */
- public void testBadEjbRedeploy() throws IOException,
HtmlElementNotFoundException, ActionNotAvailableException {
+ Deploy an ejb-jar that is known to have a bad deployment
+ descriptor. Verify the console shows deployment failed.
+ Upload the fixed the achive, redeploy and
+ verify the archive has been successfully deployed.
+ */
+ public void testBadEjbRedeploy() throws IOException, HtmlElementNotFoundException,
ActionNotAvailableException {
- try {
- String badFileSrcPath = ejtt.getTestDataDir()
+"/"+APP_TYPE.getDataDir()+"/"+ BAD_EJB2_JAR;
- String goodFileSrcPath = ejtt.getTestDataDir()
+"/"+APP_TYPE.getDataDir()+"/"+ GOOD_EJB2_JAR;
- String ejbFilePath = ejtt.getTestDataDir()
+"/"+APP_TYPE.getDataDir()+"/"+REDEPLOY_EJB2_JAR;
- FileUtils.copyFile( new File(badFileSrcPath), new
File(ejbFilePath) );
- deployEJB(ejbFilePath);
+ try {
+ String badFileSrcPath = ejtt.getTestDataDir() + "/" + APP_TYPE.getDataDir()
+ "/" + BAD_EJB2_JAR;
+ String goodFileSrcPath = ejtt.getTestDataDir() + "/" + APP_TYPE.getDataDir()
+ "/" + GOOD_EJB2_JAR;
+ String ejbFilePath = ejtt.getTestDataDir() + "/" + APP_TYPE.getDataDir() +
"/" + REDEPLOY_EJB2_JAR;
+
+ FileUtils.copyFile(new File(badFileSrcPath), new File(ejbFilePath));
+ deployEJB(ejbFilePath);
assertFalse("JMX doesn't report " + REDEPLOY_EJB2_JAR + " as
deployed.", isEJBDeployed(REDEPLOY_EJB2_JAR));
// Copy fixed archive to same name, and deploy
- FileUtils.copyFile( new File(goodFileSrcPath), new
File(ejbFilePath) );
+ FileUtils.copyFile(new File(goodFileSrcPath), new File(ejbFilePath));
- deployEJB(ejbFilePath);
+ deployEJB(ejbFilePath);
// assert text and severity level for FacesMessage on server side
assertTrue(server.getFacesMessages().hasNext());
@@ -171,76 +161,71 @@
HtmlButtonInput deleteButton = getAppDeleteButton(REDEPLOY_EJB2_JAR);
deleteButton.click();
- assertTrue("Page doesn't contain success message.",
client.getPageAsText().contains(EJB2_DEL_MSG + " '" + REDEPLOY_EJB2_JAR
+"'."));
- assertFalse("Deployable seems not to be deployed: "+REDEPLOY_EJB2_JAR,
isEJBDeployed(REDEPLOY_EJB2_JAR));
+ assertTrue("Page doesn't contain success message.",
client.getPageAsText().contains(EJB2_DEL_MSG + " '" + REDEPLOY_EJB2_JAR +
"'."));
+ assertFalse("Deployable seems not to be deployed: " + REDEPLOY_EJB2_JAR,
isEJBDeployed(REDEPLOY_EJB2_JAR));
- }
- finally {
- undeployEJB(REDEPLOY_EJB2_JAR);
- }
- }
-
+ } finally {
+ undeployEJB(REDEPLOY_EJB2_JAR);
+ }
+ }
+
// Helpers
+ private void undeployEJB(String ejbFileName)
+ throws IOException, HtmlElementNotFoundException, ActionNotAvailableException {
- private void undeployEJB( String ejbFileName )
- throws IOException, HtmlElementNotFoundException,
ActionNotAvailableException
- {
+ // Navigate to Embedded EJB 2.x Applications
+ ejtt.getNavTree().getNodeLink(NAV_EJB2).click();
- // Navigate to Embedded EJB 2.x Applications
- ejtt.getNavTree().getNodeLink(NAV_EJB2).click();
+ ejtt.getTabMenu().clickSummaryTab();
- ejtt.getTabMenu().clickSummaryTab();
+ // Find the row containing the deployable. Use the pagination if needed.
+ ContentTableRow appRow = ejtt.getTabMenu().getTabContentBox().
+ findLinkRowInDataTableUsingPagination(ejbFileName);
- // Find the row containing the deployable. Use the pagination if needed.
- ContentTableRow appRow = ejtt.getTabMenu().getTabContentBox().
-
findLinkRowInDataTableUsingPagination(ejbFileName);
+ if (null == appRow) {
+ log.warn("Can't find row with Ejb 2.x to undeploy: " + ejbFileName);
+ return;
+ }
- if( null == appRow ){
- log.warn("Can't find row with Ejb 2.x to undeploy:
"+ejbFileName);
- return;
- }
+ appRow.getButtonByLabel("Delete").click();
- appRow.getButtonByLabel("Delete").click();
+ // Log the message (with prefix of potential warning)
+ ejtt.logServerMessage("Something went wrong with undeploy: ");
- // Log the message (with prefix of potential warning)
- ejtt.logServerMessage("Something went wrong with undeploy: ");
+ // Sleep for 3 sec. TODO: write some waitForUndeployed(), as negation of opposite.
+ ejtt.sleep(2000);
- // Sleep for 3 sec. TODO: write some waitForUndeployed(), as negation of
opposite.
- ejtt.sleep( 2000 );
+ }
- }
+ private void deployEJB(String ejbFilePath)
+ throws IOException, HtmlElementNotFoundException {
+ if (!(new File(ejbFilePath)).exists()) {
+ throw new FileNotFoundException(ejbFilePath);
+ }
- private void deployEJB( String ejbFilePath )
- throws IOException, HtmlElementNotFoundException
- {
- if( !(new File(ejbFilePath)).exists())
- throw new FileNotFoundException(ejbFilePath);
+ log.info("Deploying: " + ejbFilePath);
- log.info("Deploying: "+ejbFilePath);
+ // Navigate to Embedded EJB 2 Applications
+ ejtt.getNavTree().getNodeLink(AppConstants.DeployableTypes.EJB2.getNavTreeLabel()).click();
- // Navigate to Embedded EJB 2 Applications
-
ejtt.getNavTree().getNodeLink(AppConstants.DeployableTypes.EJB2.getNavTreeLabel()).click();
+ // click on the "Add new resource" button
+ client.click("actionHeaderForm:addNewContent"); // 404 if
setThrowExceptionOnFailingStatusCode(true) above
- // click on the "Add new resource" button
- client.click("actionHeaderForm:addNewContent"); // 404 if
setThrowExceptionOnFailingStatusCode(true) above
+ // Upload the file
+ HtmlFileInput fileInput = (HtmlFileInput)
client.getElement("createContentForm:file");
+ fileInput.setContentType("application/war");
+ fileInput.setValueAttribute(ejbFilePath);
+ client.click("createContentForm:addButton");
- // Upload the file
- HtmlFileInput fileInput =
(HtmlFileInput)client.getElement("createContentForm:file");
- fileInput.setContentType("application/war");
- fileInput.setValueAttribute(ejbFilePath);
- client.click("createContentForm:addButton");
+ // Log server message.
+ ejtt.logServerMessage();
- // Log server message.
- ejtt.logServerMessage();
+ // Todo: Write some waitUntilDeployed().
+ ejtt.sleep(2000);
- // Todo: Write some waitUntilDeployed().
- ejtt.sleep( 2000 );
-
- }
-
-
+ }
}// class