[embjopr-commits] EMBJOPR SVN: r238 - 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 Mar 17 18:18:25 EDT 2009


Author: ozizka at redhat.com
Date: 2009-03-17 18:18:25 -0400 (Tue, 17 Mar 2009)
New Revision: 238

Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.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/EmbJoprTestToolkit.java
Log:
War test updated, EJTT: Deployment part created with deploy/undeploy methods.

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java	2009-03-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/AppConstants.java	2009-03-17 22:18:25 UTC (rev 238)
@@ -28,19 +28,25 @@
 		public static final String SYSPROP_TESTDATA_DIR = "jsfunit.testdata";
 
 
+
+
 		/**
 		 * Information about deployable types -
-		 * navigation tree labels, archive extensions, and XML descriptor suffixes.
+		 * navigation tree labels, archive extensions, 
+		 * XML descriptor suffixes, and MIME type.
 		 */
 		public enum DeployableTypes {
 
-			EAR(AppConstants.NAV_EAR, ".ear", null),
-			WAR(AppConstants.NAV_WAR, ".war", null),
-			EJB(AppConstants.NAV_EJB, ".jar", null),
-			SAR(AppConstants.NAV_SAR, ".sar", "-service.xml"),
-			RAR(AppConstants.NAV_RAR, ".rar", null),
-			MC_BEAN(AppConstants.NAV_MC, "", null);
+			// Mandatory: first, fourth
+			EAR(AppConstants.NAV_EAR, ".ear", null, "application/ear"),
+			WAR(AppConstants.NAV_WAR, ".war", null, "application/war"),
+			EJB(AppConstants.NAV_EJB, ".jar", null, "	application/java-archive"),
+			SAR(AppConstants.NAV_SAR, ".sar", "-service.xml", "application/sar"),
+			RAR(AppConstants.NAV_RAR, ".rar", null, "application/rar"),
+			MC_BEAN(AppConstants.NAV_MC, "",  null, "application/java-archive");
 
+			// -- Fields --
+
 			protected final String navTreeLabel;
 			public String getNavTreeLabel() {			return navTreeLabel;		}
 
@@ -50,21 +56,33 @@
 			protected final String suffix;
 			public String getSuffix() {				return suffix;			}
 
+			protected final String mimeType;
+			public String getMimeType() {			return mimeType;		}
 
-			private DeployableTypes(String navTreeLabel, String extension, String suffix) {
+
+
+			// -- Constructors --
+
+			private DeployableTypes(
+							String navTreeLabel, String extension,
+							String suffix, String mimeType)
+			{
 				this.navTreeLabel = navTreeLabel;
 				this.extension = extension;
 				this.suffix = suffix;
+				this.mimeType = mimeType;
 			}
 
+
 		}// enum DeployableTypes
-		
 
 
+		/** Several ways how to deploy / undeploy. */
 		public enum DeploymentMeans {
 			VIA_EMBJOPR,
 			VIA_FILESYSTEM,
-			VIA_JMX
+			VIA_JMX,
+			VIA_MANAGEMENTVIEW
 		}
 
 

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java	2009-03-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/ApplicationTestBaseAS5.java	2009-03-17 22:18:25 UTC (rev 238)
@@ -22,16 +22,10 @@
 package org.jboss.jopr.jsfunit;
 
 import java.io.IOException;
-import java.net.URL;
 import java.util.*;
 import javax.management.*;
-import com.gargoylesoftware.htmlunit.*;
 import com.gargoylesoftware.htmlunit.html.*;
 import org.jboss.mx.util.MBeanServerLocator;
-import org.jboss.jopr.jsfunit.exceptions.*;
-import org.apache.commons.lang.StringUtils;
-import org.apache.commons.lang.math.NumberUtils;
-import org.w3c.dom.Element;
 
 
 

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-03-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/EarTest.java	2009-03-17 22:18:25 UTC (rev 238)
@@ -914,7 +914,7 @@
 		ejtt.sleep( 2000 );
 
 		// Log the message
-		logServerMessage("Something went wrong with deploy: ");
+		ejtt.logServerMessage("Something went wrong with deploy: ");
 	}
 
 	private void undeployEar( String earFileName ) throws IOException, HtmlElementNotFoundException, ActionNotAvailableException
@@ -923,33 +923,19 @@
 		// Navigate to Enterprise Archives
 		ejtt.getNavTree().getNodeLink(NAV_EAR).click();
 
-		ejtt.getTabMenu().clickTab("Summary");
+		ejtt.getTabMenu().clickSummaryTab();
 
 		HtmlButtonInput deleteButton = getAppDeleteButton( earFileName );
 		deleteButton.click();
 
-		// Log the message
-		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.
+		// Sleep for 3 sec.  TODO: write some waitForUndeployed()
 		ejtt.sleep( 3000 );
 
 	}
 
 
-	private void logServerMessage(){ logServerMessage(""); }
 
-	private void logServerMessage( String warnPrefix ){
-		if( server.getFacesMessages().hasNext() ){
-			FacesMessage msg = server.getFacesMessages().next();
-			if( msg.getSeverity() == FacesMessage.SEVERITY_INFO ){
-				log.info( msg.getSummary() +"\n"+ msg.getDetail() );
-			}else{
-				log.warn( warnPrefix + msg.getSummary() +"\n"+ msg.getDetail() );
-			}
-		}
-	}
-
-
-
 }// class EarTest

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-03-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/WarTest.java	2009-03-17 22:18:25 UTC (rev 238)
@@ -27,11 +27,13 @@
 import java.io.IOException;
 import junit.framework.Test;
 import junit.framework.TestSuite;
-import javax.faces.application.FacesMessage;
 import javax.faces.context.FacesContext;
 import javax.servlet.http.HttpServletRequest;
 import com.gargoylesoftware.htmlunit.WebClient;
-import org.jboss.jopr.jsfunit.exceptions.DeploymentException;
+import java.io.File;
+import java.io.FileNotFoundException;
+import org.jboss.jopr.jsfunit.exceptions.ActionNotAvailableException;
+import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
 
 
 
@@ -62,57 +64,94 @@
 	 *      deployed.  Undeploy the archive.
 	 *
 	 */
-	public void testBasicWarDeployment() throws IOException
+	public void testBasicWarDeployment() 
+					throws IOException, HtmlElementNotFoundException, ActionNotAvailableException
 	{
 
-		deployWAR();
+		String filePath = ejtt.getTestDataDir() + "/war/"+BASIC_WAR;
 
-		// Check the success message.
-		String expectedMessage = "Resource hellothere.war created successfully!";
-		checkClientAndServerMessages(expectedMessage, expectedMessage, false);
+		try {
+			deployWAR( filePath );
 
-		// Use JMX to assert that the WAR really did deploy successfully
-		assertTrue("WAR was not deployed according to JMX", isWarDeployed("hellothere.war"));
+			// Check the success message.
+			String expectedMessage = "Resource hellothere.war created successfully!";
+			checkClientAndServerMessages(expectedMessage, expectedMessage, false);
 
-		// 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();
-		WebClient webClient = new WebClient();
-		HtmlPage page = (HtmlPage)webClient.getPage("http://localhost:" + port + "/hellothere/hello.jsp");
-		assertTrue(page.asText().contains("HELLO WORLD"));
+			// Use JMX to assert that the WAR really did deploy successfully
+			assertTrue("WAR was not deployed according to JMX", isWarDeployed(BASIC_WAR));
 
-		// Undeploy the WAR
-		HtmlButtonInput deleteButton = getAppDeleteButton("hellothere.war");
-		deleteButton.click();
+			// 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();
+			WebClient webClient = new WebClient();
+			HtmlPage page = (HtmlPage)webClient.getPage("http://localhost:" + port + "/hellothere/hello.jsp");
+			assertTrue(page.asText().contains("HELLO WORLD"));
 
-		// This assert doesn't work.  jopr does remove the WAR, but for some
-		// reason, JBoss doesn't undeploy the MBeans
-		// JBAS-XXXX
-		//assertFalse(isWarDeployed("hellothere.war"));
+			// Undeploy the WAR
+			HtmlButtonInput deleteButton = getAppDeleteButton(BASIC_WAR);
+			deleteButton.click();
+
+			// This assert doesn't work.  jopr does remove the WAR, but for some
+			// reason, JBoss doesn't undeploy the MBeans
+			// JBAS-XXXX
+			//assertFalse(isWarDeployed(BASIC_WAR));
+		}
+		finally {
+			undeployWAR(BASIC_WAR);
+		}
 	}
 
 
 	/**
 	 * Deploys WAR.
 	 */
-	private void deployWAR() throws IOException {
-		// click the nave tree
-		HtmlAnchor warLink = getNavTreeLink(NAV_WAR);
-		warLink.click();
+	private void deployWAR( String warFilePath )
+					throws IOException, HtmlElementNotFoundException
+	{
+		if( !(new File(warFilePath)).exists())
+			throw new FileNotFoundException(warFilePath);
+		
+		log.info("Deploying: "+warFilePath);
 
+		// Navigate to Enterprise Archives
+		//ejtt.getNavTree().getNodeLink(NAV_WAR).click();
+		ejtt.getNavTree().getNodeLink(AppConstants.DeployableTypes.WAR.getNavTreeLabel()).click();
+
 		// click on the "Add new resource" button
 		client.click("actionHeaderForm:addNewContent");  // 404 if setThrowExceptionOnFailingStatusCode(true) above
 
-		// upload hellothere.war
+		// Upload the file
 		HtmlFileInput fileInput = (HtmlFileInput)client.getElement("createContentForm:file");
 		fileInput.setContentType("application/war");
-		fileInput.setValueAttribute(System.getProperty("jsfunit.testdata") + "/war/hellothere.war");
+		fileInput.setValueAttribute(warFilePath);
 		client.click("createContentForm:addButton");
+		ejtt.sleep( 2000 );
 
 	}
 
+
+	private void undeployWAR( String warFileName )
+					throws IOException, HtmlElementNotFoundException, ActionNotAvailableException
+	{
+
+		// Navigate to Enterprise Archives
+		ejtt.getNavTree().getNodeLink(NAV_EAR).click();
+
+		ejtt.getTabMenu().clickSummaryTab();
+
+		HtmlButtonInput deleteButton = getAppDeleteButton( warFileName );
+		deleteButton.click();
+
+		// Log the message (with prefix of potential warning)
+		ejtt.logServerMessage("Something went wrong with undeploy: ");
+
+		// Sleep for 3 sec. TODO: write some waitForUndeployed()
+		ejtt.sleep( 3000 );
+
+	}
+
 }
 

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-03-17 19:32:30 UTC (rev 237)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/util/EmbJoprTestToolkit.java	2009-03-17 22:18:25 UTC (rev 238)
@@ -9,12 +9,16 @@
 import org.jboss.jopr.jsfunit.exceptions.*;
 import com.gargoylesoftware.htmlunit.html.*;
 import com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine;
+import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URL;
+import javax.faces.application.FacesMessage;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.math.NumberUtils;
 import org.jboss.jopr.jsfunit.AppConstants;
 import org.jboss.jsfunit.jsfsession.*;
+import org.jboss.logging.Logger;
 import org.mozilla.javascript.NativeFunction;
 import org.w3c.dom.Element;
 
@@ -28,10 +32,11 @@
  */
 public class EmbJoprTestToolkit {
 
+	private Logger log = Logger.getLogger(EmbJoprTestToolkit.class.getName());
+
 	protected JSFClientSession client;
 	protected JSFServerSession server;
 	private EmbJoprTestToolkit selfEjtt; // For closures.
-
 	public JSFClientSession getClient() { return client; }
 	public JSFServerSession getServer() { return server; }
 
@@ -1204,6 +1209,109 @@
 
 
 
+
+	public void logServerMessage(){ logServerMessage(""); }
+
+	public void logServerMessage( String warnPrefix ){
+		if( server.getFacesMessages().hasNext() ){
+			FacesMessage msg = server.getFacesMessages().next();
+			if( msg.getSeverity() == FacesMessage.SEVERITY_INFO ){
+				log.info( msg.getSummary() +"\n"+ msg.getDetail() );
+			}else{
+				log.warn( warnPrefix + msg.getSummary() +"\n"+ msg.getDetail() );
+			}
+		}
+	}
+
+
+
+	public class Deployment {
+
+		// TODO: Shortcuts:
+		/*
+		private void deployWAR( String warFilePath ){
+
+		}
+
+		private void undeployWAR( String warFileName ){
+
+		}
+
+		private void deployEAR( String warFilePath ){
+
+		}
+
+		private void undeployEAR( String warFileName ){
+
+		}
+		// Etc. */
+
+
+
+		/**
+		 * Deploys the deployable using EmbJopr's web UI.
+		 *
+		 * @param type  Type of the deployable - EAR, SAR, WAR, ...
+		 */
+		private void deployViaEmbJopr( AppConstants.DeployableTypes type, String filePath )
+					throws IOException, HtmlElementNotFoundException
+		{
+			if( !(new File(filePath)).exists())
+				throw new FileNotFoundException(filePath);
+
+			log.info("Deploying: "+filePath);
+
+			// Navigate to appropriate page
+			getNavTree().getNodeLink(type.getNavTreeLabel()).click();
+
+			// 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(type.getMimeType());
+			fileInput.setValueAttribute( filePath );
+			client.click("createContentForm:addButton");
+			sleep( 2000 );
+
+		}// deployViaEmbJopr()
+
+
+
+		/**
+		 * Undeploys the deployable using EmbJopr's web UI.
+		 *
+		 * @param type  Type of the deployable - EAR, SAR, WAR, ...
+		 */
+		private void undeployViaEmbJopr( AppConstants.DeployableTypes type, String fileName )
+						throws IOException, HtmlElementNotFoundException, ActionNotAvailableException, ActionOutOfSyncException
+		{
+
+			// Navigate to Enterprise Archives
+			getNavTree().getNodeLink(type.getNavTreeLabel()).click();
+
+			getTabMenu().clickSummaryTab();
+
+			// Not tested 
+			HtmlButtonInput deleteButton = (HtmlButtonInput) getTabMenu().getTabContentBox()
+							.getFirstTable().getFirstRowContainingText(fileName).getButtonByLabel("Delete");
+			deleteButton.click();
+
+			// Log the message (with prefix of potential warning)
+			logServerMessage("Something went wrong with undeploy: ");
+
+			// Sleep for 3 sec. TODO: write some waitForUndeployed()
+			sleep( 3000 );
+
+		}// undeployViaEmbJopr()
+
+
+	}
+
+
+
+
+
 	// TODO
 	protected class JMXDeploymentInfo {
 




More information about the embjopr-commits mailing list