Author: thomas.heute(a)jboss.com
Date: 2007-02-21 08:11:17 -0500 (Wed, 21 Feb 2007)
New Revision: 6361
Added:
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/MonoValuedTestParameterValue.java
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/MultiValuedTestParameterValue.java
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/TestParameterValue.java
Modified:
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/util/Tools.java
branches/JBoss_Portal_Branch_2_4/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java
branches/JBoss_Portal_Branch_2_4/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java
Log:
Try to port back the DB matrix testing to 2.4.
Added:
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/MonoValuedTestParameterValue.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/MonoValuedTestParameterValue.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/MonoValuedTestParameterValue.java 2007-02-21
13:11:17 UTC (rev 6361)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * 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.portal.common.test;
+
+/**
+ * A mono value.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class MonoValuedTestParameterValue extends TestParameterValue
+{
+
+ /** The value. */
+ protected final Object value;
+
+ public MonoValuedTestParameterValue(Object value)
+ {
+ this.value = value;
+ }
+
+ public Object get()
+ {
+ return value;
+ }
+}
Added:
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/MultiValuedTestParameterValue.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/MultiValuedTestParameterValue.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/MultiValuedTestParameterValue.java 2007-02-21
13:11:17 UTC (rev 6361)
@@ -0,0 +1,90 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * 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.portal.common.test;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Arrays;
+
+/**
+ * A multi value.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class MultiValuedTestParameterValue extends TestParameterValue
+{
+
+ /** . */
+ protected final Collection value;
+
+ public MultiValuedTestParameterValue(Object[] value) throws IllegalArgumentException
+ {
+ if (value == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.value = Arrays.asList(value);
+ }
+
+ public MultiValuedTestParameterValue(Collection value) throws
IllegalArgumentException
+ {
+ if (value == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ this.value = value;
+ }
+
+ public Object get()
+ {
+ return value;
+ }
+
+ /**
+ * Return an iterator over the values.
+ */
+ public Iterator iterator()
+ {
+ return new Iterator()
+ {
+ Iterator i = value.iterator();
+ public boolean hasNext()
+ {
+ return i.hasNext();
+ }
+ public Object next()
+ {
+ return new MonoValuedTestParameterValue(i.next());
+ }
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+}
Added:
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/TestParameterValue.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/TestParameterValue.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/test/TestParameterValue.java 2007-02-21
13:11:17 UTC (rev 6361)
@@ -0,0 +1,63 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * 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.portal.common.test;
+
+import java.io.Serializable;
+
+/**
+ * The value of a test parameter.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class TestParameterValue implements Serializable
+{
+ /**
+ * Return the actual value.
+ *
+ * @return
+ */
+ public abstract Object get();
+
+ public int hashCode()
+ {
+ Object o = get();
+ return o == null ? 0 : o.hashCode();
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof TestParameterValue)
+ {
+ TestParameterValue that = (TestParameterValue)obj;
+ Object thisO = get();
+ Object thatO = that.get();
+ return thisO == null ? thatO == null : thisO.equals(thatO);
+ }
+ return false;
+ }
+}
Modified:
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/util/Tools.java 2007-02-21
11:47:55 UTC (rev 6360)
+++
branches/JBoss_Portal_Branch_2_4/common/src/main/org/jboss/portal/common/util/Tools.java 2007-02-21
13:11:17 UTC (rev 6361)
@@ -26,6 +26,7 @@
import org.apache.log4j.Logger;
import org.jboss.portal.common.logging.Log4JWriter;
+import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -785,4 +786,24 @@
ObjectInputStream ois = new ObjectInputStream(bais);
return ois.readObject();
}
+
+ public static BufferedInputStream safeBufferedWrapper(InputStream in)
+ {
+ if (in != null)
+ {
+ if (in instanceof BufferedInputStream)
+ {
+ return (BufferedInputStream)in;
+ }
+ else
+ {
+ return new BufferedInputStream(in);
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
}
\ No newline at end of file
Modified:
branches/JBoss_Portal_Branch_2_4/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java 2007-02-21
11:47:55 UTC (rev 6360)
+++
branches/JBoss_Portal_Branch_2_4/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java 2007-02-21
13:11:17 UTC (rev 6361)
@@ -20,10 +20,12 @@
* 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.portal.test.framework.embedded;
import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
+import org.jboss.portal.common.test.MultiValuedTestParameterValue;
import org.jboss.resource.adapter.jdbc.local.LocalTxDataSource;
import org.jboss.resource.connectionmanager.CachedConnectionManagerReference;
import org.w3c.dom.Document;
@@ -36,8 +38,10 @@
import java.sql.Connection;
import java.sql.Statement;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Hashtable;
import java.util.Iterator;
+import java.util.List;
/**
* An helper to setup JDNI available objects
@@ -55,7 +59,7 @@
private CachedConnectionManagerReference connectionManagerReference;
//
- private Config cfg;
+ private Config config;
private String jndiName = "java:/DefaultDS";
@@ -64,7 +68,7 @@
public DataSourceSupport(Config cfg)
{
- this.cfg = cfg;
+ this.config = cfg;
}
public DataSourceSupport()
@@ -81,10 +85,10 @@
//
ds = new LocalTxDataSource();
- ds.setConnectionURL(cfg.getConnectionURL());
- ds.setDriverClass(cfg.getDriverClass());
- ds.setUserName(cfg.getUserName());
- ds.setPassword(cfg.getPassword());
+ ds.setConnectionURL(config.getConnectionURL());
+ ds.setDriverClass(config.getDriverClass());
+ ds.setUserName(config.getUserName());
+ ds.setPassword(config.getPassword());
ds.setJndiName(jndiName);
ds.setMaxSize(10);
ds.setMinSize(0);
@@ -99,7 +103,7 @@
public void stop()
{
// Make hsqldb flush its data on the disk
- if ("org.hsqldb.jdbcDriver".equals(cfg.driverClass))
+ if ("org.hsqldb.jdbcDriver".equals(config.driverClass))
{
try
{
@@ -132,56 +136,16 @@
{
}
- public String getConnectionURL()
+ public Config getConfig()
{
- return cfg.connectionURL;
+ return config;
}
- public void setConnectionURL(String connectionURL)
+ public void setConfig(Config config)
{
- this.cfg.connectionURL = connectionURL;
+ this.config = config;
}
- public String getDriverClass()
- {
- return cfg.driverClass;
- }
-
- public void setDriverClass(String driverClass)
- {
- this.cfg.driverClass = driverClass;
- }
-
- public String getUserName()
- {
- return cfg.userName;
- }
-
- public void setUserName(String userName)
- {
- this.cfg.userName = userName;
- }
-
- public String getPassword()
- {
- return cfg.password;
- }
-
- public void setPassword(String password)
- {
- this.cfg.password = password;
- }
-
- public String getJndiName()
- {
- return jndiName;
- }
-
- public void setJndiName(String jndiName)
- {
- this.jndiName = jndiName;
- }
-
public TransactionManager getTransactionManager()
{
return transactionManager;
@@ -205,26 +169,40 @@
public static class Config
{
- private String displayName;
+ /** . */
+ private String name;
+
+ /** . */
private String connectionURL;
+
+ /** . */
private String driverClass;
+
+ /** . */
private String userName;
+
+ /** . */
private String password;
- public Config(String displayName, String connectionURL, String driverClass, String
userName, String password)
+ public Config(String name, String connectionURL, String driverClass, String
userName, String password)
{
- this.displayName = displayName;
+ this.name = name;
this.connectionURL = connectionURL;
this.driverClass = driverClass;
this.userName = userName;
this.password = password;
}
- public String getDisplayName()
+ public Config()
{
- return displayName;
+
}
+ public String getName()
+ {
+ return name;
+ }
+
public String getConnectionURL()
{
return connectionURL;
@@ -247,32 +225,74 @@
public String toString()
{
- return "DataSource[" + displayName + "]";
+ return "Datasource[" + name + "]";
}
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public void setConnectionURL(String connectionURL)
+ {
+ this.connectionURL = connectionURL;
+ }
+
+ public void setDriverClass(String driverClass)
+ {
+ this.driverClass = driverClass;
+ }
+
+ public void setUserName(String userName)
+ {
+ this.userName = userName;
+ }
+
+ public void setPassword(String password)
+ {
+ this.password = password;
+ }
+
+ public static MultiValuedTestParameterValue fromXML2(URL url) throws Exception
+ {
+ Config[] configs = fromXML(url);
+ List list = Arrays.asList(configs);
+ return new MultiValuedTestParameterValue(list);
+ }
+
public static Config[] fromXML(URL url) throws Exception
{
ArrayList configs = new ArrayList();
InputStream in = null;
try
{
- in = url.openStream();
+ in = Tools.safeBufferedWrapper(url.openStream());
Document doc =
XML.getDocumentBuilderFactory().newDocumentBuilder().parse(in);
for (Iterator i = XML.getChildrenIterator(doc.getDocumentElement(),
"datasource"); i.hasNext();)
{
Element childElt = (Element)i.next();
- Element displayNameURLElt = XML.getUniqueChild(childElt,
"datasource-name", true);
+
+ // Parse the datasource name, taking in account the deprecated
display-name element
+ Element nameElt = XML.getUniqueChild(childElt,
"datasource-name", false);
+ if (nameElt == null)
+ {
+ System.out.println("XML element datasource-name is not present,
trying deprecated display-name element instead, you should fix your
datasources.xml");
+ nameElt = XML.getUniqueChild(childElt, "display-name",
true);
+ }
+
+ // Parse the rest of the configuration
Element connectionURLElt = XML.getUniqueChild(childElt,
"connection-url", true);
Element driverClassElt = XML.getUniqueChild(childElt,
"driver-class", true);
Element userNameElt = XML.getUniqueChild(childElt, "user-name",
true);
Element passwordElt = XML.getUniqueChild(childElt, "password",
true);
- String displayName = XML.asString(displayNameURLElt);
+ String name = XML.asString(nameElt);
String connectionURL = XML.asString(connectionURLElt);
String driverClass = XML.asString(driverClassElt);
String userName = XML.asString(userNameElt);
String password = XML.asString(passwordElt);
Config dsCfg = new Config(
- displayName,
+ name,
connectionURL,
driverClass,
userName,
@@ -286,6 +306,5 @@
Tools.safeClose(in);
}
}
-
}
}
Modified:
branches/JBoss_Portal_Branch_2_4/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java 2007-02-21
11:47:55 UTC (rev 6360)
+++
branches/JBoss_Portal_Branch_2_4/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java 2007-02-21
13:11:17 UTC (rev 6361)
@@ -20,6 +20,7 @@
* 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.portal.test.framework.embedded;
import org.hibernate.HibernateException;
@@ -30,11 +31,20 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Settings;
import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.jboss.portal.common.util.XML;
+import org.jboss.portal.common.util.Tools;
+import org.w3c.dom.Element;
+import org.w3c.dom.Document;
import javax.transaction.Synchronization;
import java.util.Collection;
import java.util.Iterator;
+import java.util.Map;
+import java.util.LinkedHashMap;
+import java.util.HashMap;
import java.util.Properties;
+import java.io.InputStream;
+import java.net.URL;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -43,8 +53,6 @@
public class HibernateSupport
{
- public static final String DS_JNDI_NAME = "java:/DefaultDS";
-
/** . */
protected String jndiName;
@@ -52,17 +60,20 @@
protected Collection mappings;
/** . */
- protected Configuration cfg;
+ protected Config config;
/** . */
protected SessionFactory factory;
/** . */
- protected Settings settings;
+ protected Session session;
/** . */
- protected Session session;
+ protected Configuration cfg;
+ /** . */
+ protected Settings settings;
+
public Collection getMappings()
{
return mappings;
@@ -73,11 +84,16 @@
this.mappings = mappings;
}
- public Configuration getConfig()
+ public Config getConfig()
{
- return cfg;
+ return config;
}
+ public void setConfig(Config config)
+ {
+ this.config = config;
+ }
+
public SessionFactory getSessionFactory()
{
return factory;
@@ -95,10 +111,8 @@
protected void createConfiguration()
{
- //
- cfg = new Configuration();
+ Configuration cfg = new Configuration();
- //
for (Iterator i = mappings.iterator(); i.hasNext();)
{
String mapping = (String)i.next();
@@ -107,25 +121,21 @@
//
Properties props = new Properties();
- props.setProperty("hibernate.show_sql", "true");
- props.setProperty("hibernate.transaction.flush_before_completion",
"true");
- props.setProperty("hibernate.transaction.auto_close_session",
"true");
- props.setProperty("hibernate.transaction.factory_class",
"org.hibernate.transaction.JTATransactionFactory");
- props.setProperty("hibernate.transaction.manager_lookup_class",
"org.hibernate.transaction.JBossTransactionManagerLookup");
- props.setProperty("hibernate.connection.datasource", DS_JNDI_NAME);
- props.setProperty("hibernate.cache.provider_class",
"org.hibernate.cache.HashtableCacheProvider");
+ props.putAll(config.properties);
+ cfg.addProperties(props);
//
+ cfg.setProperty("hibernate.connection.datasource",
"java:/DefaultDS");
+
+ //
if (jndiName != null)
{
- props.setProperty("hibernate.session_factory_name", jndiName);
+ cfg.setProperty("hibernate.session_factory_name", jndiName);
}
//
- cfg.setProperties(props);
-
- //
- settings = cfg.buildSettings();
+ this.settings = cfg.buildSettings();
+ this.cfg = cfg;
}
protected void createSessionFactory()
@@ -152,7 +162,7 @@
protected void destroyConfiguration()
{
- cfg = null;
+ config = null;
}
public void create() throws Exception
@@ -304,4 +314,105 @@
});
return session;
}
+
+ public static class Config
+ {
+
+ /** . */
+ private String name;
+
+ /** . */
+ private Map properties;
+
+ public Config(String name, Map properties)
+ {
+ this.name = name;
+ this.properties = properties;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Map getProperties()
+ {
+ return properties;
+ }
+ }
+
+ /** . */
+ private static Map configs;
+
+ public static Map fromXML(URL url) throws Exception
+ {
+ Map configs = new LinkedHashMap();
+ InputStream in = null;
+ try
+ {
+ in = Tools.safeBufferedWrapper(url.openStream());
+ Document doc = XML.getDocumentBuilderFactory().newDocumentBuilder().parse(in);
+ for (Iterator i = XML.getChildrenIterator(doc.getDocumentElement(),
"configuration"); i.hasNext();)
+ {
+ Element childElt = (Element)i.next();
+
+ //
+ Element configurationNameElt = XML.getUniqueChild(childElt,
"configuration-name", true);
+ String configurationName = XML.asString(configurationNameElt);
+
+ //
+ Map properties = new HashMap();
+ Element propertiesElt = XML.getUniqueChild(childElt, "properties",
false);
+ if (propertiesElt != null)
+ {
+ for (Iterator j = XML.getChildrenIterator(propertiesElt,
"property");j.hasNext();)
+ {
+ Element propertyElt = (Element)j.next();
+ Element nameElt = XML.getUniqueChild(propertyElt, "name",
true);
+ Element valueElt = XML.getUniqueChild(propertyElt, "value",
true);
+ String name = XML.asString(nameElt);
+ String value = XML.asString(valueElt);
+ properties.put(name, value);
+ }
+ }
+
+ //
+ Config config = new Config(configurationName, properties);
+ configs.put(configurationName, config);
+ }
+ return configs;
+ }
+ finally
+ {
+ Tools.safeClose(in);
+ }
+ }
+
+ public synchronized static Config getConfig(String name) throws Exception
+ {
+ if (configs == null)
+ {
+ URL url =
Thread.currentThread().getContextClassLoader().getResource("hibernates.xml");
+ configs = fromXML(url);
+
+ // Remove and merge default with all
+ Config defaultCfg = (Config)configs.remove("default");
+
+ //
+ for (Iterator i = configs.values().iterator();i.hasNext();)
+ {
+ Config cfg = (Config)i.next();
+ if ("default".equals(cfg.getName()) == false)
+ {
+ Map tmp = new HashMap(defaultCfg.properties);
+ tmp.putAll(cfg.properties);
+ cfg.properties = tmp;
+ }
+ }
+
+ }
+
+ //
+ return (Config)configs.get(name);
+ }
}