[embjopr-commits] EMBJOPR SVN: r498 - trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ejb.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Thu Jun 4 14:35:27 EDT 2009


Author: ozizka at redhat.com
Date: 2009-06-04 14:35:27 -0400 (Thu, 04 Jun 2009)
New Revision: 498

Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ejb/Ejb20Test.java
Log:
Ejb20 tests added

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-04 18:07:45 UTC (rev 497)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/app/ejb/Ejb20Test.java	2009-06-04 18:35:27 UTC (rev 498)
@@ -21,15 +21,22 @@
  */
 package org.jboss.jopr.jsfunit.as5.app.ejb;
 
+import org.jboss.jopr.jsfunit.util.EmbJoprTestToolkit.*;
+
+import com.gargoylesoftware.htmlunit.WebClient;
 import org.jboss.jopr.jsfunit.*;
 import com.gargoylesoftware.htmlunit.html.*;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
+import java.io.*;
+import java.util.*;
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+import javax.servlet.http.HttpServletRequest;
 import junit.framework.Test;
 import junit.framework.TestSuite;
-import javax.faces.application.FacesMessage;
 import org.apache.commons.io.FileUtils;
+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.*;
 
@@ -52,6 +59,9 @@
 	}
 
 
+
+
+
 	/*
 	 * testName: testBasicEjbDeployment
 	 * assertion:  verify basic deployment of an EJB JAR.
@@ -64,89 +74,103 @@
 
 		final String DEPLOYABLE_NAME = BASIC_EJB2;
 
-		// Navigate to EJB Applications
-		HtmlAnchor ejbLink = getNavTreeLink(APP_TYPE.getNavTreeLabel());
-		ejbLink.click();
+		try {
+			// Navigate to EJB Applications
+			HtmlAnchor ejbLink = getNavTreeLink(APP_TYPE.getNavTreeLabel());
+			ejbLink.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
 
-		// TODO: "/ejb/BASIC_JAR" causes exceptions in seam:
-		// http://wwwapps.rdu.redhat.com/w3xpastebin/pastebin.php?show=9842
+			// 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);
-		File uploadFile = new File(filePath);
-		if (!uploadFile.exists()) {
-			throw new EmbJoprTestException("Can't find EJB2 file to upload: '" + 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 + "'");
+			}
 
-		// upload ejb
-		HtmlFileInput fileInput = (HtmlFileInput) client.getElement("createContentForm:file");
-		fileInput.setContentType("application/ejb");
-		fileInput.setValueAttribute(filePath);
-		client.click("createContentForm:addButton");
+			// upload ejb
+			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!"));
+			// 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!"));
 
-		// assert text and severity level for FacesMessage on server side
-		assertTrue(server.getFacesMessages().hasNext());
-		FacesMessage successMessage = server.getFacesMessages().next();
-		assertTrue(FacesMessage.SEVERITY_INFO.equals(successMessage.getSeverity()));
-		assertTrue(successMessage.getDetail().contains("Resource " + DEPLOYABLE_NAME + " created successfully!"));
+			// assert text and severity level for FacesMessage on server side
+			assertTrue(server.getFacesMessages().hasNext());
+			FacesMessage successMessage = server.getFacesMessages().next();
+			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
-		assertTrue(isEJBDeployed(DEPLOYABLE_NAME));
+			// Use JMX to assert that the EJB components really did deploy successfully
+			assertTrue(isEJBDeployed(DEPLOYABLE_NAME));
 
-		// Undeploy the EJB JAR 
-		HtmlButtonInput deleteButton = getAppDeleteButton(DEPLOYABLE_NAME);
-		deleteButton.click();
+			// Undeploy the EJB JAR
+			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));
+		} finally {
+			// Undeploy the EJB JAR
+			try {
+				ejtt.deployment.undeployViaEmbJopr(APP_TYPE, REDEPLOY_EJB2_JAR);
+			} catch (EmbJoprTestException ex) {
+				log.debug("Exception during undeployment - " + ex.getMessage());
+			}
+		}
 
 	}// testBasicEjbDeployment()
 
+
+
+
+
+
+	
 	/**
-	 *
 	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 {
 
-
 		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);
+			//deployEJB(ejbFilePath);
+			ejtt.deployment.deployViaEmbJopr(APP_TYPE, 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));
 
-			deployEJB(ejbFilePath);
+			//deployEJB(ejbFilePath);
+			ejtt.deployment.deployViaEmbJopr(APP_TYPE, ejbFilePath);
 
 			// assert text and severity level for FacesMessage on server side
 			assertTrue(server.getFacesMessages().hasNext());
@@ -157,75 +181,253 @@
 			// Use JMX to assert that the EJB components really did deploy successfully
 			assertTrue(isEJBDeployed(REDEPLOY_EJB2_JAR));
 
-			// Undeploy the EJB JAR 
-			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));
+		} finally {
+			// Undeploy the EJB JAR
+			try {
+				ejtt.deployment.undeployViaEmbJopr(APP_TYPE, REDEPLOY_EJB2_JAR);
+			} catch (EmbJoprTestException ex) {
+				log.debug("Exception during undeployment - " + ex.getMessage());
+			}
+		}
+	}
 
 
+
+
+	/**
+	 *
+	 */
+	public void testEjb20SummaryTab() throws EmbJoprTestException, IOException {
+
+		final String DEPLOYABLE_NAME = BASIC_EJB2;
+
+		try {
+
+			// Deploy the APP
+			String appFilePath = ejtt.getTestDataDir() + "/"+APP_TYPE.getDataDir()+"/" + DEPLOYABLE_NAME;
+			ejtt.deployment.deployViaEmbJopr(APP_TYPE, appFilePath);
+
+			// Click on the app link.
+			ContentTableRow appRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(DEPLOYABLE_NAME);
+			appRow.getLinkByLabel(DEPLOYABLE_NAME).click();
+
+
+			// Check the values in info table(s)
+
+			// General Properties
+			HtmlTable genpropTable = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("General Properties").getElement();
+			ContentInfoTable infoTable = ejtt.getContentInfoTable(genpropTable);
+			Properties props = infoTable.getProperties();
+
+			// Name
+			assertEquals(DEPLOYABLE_NAME, props.getProperty("Name").trim());
+			// Version: "--"
+			// Description: "a standalone EJB 2.x application"
+
+
+			// Traits
+			infoTable = ejtt.getContentInfoTable(
+							ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Traits").getElement());
+			props = infoTable.getProperties();
+
+			// Path
+			String path = ejtt.getDeployDir() + "/" + DEPLOYABLE_NAME;
+			assertEquals(path, props.getProperty("Path").trim());
+
+			// Exploded
+			assertEquals("no", props.getProperty("Exploded?").trim());
+
+			/* Currently hidden.
+			// Metrics Summary
+			HtmlTable summaryTable = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Numeric Metrics").getElement();
+			infoTable = ejtt.getContentInfoTable(summaryTable);
+			/**/
+
 		} finally {
-			undeployEJB(REDEPLOY_EJB2_JAR);
+			try {
+				ejtt.deployment.undeployViaEmbJopr(APP_TYPE, DEPLOYABLE_NAME);
+			} catch (Exception ex) {
+				log.error("Caught exception when undeploying: " + ex, ex);
+			}
 		}
+
 	}
 
+	/**
+	 *
+	 */
+	public void testEjb20MetricsTab() throws EmbJoprTestException, IOException {
 
-	// Helpers
-	private void undeployEJB(String ejbFileName)
-					throws IOException, HtmlElementNotFoundException, ActionNotAvailableException {
+		final String DEPLOYABLE_NAME = BASIC_EJB2;
 
-		// Navigate to Embedded EJB 2.x Applications
-		ejtt.getNavTree().getNodeLink(NAV_EJB2).click();
+		try {
 
-		ejtt.getTabMenu().clickSummaryTab();
+			// Deploy the APP
+			String appFilePath = ejtt.getTestDataDir() + "/"+APP_TYPE.getDataDir()+"/" + DEPLOYABLE_NAME;
+			ejtt.deployment.deployViaEmbJopr(APP_TYPE, appFilePath);
 
-		// Find the row containing the deployable. Use the pagination if needed.
-		ContentTableRow appRow = ejtt.getTabMenu().getTabContentBox().
-						findLinkRowInDataTableUsingPagination(ejbFileName);
+			// Click on the app link.
+			ContentTableRow appRow = ejtt.getDefaultContentTable().getFirstRowContainingLink(DEPLOYABLE_NAME);
+			appRow.getLinkByLabel(DEPLOYABLE_NAME).click();
 
-		if (null == appRow) {
-			log.warn("Can't find row with Ejb 2.x to undeploy: " + ejbFileName);
-			return;
-		}
+			// Switch to the Metrics tab.
+			ejtt.tabMenu.getTabByID(METRICS_TAB).click();
 
-		appRow.getButtonByLabel("Delete").click();
 
-		// Log the message (with prefix of potential warning)
-		ejtt.logServerMessage("Something went wrong with undeploy: ");
+			// Check the values in info table(s)
 
-		// Sleep for 3 sec. TODO: write some waitForUndeployed(), as negation of opposite.
-		ejtt.sleep(2000);
+			// General Properties
+			HtmlTable genpropTable = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("General Properties").getElement();
+			ContentInfoTable infoTable = ejtt.getContentInfoTable(genpropTable);
+			Properties props = infoTable.getProperties();
 
+			// Traits
+			infoTable = ejtt.getContentInfoTable(
+							ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Traits").getElement());
+			props = infoTable.getProperties();
+
+			// Path
+			String path = ejtt.getDeployDir() + "/" + DEPLOYABLE_NAME;
+			assertEquals(path, props.getProperty("Path").trim());
+
+
+			/* Currently no num metrics..
+			// Metrics Summary
+			HtmlTable summaryTable = ejtt.getTabMenu().getTabContentBox().getTableUnderHeader("Numeric Metrics").getElement();
+			infoTable = ejtt.getContentInfoTable(summaryTable);
+			/**/
+
+
+			// Finally, click the Refresh button.
+			String xPath = ".//input[normalize-space(value)='Refresh']";
+			HtmlInput button = ejtt.tabMenu.getTabContentBox().getElement().getFirstByXPath(xPath);
+			if( null == button )
+				throw new HtmlElementNotFoundException("Refresh button not found using XPath: "+xPath);
+
+			button.click();
+
+			// Check that we are still on Metrics tab.
+			assertTrue( ejtt.tabMenu.isTabActiveByID(METRICS_TAB) );
+
+
+		} finally {
+			try {
+				ejtt.deployment.undeployViaEmbJopr(APP_TYPE, DEPLOYABLE_NAME);
+			} catch (Exception ex) {
+				log.error("Caught exception when undeploying: " + ex, ex);
+			}
+		}
+
 	}
 
-	private void deployEJB(String ejbFilePath)
-					throws IOException, HtmlElementNotFoundException {
-		if (!(new File(ejbFilePath)).exists()) {
-			throw new FileNotFoundException(ejbFilePath);
+
+
+
+
+
+
+
+
+	/**
+	 * Stops and Starts an EJB.
+	 *
+	 * Was failing because of EMBJOPR-133.
+	 * Now FAILS because of EMBJOPR-172.
+	 */
+	public void testEjbStopAndStart() throws IOException, EmbJoprTestException
+	{
+		final String DEPLOYABLE_NAME = BASIC_EJB2;
+
+
+		// Deploy the APP.
+		String appfilePath = ejtt.getTestDataDir() + "/"+APP_TYPE.getDataDir()+"/"+DEPLOYABLE_NAME;
+		ejtt.deployment.deployViaEmbJopr(APP_TYPE, DEPLOYABLE_NAME);
+
+
+		try {
+
+			// Wait until app is UP
+			ejtt.getNavTree().getNodeByLabel(APP_TYPE.getNavTreeLabel()).click();
+			ejtt.deployment.waitActivelyForDeployment(APP_TYPE, DEPLOYABLE_NAME,
+							3000, 15, this);
+
+			// 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();
+
+			// Wait for the op to finish and check the final status.
+			ejtt.operations.waitActivelyForOperationToFinish("Stop", 1500, 5);
+			assertTrue( ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful() );
+
+
+
+			// Click the Start button.
+			ejtt.tabMenu.getTabContentBox().getButtonByLabel("Start").click();
+			ejtt.operations.waitActivelyForOperationToFinish("Start", 1500, 5);
+
 		}
+		finally {
+			try {
+				ejtt.deployment.undeployViaEmbJopr(APP_TYPE, DEPLOYABLE_NAME);
+			}catch( Exception ex ){
+				log.error("Caught exception when undeploying: "+ex, ex);
+			}
+		}
+	}
 
-		log.info("Deploying: " + ejbFilePath);
 
-		// Navigate to Embedded EJB 2 Applications
-		ejtt.getNavTree().getNodeLink(AppConstants.DeployableTypes.EJB2.getNavTreeLabel()).click();
+	/**
+	 * Restarts the EJB in Control tab.
+	 */
+	public void testEjbRestart() throws IOException, EmbJoprTestException
+	{
+		final String DEPLOYABLE_NAME = BASIC_EJB2;
 
-		// 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");
+		// Deploy the app.
+		String appFilePath = ejtt.getTestDataDir() + "/"+APP_TYPE.getDataDir()+"/"+DEPLOYABLE_NAME;
+		ejtt.deployment.deployViaEmbJopr(APP_TYPE, appFilePath);
 
-		// Log server message.
-		ejtt.logServerMessage();
+		try {
 
-		// Todo: Write some waitUntilDeployed().
-		ejtt.sleep(2000);
+			// Wait until app is UP
+			ejtt.getNavTree().getNodeByLabel(APP_TYPE.getNavTreeLabel()).click();
+			ejtt.deployment.waitActivelyForDeployment(APP_TYPE, DEPLOYABLE_NAME,
+							3000, 15, this);
 
+
+			// Navigate to the 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();
+
+			// Wait for the op to finish and check the final status.
+			ejtt.operations.waitActivelyForOperationToFinish("Restart", 1500, 5);
+			assertTrue( ejtt.getTabMenu().getTabContentBox().getOperationsHistoryTable().wasLastOperationSuccesful() );
+
+		}
+		finally {
+			try {
+				ejtt.deployment.undeployViaEmbJopr(APP_TYPE, DEPLOYABLE_NAME);
+			}catch( Exception ex ){
+				log.error("Caught exception when undeploying: "+ex, ex);
+			}
+		}
 	}
+
+
+
+
+
 }// class
 
 




More information about the embjopr-commits mailing list