[embjopr-commits] EMBJOPR SVN: r156 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directories.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Tue Feb 17 16:32:24 EST 2009


Author: ozizka at redhat.com
Date: 2009-02-17 16:32:24 -0500 (Tue, 17 Feb 2009)
New Revision: 156

Added:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/DeploymentException.java
Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java
Log:
Added logging to setUp() to let us find start of the test  more easily

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java	2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java	2009-02-17 21:32:24 UTC (rev 156)
@@ -22,7 +22,9 @@
 package org.jboss.jopr.jsfunit;
 
 import com.gargoylesoftware.htmlunit.html.*;
+import java.io.IOException;
 import java.util.Set;
+import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 import org.jboss.mx.util.MBeanServerLocator;
@@ -49,36 +51,72 @@
 	}
 
 
+	/**
+	 * This method should query the JMX server and decide whether the given
+	 * MBean displays deployed resource.
+	 *
+	 *
+	 * TODO: Move to EmbJoprTestCase?
+	 *
+	 * @param deploymentMBean  Name of the MBean to examine. Differs between AS4 and 5.
+	 * @return true  if the MBean indicates that the resource is deployed, false otherwise.
+	 * @throws javax.management.JMException  upon JMX related error, including invalid
+	 *                 or non-existent MBean / attribute name.
+	 * @throws java.io.IOException  upon I/O error.
+	 */
+	protected boolean isMBeanStateDeployedImpl(ObjectName mBeanName)  throws JMException, IOException
+	{
+		JMXUtils jmxUtils = JMXUtils.getInstanceForLocalJBoss();
+		Object state = jmxUtils.getMBeanAttribute(mBeanName, "State");
+		return ("DEPLOYED".equals( state.toString() ));
+	}
 
-	public boolean isEJBDeployed(String ejbJarName) throws RuntimeException
+	protected boolean isMBeanStateDeployedImpl(String mBeanName)  throws JMException, IOException {
+		return isMBeanStateDeployedImpl( new ObjectName(mBeanName) );
+	}
+
+
+	/**
+	 * Queries JBoss via JMX for given query and checks whether the
+	 * StateString property of the first result is "Started".
+	 *
+	 * @param mBeanName
+	 * @return true if the StateString property of the first MBean found is "Started".
+	 * @throws javax.management.JMException
+	 * @throws java.io.IOException
+	 */
+	protected boolean isMBeanStateDeployedByQuery(String mBeanName)  throws JMException, IOException
 	{
+		log.info("Querying JMX: "+mBeanName);
 
-		try {
-			MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
-			ObjectName objName =
-							new ObjectName("jboss.j2ee:module=\"" +
-							ejbJarName + "\",service=EjbModule");
-			Set mBeans = jmxServer.queryNames(objName, null);
+		ObjectName objName =	new ObjectName(mBeanName);
 
-			if (mBeans.size() != 1) {
-				return false;
-			}
+		MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
+		Set mBeans = jmxServer.queryNames(objName, null);
+		if (mBeans.size() != 1) {
+			return false;
+		}
+		ObjectName deploymentMBean = (ObjectName) mBeans.iterator().next();
+		// Returns org.jboss.deployers.spi.DeploymentState.
+		Object state = jmxServer.getAttribute(deploymentMBean, "State");
+		return "DEPLOYED".equals(state.toString()) || "3".equals(state.toString());
+	}
 
-			ObjectName deploymentMBean = (ObjectName) mBeans.iterator().next();
 
-			// returns org.jboss.deployers.spi.DeploymentState
-			Object state = jmxServer.getAttribute(deploymentMBean, "StateString");
 
-			return "Started".equals(state.toString());
-
-		} catch (Exception e) {
+	public boolean isEJBDeployed(String ejbJarName) throws RuntimeException
+	{
+		try {
+			String mBeanName = "jboss.j2ee:module=\""+ejbJarName+"\",service=EjbModule";
+			return isMBeanStateDeployedByQuery(mBeanName);
+		}
+		catch (Exception e) {
 			throw new RuntimeException(e);
 		}
 	}
 
 	public boolean isWarDeployed(String warName) throws RuntimeException
 	{
-
 		if (warName.endsWith(".war")) {
 			warName = warName.substring(0, warName.lastIndexOf(".war"));
 		} else {
@@ -86,52 +124,22 @@
 		}
 
 		try {
-			MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
-			ObjectName objName =
-							new ObjectName("jboss.deployment:id=\"jboss.web.deployment:war=/" +
-							warName + "\",*");
-			Set mBeans = jmxServer.queryNames(objName, null);
-
-			if (mBeans.size() != 1) {
-				return false;
-			}
-
-			ObjectName deploymentMBean = (ObjectName) mBeans.iterator().next();
-
-			// returns org.jboss.deployers.spi.DeploymentState
-			Object state = jmxServer.getAttribute(deploymentMBean, "State");
-
-			return "DEPLOYED".equals(state.toString());
-
-		} catch (Exception e) {
+			String query = "jboss.deployment:id=\"jboss.web.deployment:war=/"+warName+"\",*";
+			return isMBeanStateDeployedByQuery(query);
+		}
+		catch (Exception e) {
 			throw new RuntimeException(e);
 		}
 	}
 
 	public boolean isEarDeployed(String earName) throws RuntimeException
 	{
-
 		try {
-
-			MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
-			ObjectName objName =
-							new ObjectName("jboss.deployment:id=\"vfszip:" +
-							System.getProperty("jsfunit.deploy.dir") + "/" + earName + "\",*");
-
-			Set mBeans = jmxServer.queryNames(objName, null);
-
-			if (mBeans.size() != 1) {
-				return false;
-			}
-
-			ObjectName deploymentMBean = (ObjectName) mBeans.iterator().next();
-
-			// returns org.jboss.deployers.spi.DeploymentState
-			Object state = jmxServer.getAttribute(deploymentMBean, "State");
-
-			return "DEPLOYED".equals(state.toString());
-
-		} catch (Exception e) {
+			String query = "jboss.deployment:id=\"vfszip:" +
+							System.getProperty("jsfunit.deploy.dir") + "/" + earName + "\",*";
+			return isMBeanStateDeployedByQuery(query);
+		}
+		catch (Exception e) {
 			throw new RuntimeException(e);
 		}
 	}

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java	2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DebugUtils.java	2009-02-17 21:32:24 UTC (rev 156)
@@ -59,6 +59,26 @@
 
 	}
 
+	/**
+	 *
+	 * @return
+	 */
+	public static String getCurrentMethodFullName() {
 
+		StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+		StackTraceElement ste = stackTrace[3];
+		return ste.getClassName() +"#"+ ste.getMethodName();
 
+		/*
+		StringBuilder sb = new StringBuilder();
+		for( StackTraceElement ste : stackTrace ){
+			sb.append(" -- ").append( ste.getClassName() ).append("#").append( ste.getMethodName() ).append("\n");
+		}
+		return sb.toString();
+		*/
+
+	}
+
+
+
 }

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java	2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java	2009-02-17 21:32:24 UTC (rev 156)
@@ -103,8 +103,8 @@
         this.client = jsfSession.getJSFClientSession();
         this.server = jsfSession.getJSFServerSession(); 
 
-    }	
-
+    }
+		
     /**
      * Need a standard JSFUnit API to replace this code
      */

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java	2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/JMXUtils.java	2009-02-17 21:32:24 UTC (rev 156)
@@ -1,18 +1,17 @@
 package org.jboss.jopr.jsfunit;
 
 import java.io.IOException;
-import java.util.Comparator;
-import java.util.Hashtable;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.util.*;
 import javax.management.*;
 import javax.naming.*;
 import org.jboss.mx.util.MBeanServerLocator;
 
 /**
  * JMX utilities.
- * TODO: Write set, invoke if needed. Possibly also remote JMX support (will we ever need it?).
+ *
+ * TODO: Write set(), invoke() if needed.
+ * Possibly also remote JMX support (will we ever need it?).
+ * 
  * @author ondra
  */
 public final class JMXUtils{


Property changes on: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5
___________________________________________________________________
Name: svn:ignore
   + JMXUtilsAS5.java


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-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java	2009-02-17 21:32:24 UTC (rev 156)
@@ -25,17 +25,9 @@
 import org.jboss.jopr.jsfunit.*;
 import com.gargoylesoftware.htmlunit.html.*;
 import java.io.IOException;
-import java.util.*;
 import junit.framework.Test;
 import junit.framework.TestSuite;
-import java.util.Map;
 import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
-import javax.servlet.http.HttpServletRequest;
-import com.gargoylesoftware.htmlunit.WebClient;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import org.jboss.mx.util.MBeanServerLocator;
 
 
 
@@ -91,9 +83,9 @@
 		assertTrue(successMessage.getDetail().contains("eardeployment.ear created successfully"));
 
 		// Use JMX to assert that the EAR components really did deploy successfully
-		assertTrue(isEarDeployed("eardeployment.ear"));
-		assertTrue(isEJBDeployed("sessiona.jar"));
-		assertTrue(isEJBDeployed("sessionb.jar"));
+		assertTrue("JMX doesn't report EAR as exposed: eardeployment.ear", isEarDeployed("eardeployment.ear"));
+		assertTrue("JMX doesn't report EJB sessiona.jar as exposed.", isEJBDeployed("sessiona.jar"));
+		assertTrue("JMX doesn't report EJB sessionb.jar as exposed.", isEJBDeployed("sessionb.jar"));
 
 		// Undeploy the EAR
 		HtmlButtonInput deleteButton = getAppDeleteButton("eardeployment.ear");

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java	2009-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EjbTest.java	2009-02-17 21:32:24 UTC (rev 156)
@@ -22,14 +22,15 @@
 
 package org.jboss.jopr.jsfunit.as5;
 
-import java.util.logging.Level;
-import java.util.logging.Logger;
 import org.jboss.jopr.jsfunit.*;
 import com.gargoylesoftware.htmlunit.html.*;
+import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import javax.faces.application.FacesMessage;
+import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
 
 
 
@@ -61,8 +62,10 @@
          *
          */
 
-	public void testBasicEjbDeployment() throws IOException
+	public void testBasicEjbDeployment() throws IOException, EmbJoprTestException
 	{
+		log.info(DebugUtils.getCurrentMethodFullName());
+
 		// Navigate to EJB Applications
 		HtmlAnchor ejbLink = getNavTreeLink(NAV_EJB);
 		ejbLink.click();
@@ -70,10 +73,16 @@
 		// click on the "Add new resource" button
 		client.click("actionHeaderForm:addNewContent");  // 404 if setThrowExceptionOnFailingStatusCode(true) above
 
-		// upload ejb 
+		String filePath = System.getProperty("jsfunit.testdata") + "/ejb/"+BASIC_JAR;
+		log.info("Uploading EJB archive: "+filePath);
+		File uploadFile = new File(filePath);
+		if( !uploadFile.exists() )
+			throw new EmbJoprTestException("Can't find EJB file to upload: '"+filePath+"'");
+
+		// upload ejb
 		HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
 		fileInput.setContentType("application/ejb");
-		fileInput.setValueAttribute(System.getProperty("jsfunit.testdata") + "/ejb/BASIC_JAR");
+		fileInput.setValueAttribute(filePath);
 		client.click("createContentForm:addButton");
 
 		log.info("HTTP status after EJB upload: "+client.getContentPage().getWebResponse().getStatusCode());

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-02-17 17:14:00 UTC (rev 155)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java	2009-02-17 21:32:24 UTC (rev 156)
@@ -25,17 +25,13 @@
 import org.jboss.jopr.jsfunit.*;
 import com.gargoylesoftware.htmlunit.html.*;
 import java.io.IOException;
-import java.util.*;
 import junit.framework.Test;
 import junit.framework.TestSuite;
-import java.util.Map;
 import javax.faces.application.FacesMessage;
 import javax.faces.context.FacesContext;
 import javax.servlet.http.HttpServletRequest;
 import com.gargoylesoftware.htmlunit.WebClient;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.jopr.jsfunit.exceptions.DeploymentException;
 
 
 
@@ -58,45 +54,29 @@
 	}
 
 
-        /*
-         * testName: testBasicWarDeployment
-         * assertion:  verify basic deployment of an EJB JAR.
-         * test Strategy:  Navigate to WAR Applications.
-         *      Add a new resource.  Verify the resource was successfully
-         *      deployed.  Undeploy the archive.
-         *
-         */
-
-
+	/*
+	 * testName: testBasicWarDeployment
+	 * assertion:  verify basic deployment of an EJB JAR.
+	 * test Strategy:  Navigate to WAR Applications.
+	 *      Add a new resource.  Verify the resource was successfully
+	 *      deployed.  Undeploy the archive.
+	 *
+	 */
 	public void testBasicWarDeployment() throws IOException
 	{
-		// click the nave tree
-		HtmlAnchor warLink = getNavTreeLink(NAV_WAR);
-		warLink.click();
 
-		// click on the "Add new resource" button
-		client.click("actionHeaderForm:addNewContent");  // 404 if setThrowExceptionOnFailingStatusCode(true) above
+		deployWAR();
 
-		// upload hellothere.war
-		HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
-		fileInput.setContentType("application/war");
-		fileInput.setValueAttribute(System.getProperty("jsfunit.testdata") + "/war/hellothere.war");
-		client.click("createContentForm:addButton");
+		// Check the success message.
+		String expectedMessage = "Resource hellothere.war created successfully!";
+		checkClientAndServerMessages(expectedMessage, expectedMessage, false);
 
-		// assert that the success message appeared on the client side
-		assertTrue(client.getPageAsText().contains("Resource hellothere.war created successfully!"));
-
-		// assert text and sevrity 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 hellothere.war created successfully!"));
-
 		// Use JMX to assert that the WAR really did deploy successfully
-		assertTrue(isWarDeployed("hellothere.war"));
+		assertTrue("WAR was not deployed according to JMX", isWarDeployed("hellothere.war"));
 
 		// use HtmlUnit to test the newly deployed war in a new WebClient session
 		// note that I have full access to the FacesContext and the previous request
+		//Thread.sleep(3000); // Give JBoss some time to launch the webapp.
 		HttpServletRequest request =
 			 (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
 		int port = request.getLocalPort();
@@ -114,5 +94,25 @@
 		//assertFalse(isWarDeployed("hellothere.war"));
 	}
 
+
+	/**
+	 * Deploys WAR.
+	 */
+	private void deployWAR() throws IOException {
+		// click the nave tree
+		HtmlAnchor warLink = getNavTreeLink(NAV_WAR);
+		warLink.click();
+
+		// click on the "Add new resource" button
+		client.click("actionHeaderForm:addNewContent");  // 404 if setThrowExceptionOnFailingStatusCode(true) above
+
+		// upload hellothere.war
+		HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
+		fileInput.setContentType("application/war");
+		fileInput.setValueAttribute(System.getProperty("jsfunit.testdata") + "/war/hellothere.war");
+		client.click("createContentForm:addButton");
+
+	}
+
 }
 

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/DeploymentException.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/DeploymentException.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/exceptions/DeploymentException.java	2009-02-17 21:32:24 UTC (rev 156)
@@ -0,0 +1,30 @@
+package org.jboss.jopr.jsfunit.exceptions;
+
+/**
+ * Signalizes that there was an action performed
+ * that was out of context - e.g. clicking on a button
+ * that was a part of a HTML page that's already gone.
+ *
+ *
+ * @author ondra
+ */
+public class DeploymentException extends EmbJoprTestException {
+
+	public DeploymentException() {
+	}
+
+	public DeploymentException(String message) {
+		super(message);
+	}
+
+	public DeploymentException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+	public DeploymentException(Throwable cause) {
+		super(cause);
+	}
+
+	
+
+}




More information about the embjopr-commits mailing list