Author: kpiwko(a)redhat.com
Date: 2009-08-25 10:57:46 -0400 (Tue, 25 Aug 2009)
New Revision: 11424
Modified:
branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeamGenTest.java
Log:
JBQA-2557
Modified:
branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeamGenTest.java
===================================================================
---
branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeamGenTest.java 2009-08-25
12:29:17 UTC (rev 11423)
+++
branches/community/Seam_2_2/src/test/ftest/seamgen/src/main/org/jboss/seam/test/functional/seamgen/SeamGenTest.java 2009-08-25
14:57:46 UTC (rev 11424)
@@ -25,20 +25,16 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.util.NoSuchElementException;
import java.util.Properties;
+import java.util.StringTokenizer;
-import org.codehaus.cargo.container.ContainerType;
import org.codehaus.cargo.container.InstalledLocalContainer;
import org.codehaus.cargo.container.LocalContainer;
-import org.codehaus.cargo.container.configuration.ConfigurationType;
import org.codehaus.cargo.container.configuration.LocalConfiguration;
import org.codehaus.cargo.container.jboss.JBoss42xInstalledLocalContainer;
import org.codehaus.cargo.container.jboss.JBoss5xInstalledLocalContainer;
import org.codehaus.cargo.container.jboss.JBossExistingLocalConfiguration;
-import org.codehaus.cargo.container.jboss.JBossStandaloneLocalConfiguration;
-import org.codehaus.cargo.generic.DefaultContainerFactory;
-import org.codehaus.cargo.generic.configuration.ConfigurationFactory;
-import org.codehaus.cargo.generic.configuration.DefaultConfigurationFactory;
import org.jboss.seam.test.functional.seamgen.utils.SeamGenAdapter;
import org.openqa.selenium.server.RemoteControlConfiguration;
import org.openqa.selenium.server.SeleniumServer;
@@ -56,31 +52,31 @@
*/
public class SeamGenTest
{
-
+
protected static SeamGenAdapter seamGen;
protected static Properties seamGenProperties;
protected static Properties ftestProperties = new Properties();
-
+
protected static String SEAM_DIR;
protected static String SEAM_FTEST_PROPERTIES_FILE;
protected static String SEAMGEN_BUILDFILE;
protected static String SEAMGEN_PROPERTIES_FILE;
protected static String WORKSPACE;
-
+
// container specific properties
protected static String CONTAINER;
protected static String CONTAINER_LOCATION;
protected static int DEPLOY_TIMEOUT;
-
+
protected static boolean ICEFACES;
protected static boolean WAR;
-
+
protected static boolean DELETE_PROJECT;
protected static boolean CONTROL_CONTAINER;
-
+
protected static String TEST_SEAMGEN_PROPERTIES_FILE;
-
+
// Selenium related constants
protected static String SELENIUM_HOST;
protected static String SELENIUM_BROWSER;
@@ -89,25 +85,26 @@
protected static String SELENIUM_SPEED;
protected static String SELENIUM_TIMEOUT;
protected static long SELENIUM_ICEFACES_WAIT_TIME;
-
+ protected static String SELENIUM_SERVER_ARGS;
+
protected static String OUTPUT_DIR;
-
+
// Test application specific constants
protected static String APP_NAME;
protected static String HOME_PAGE;
-
+
// Selenium server instance
protected static SeleniumServer seleniumServer;
// Container instance
protected static LocalContainer container;
-
+
@BeforeSuite
@Parameters("seam.dir")
public void beforeSuite((a)Optional(".") String seamDir) throws Exception
{
// Seam location
SEAM_DIR = seamDir;
-
+
// ftest configuration file
String relativeLocation = System.getProperty("ftest.config.location");
if (relativeLocation.equals("${ftest.config.location}"))
@@ -121,15 +118,16 @@
SEAMGEN_BUILDFILE = SEAM_DIR + "/seam-gen/build.xml";
SEAMGEN_PROPERTIES_FILE = SEAM_DIR + "/seam-gen/build.properties";
OUTPUT_DIR = SEAM_DIR + "/test-output/functional-framework/";
-
+
loadFtestProperties();
createOutputDir();
startSeleniumServer();
- if (CONTROL_CONTAINER) {
+ if (CONTROL_CONTAINER)
+ {
container = startContainer(CONTAINER, CONTAINER_LOCATION);
}
}
-
+
@AfterSuite
public void afterSuite()
{
@@ -139,7 +137,7 @@
stopContainer(container);
}
}
-
+
@BeforeTest
@Parameters( { "icefaces", "type", "suffix",
"explode" })
public void setUp(@Optional("false") boolean icefaces,
@Optional("ear") String type, @Optional("") String suffix,
@Optional("true") boolean explode) throws Exception
@@ -148,14 +146,14 @@
WAR = type.equalsIgnoreCase("war");
APP_NAME = "seamGenTestApp" + (ICEFACES ? "Ice" :
"Rich") + (WAR ? "War" : "Ear") + (explode ? "E" :
"D") + suffix;
HOME_PAGE = "/" + APP_NAME + "/home.seam";
-
+
setSeamGenProperties();
-
+
seamGen = new SeamGenAdapter(SEAMGEN_BUILDFILE);
seamGen.setExplode(explode);
-
+
}
-
+
@AfterTest
public void tearDown()
{
@@ -168,21 +166,21 @@
seamGen.undeploy();
}
}
-
+
private void loadFtestProperties() throws FileNotFoundException, IOException
{
// load general properties
ftestProperties.load(new FileInputStream(SEAM_FTEST_PROPERTIES_FILE));
-
+
WORKSPACE = ftestProperties.getProperty("workspace.home");
-
+
// container specific
CONTAINER = ftestProperties.getProperty("container",
"jboss5");
CONTAINER_LOCATION = ftestProperties.getProperty(CONTAINER + ".home");
DEPLOY_TIMEOUT = Integer.parseInt(ftestProperties.getProperty(CONTAINER +
".deploy.waittime")) * 1000; // miliseconds
DELETE_PROJECT =
Boolean.valueOf(ftestProperties.getProperty("seamgen.delete.project",
"false"));
CONTROL_CONTAINER =
Boolean.valueOf(ftestProperties.getProperty("seamgen.control.container",
"false"));
-
+
// load selenium constants
SELENIUM_HOST = ftestProperties.getProperty("selenium.host");
SELENIUM_BROWSER = ftestProperties.getProperty("selenium.browser");
@@ -191,14 +189,15 @@
SELENIUM_SPEED = ftestProperties.getProperty("selenium.speed");
SELENIUM_TIMEOUT = ftestProperties.getProperty("selenium.timeout");
SELENIUM_ICEFACES_WAIT_TIME =
Long.valueOf(ftestProperties.getProperty("selenium.icefaces.wait.time",
"2000"));
+ SELENIUM_SERVER_ARGS =
ftestProperties.getProperty("selenium.server.cmd.args");
}
-
+
private void setSeamGenProperties()
{
seamGenProperties = new Properties();
-
+
String[] propertiesToCopy = { "database.type",
"database.exists", "database.drop", "driver.jar",
"driver.license.jar", "hibernate.connection.username",
"hibernate.connection.password", "hibernate.connection.driver_class",
"hibernate.connection.dataSource_class",
"hibernate.cache.provider_class", "hibernate.default_catalog.null",
"hibernate.default_schema.null", "hibernate.dialect",
"hibernate.connection.url", "model.package",
"action.package", "test.package", "richfaces.skin",
"icefaces.home", "jboss.domain" };
-
+
for (String property : propertiesToCopy)
{
if (ftestProperties.get(property) != null)
@@ -206,7 +205,7 @@
seamGenProperties.put(property, ftestProperties.get(property));
}
}
-
+
// override with ftest.properties
seamGenProperties.put("workspace.home", WORKSPACE);
seamGenProperties.put("jboss.home", CONTAINER_LOCATION);
@@ -214,16 +213,85 @@
seamGenProperties.put("project.type", WAR ? "war" :
"ear");
seamGenProperties.put("project.name", APP_NAME);
}
-
+
+ /**
+ * Parses some of Selenium command line arguments stated in ftest.properties.
+ * There is not orthogonality between arguments of command line and
+ * Java configuration interface, so some arguments cannot be set by this method
+ * @param rcc RC configuration to be modified
+ */
+ private void setSeleniumServerProperties(RemoteControlConfiguration rcc)
+ {
+ StringTokenizer parameters = new StringTokenizer(SELENIUM_SERVER_ARGS, "
");
+ try
+ {
+ while (parameters.hasMoreTokens())
+ {
+ String cmd = parameters.nextToken();
+ if ("-firefoxProfileTemplate".equals(cmd))
+ {
+ rcc.setFirefoxProfileTemplate(new File(parameters.nextToken()));
+ }
+ else if("-log".equals(cmd)) {
+ rcc.setLogOutFileName(parameters.nextToken());
+ }
+ else if("-singleWindow".equals(cmd)) {
+ rcc.setMultiWindow(false);
+ }
+ else if("-avoidProxy".equals(cmd)) {
+ rcc.setHonorSystemProxy(false);
+ }
+ else if("-profilesLocation".equals(cmd)) {
+ rcc.setProfilesLocation(new File(parameters.nextToken()));
+ }
+ else if("-trustAllSSLCertificates".equals(cmd)){
+ rcc.setTrustAllSSLCertificates(true);
+ }
+ else if("-interactive".equals(cmd)){
+ rcc.setInteractive(true);
+ }
+ else if("-userExtensions".equals(cmd)){
+ rcc.setUserExtensions(new File(parameters.nextToken()));
+ }
+ // injection modes
+ else if("-proxyInjectionMode".equals(cmd)){
+ rcc.setProxyInjectionModeArg(true);
+ }
+ else if("-dontInjectRegex".equals(cmd) &&
rcc.getProxyInjectionModeArg()) {
+ rcc.setDontInjectRegex(parameters.nextToken());
+ }
+ else if("-userJsInjection".equals(cmd) &&
rcc.getProxyInjectionModeArg()) {
+ rcc.setUserJSInjection(true);
+ }
+ else if("-ensureCleanSession".equals(cmd)) {
+ rcc.setReuseBrowserSessions(false);
+ }
+ else {
+ System.err.println("Unknown selenium server argument: " + cmd);
+ }
+ }
+ }
+ catch (NoSuchElementException nsee)
+ {
+ System.err.println("Invalid command line arguments in
selenium.server.cmd.args (" + SELENIUM_SERVER_ARGS + ")");
+ }
+ catch (NullPointerException ioe)
+ {
+ System.err.println("Unable to open empty filename in
selenium.server.cmd.args (" + SELENIUM_SERVER_ARGS+")");
+ }
+
+ }
+
private void startSeleniumServer() throws Exception
{
RemoteControlConfiguration rcc = new RemoteControlConfiguration();
rcc.setPort(SELENIUM_SERVER_PORT);
rcc.setLogOutFileName(OUTPUT_DIR + "/selenium-server.log");
+ setSeleniumServerProperties(rcc);
seleniumServer = new SeleniumServer(rcc);
seleniumServer.start();
}
-
+
private void createOutputDir()
{
File dir = new File(OUTPUT_DIR);
@@ -232,18 +300,18 @@
dir.mkdir();
}
}
-
+
public LocalContainer startContainer(String containerName, String containerHome)
{
-
+
LocalConfiguration configuration = new
JBossExistingLocalConfiguration(containerHome + "/server/default");
-
+
InstalledLocalContainer container;
-
+
if (containerName.equals("jboss4"))
{
container = new JBoss42xInstalledLocalContainer(configuration);
-
+
}
else if (containerName.equals("jboss5"))
{
@@ -254,11 +322,11 @@
throw new RuntimeException("Unknown container");
}
container.setHome(containerHome);
-
+
container.start();
return container;
}
-
+
public void stopContainer(LocalContainer container)
{
container.stop();