JBoss Portal SVN: r7377 - trunk/common/src/main/org/jboss/portal/common/util.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-06-03 15:34:48 -0400 (Sun, 03 Jun 2007)
New Revision: 7377
Modified:
trunk/common/src/main/org/jboss/portal/common/util/Tools.java
Log:
typo
Modified: trunk/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 19:34:32 UTC (rev 7376)
+++ trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 19:34:48 UTC (rev 7377)
@@ -708,7 +708,7 @@
}
/**
- * Append an object to an array of object. The original array is not modified. The returned array
+ * Append an object to an array of objects. The original array is not modified. The returned array
* will be of the same component type of the provided array and its first n elements where n is the size
* of the provided array will be the elements of the provided array. The last element of the array will be
* the provided object to append.
16 years, 11 months
JBoss Portal SVN: r7376 - trunk/common/src/main/org/jboss/portal/common/util.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-06-03 15:34:32 -0400 (Sun, 03 Jun 2007)
New Revision: 7376
Modified:
trunk/common/src/main/org/jboss/portal/common/util/Tools.java
Log:
minor javadoc
Modified: trunk/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 19:31:15 UTC (rev 7375)
+++ trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 19:34:32 UTC (rev 7376)
@@ -707,7 +707,19 @@
return buffer.toString();
}
- public static Object[] appendTo(Object[] array, Object o)
+ /**
+ * Append an object to an array of object. The original array is not modified. The returned array
+ * will be of the same component type of the provided array and its first n elements where n is the size
+ * of the provided array will be the elements of the provided array. The last element of the array will be
+ * the provided object to append.
+ *
+ * @param array the array to augment
+ * @param o the object to append
+ * @return a new array
+ * @throws IllegalArgumentException if the array is null
+ * @throws ClassCastException if the appended object class prevents it from being added to the array
+ */
+ public static Object[] appendTo(Object[] array, Object o) throws IllegalArgumentException, ClassCastException
{
if (array == null)
{
16 years, 11 months
JBoss Portal SVN: r7375 - trunk/common/src/main/org/jboss/portal/common/util.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-06-03 15:31:15 -0400 (Sun, 03 Jun 2007)
New Revision: 7375
Modified:
trunk/common/src/main/org/jboss/portal/common/util/Tools.java
Log:
minor javadoc
Modified: trunk/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 19:20:39 UTC (rev 7374)
+++ trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 19:31:15 UTC (rev 7375)
@@ -723,6 +723,17 @@
return copy;
}
+ /**
+ * Return true if
+ * <ul>
+ * <li>o1 is null and o2 is null</li<
+ * <li>o1 is not null and the invocation of <code>equals(Object o)</code> on o1 wit o2 as argument returns true</li>
+ * </ul>
+ *
+ * @param o1 the first argument
+ * @param o2 the second argument
+ * @return if arguments are equals according to the semantic defined by the method contract
+ */
public static boolean safeEquals(Object o1, Object o2)
{
if (o1 == null)
16 years, 11 months
JBoss Portal SVN: r7374 - in trunk: cms/src/main/org/jboss/portal/cms/hibernate and 27 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-06-03 15:20:39 -0400 (Sun, 03 Jun 2007)
New Revision: 7374
Added:
trunk/common/src/main/org/jboss/portal/common/io/IOTools.java
trunk/common/src/main/org/jboss/portal/test/common/io/
trunk/common/src/main/org/jboss/portal/test/common/io/IOToolsTestCase.java
Modified:
trunk/cms/src/main/org/jboss/portal/cms/CMSMimeMappings.java
trunk/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java
trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java
trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java
trunk/common/build.xml
trunk/common/src/main/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java
trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java
trunk/common/src/main/org/jboss/portal/common/logging/LoaderRepositorySelector.java
trunk/common/src/main/org/jboss/portal/common/util/LoaderResource.java
trunk/common/src/main/org/jboss/portal/common/util/Tools.java
trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
trunk/common/src/main/org/jboss/portal/test/common/BufferedStreamTestCase.java
trunk/common/src/main/org/jboss/portal/test/common/JarTestCase.java
trunk/core-cms/src/main/org/jboss/portal/core/cms/servlet/CMSExportServlet.java
trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java
trunk/core/src/main/org/jboss/portal/core/deployment/jboss/PortletAppDeployment.java
trunk/core/src/main/org/jboss/portal/test/core/Utils.java
trunk/format/src/main/org/jboss/portal/format/template/TemplateLoader.java
trunk/jems/src/main/org/jboss/portal/jems/hibernate/ByteArrayBlob.java
trunk/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeployment.java
trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java
trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/portletrequests/PortletRequestsSequenceBuilder.java
trunk/portlet/src/main/org/jboss/portal/test/portlet/session/TestClassLoader.java
trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java
trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java
trunk/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java
trunk/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeployment.java
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeployment.java
trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeployment.java
trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java
trunk/workflow/src/main/org/jboss/portal/workflow/cms/ApprovePublishImpl.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/AbstractJNDIServiceFactory.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java
Log:
- extracted related IO methods from Tools to io.IOTools
- added test cases for IOTools
Modified: trunk/cms/src/main/org/jboss/portal/cms/CMSMimeMappings.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/CMSMimeMappings.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/cms/src/main/org/jboss/portal/cms/CMSMimeMappings.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -22,8 +22,8 @@
******************************************************************************/
package org.jboss.portal.cms;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
+import org.jboss.portal.common.io.IOTools;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -67,7 +67,7 @@
}
finally
{
- Tools.safeClose(is);
+ IOTools.safeClose(is);
}
}
Modified: trunk/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/cms/src/main/org/jboss/portal/cms/hibernate/HibernateStore.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -33,7 +33,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.jboss.portal.cms.util.HibernateUtil;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.logging.Logger;
import java.io.ByteArrayInputStream;
@@ -957,7 +957,7 @@
try
{
long length = f.length();
- in = Tools.safeBufferedWrapper(new FileInputStream(f));
+ in = IOTools.safeBufferedWrapper(new FileInputStream(f));
if (schemaObjectPrefix.equals(HibernateStoreConstants.versionClassName))
{
Query query = session.createQuery("from VersionEntry where FSENTRY_PATH = ? and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
@@ -1069,7 +1069,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
// temp file can now safely be removed
f.delete();
f = null;
@@ -1141,7 +1141,7 @@
}
finally
{
- Tools.safeClose(out);
+ IOTools.safeClose(out);
// in.close();
}
}
@@ -1166,7 +1166,7 @@
try
{
long length = f.length();
- in = Tools.safeBufferedWrapper(new FileInputStream(f));
+ in = IOTools.safeBufferedWrapper(new FileInputStream(f));
if (schemaObjectPrefix.equals(HibernateStoreConstants.versionClassName))
{
Query query = session.createQuery("from VersionEntry where FSENTRY_PATH = ? and FSENTRY_NAME = ? and FSENTRY_DATA is not null");
@@ -1240,7 +1240,7 @@
try
{
long length = f.length();
- in = Tools.safeBufferedWrapper(new FileInputStream(f));
+ in = IOTools.safeBufferedWrapper(new FileInputStream(f));
if (schemaObjectPrefix.equals(HibernateStoreConstants.versionClassName))
{
VersionEntry versionEntry = new VersionEntry(parentDir, name, createBlob(in), System.currentTimeMillis(), length);
@@ -1278,7 +1278,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
// temp file can now safely be removed
f.delete();
f = null;
@@ -1708,12 +1708,12 @@
{
in = blob.getBinaryStream();
ByteArrayOutputStream out = new ByteArrayOutputStream(in.available());
- Tools.copy(in, out);
+ IOTools.copy(in, out);
return out.toByteArray();
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified: trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/HibernatePersistenceManager.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -49,7 +49,7 @@
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.jboss.portal.cms.hibernate.HibernateStoreConstants;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.logging.Logger;
import javax.jcr.PropertyType;
@@ -402,7 +402,7 @@
NodeState state = createNew(id);
Serializer.deserialize(state, in);
- Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
return state;
}
@@ -448,7 +448,7 @@
PropertyState state = createNew(id);
Serializer.deserialize(state, in, blobStore);
- Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
return state;
}
@@ -497,7 +497,7 @@
NodeReferences refs = new NodeReferences(targetId);
Serializer.deserialize(refs, in);
- Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
return refs;
}
Modified: trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/cms/src/main/org/jboss/portal/cms/hibernate/state/JBossCachePersistenceManager.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -53,6 +53,7 @@
import org.jboss.mx.util.MBeanProxyExt;
import org.jboss.mx.util.MBeanServerLocator;
import org.jboss.portal.cms.hibernate.HibernateStoreConstants;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.logging.Logger;
import javax.jcr.PropertyType;
@@ -552,7 +553,7 @@
// setup the propertyState
nodeState = createNew(node);
Serializer.deserialize(nodeState, in);
- org.jboss.portal.common.util.Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
success = true;
@@ -846,7 +847,7 @@
// setup the propertyState
propertyState = createNew(property);
Serializer.deserialize(propertyState, in, blobStore);
- org.jboss.portal.common.util.Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
success = true;
@@ -1178,7 +1179,7 @@
// setup the propertyState
refs = new NodeReferences(targetId);
Serializer.deserialize(refs, in);
- org.jboss.portal.common.util.Tools.safeClose(in);
+ IOTools.safeClose(in);
tx.commit();
success = true;
Modified: trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/cms/src/main/org/jboss/portal/cms/impl/jcr/JCRCMS.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -45,8 +45,8 @@
import org.jboss.portal.common.invocation.InvocationHandler;
import org.jboss.portal.common.net.URLNavigator;
import org.jboss.portal.common.net.URLVisitor;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.jems.as.JNDI;
import org.jboss.portal.identity.User;
import org.jboss.portal.identity.UserModule;
@@ -66,7 +66,6 @@
import javax.jcr.Session;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
-import javax.naming.InitialContext;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.URL;
@@ -494,11 +493,11 @@
try
{
urlin = url.openStream();
- Tools.copy(urlin, baos);
+ IOTools.copy(urlin, baos);
}
finally
{
- Tools.safeClose(urlin);
+ IOTools.safeClose(urlin);
}
//
@@ -534,7 +533,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
};
Modified: trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java
===================================================================
--- trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/cms/src/main/org/jboss/portal/test/cms/commands/TestFileArchiveUpload.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -26,14 +26,13 @@
import org.jboss.portal.cms.CMSException;
import org.jboss.portal.cms.Command;
import org.jboss.portal.cms.model.Folder;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;
-import java.util.Map;
/**
@@ -77,7 +76,7 @@
public void testArchiveUpload() throws CMSException, IOException
{
service.setDefaultLocale(Locale.ENGLISH.getLanguage());
- InputStream is = Tools.safeBufferedWrapper(new FileInputStream(sZipFile));
+ InputStream is = IOTools.safeBufferedWrapper(new FileInputStream(sZipFile));
Command storearchiveCMD = service.getCommandFactory().createStoreArchiveCommand("", is, "en");
List contentsToVersion = (List)service.execute(storearchiveCMD);
Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/build.xml 2007-06-03 19:20:39 UTC (rev 7374)
@@ -210,6 +210,7 @@
</x-sysproperty>
<x-test>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.io.IOToolsTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.reflect.ReflectionTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.reflect.ModifierTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.test.junit.POJOJunitTestTestCase"/>
Modified: trunk/common/src/main/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/i18n/ComplexResourceBundleFactory.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.common.i18n;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.IOException;
import java.io.InputStream;
@@ -105,7 +105,7 @@
{
try
{
- in = Tools.safeBufferedWrapper(in);
+ in = IOTools.safeBufferedWrapper(in);
return new PropertyResourceBundle(in);
}
catch (IOException e)
@@ -113,7 +113,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Added: trunk/common/src/main/org/jboss/portal/common/io/IOTools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/io/IOTools.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/io/IOTools.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -0,0 +1,438 @@
+/******************************************************************************
+ * 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.io;
+
+import org.jboss.portal.common.util.Tools;
+import org.apache.log4j.Logger;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.InvocationTargetException;
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.ByteArrayOutputStream;
+import java.io.Writer;
+import java.io.Serializable;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+
+/**
+ * IO tools.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class IOTools
+{
+
+ /** The logger. */
+ public static final Logger log = Logger.getLogger(IOTools.class);
+
+ /** . */
+ private static final Object[] EMPTY_ARGS = new Object[0];
+
+ /** . */
+ private static final Class[] EMPTY_PARAMETER_TYPES = new Class[0];
+
+ /**
+ * <p>Attempt to close an object. Null argument value is authorized and no operation will be performed in that
+ * use case.</p>
+ *
+ * <p>It will try to obtain a <code>close()</code> method by reflection and it
+ * will be invoked only if the method is public and not static. If the method is called, any <code>Error</code>
+ * or <code>RuntimeException</code> will be rethrown, any other kind of throwable will not be rethrown in any form.</p>
+ *
+ * @param closable the object to close
+ */
+ public static void safeClose(Object closable)
+ {
+ if (closable != null)
+ {
+ try
+ {
+ Method m = closable.getClass().getMethod("close", EMPTY_PARAMETER_TYPES);
+ if (Modifier.isStatic(m.getModifiers()))
+ {
+ log.warn("close() method on closable object is static");
+ return;
+ }
+ m.invoke(closable, EMPTY_ARGS);
+ }
+ catch (NoSuchMethodException e)
+ {
+ log.warn("The closable object does not have a close() method", e);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.warn("Cannot access close() method on closable object", e);
+ }
+ catch (InvocationTargetException e)
+ {
+ Throwable t = e.getCause();
+
+ //
+ if (t instanceof RuntimeException)
+ {
+ log.error("The close() method threw a runtime exception", t);
+ throw (RuntimeException)t;
+ }
+ else if (t instanceof Error)
+ {
+ log.error("The close() method threw an error", t);
+ throw (Error)t;
+ }
+ else if (t instanceof Exception)
+ {
+ log.error("The close() method threw an exception", t);
+ }
+ else
+ {
+ log.error("The close() method threw an unexpected throwable", t);
+ }
+ }
+ }
+ }
+
+ /**
+ * <p>Attempt to close an <code>OutputStream</code>. Null argument value is authorized and no operation will be performed in that
+ * use case.</p>
+ *
+ * @param out the stream to close
+ */
+ public static void safeClose(OutputStream out)
+ {
+ if (out != null)
+ {
+ try
+ {
+ out.close();
+ }
+ catch (IOException e)
+ {
+ log.error("Error while closing outstream", e);
+ }
+ }
+ }
+
+ /**
+ * <p>Attempt to close an <code>InputStream</code>. Null argument value is authorized and no operation will be performed in that
+ * use case.</p>
+ *
+ * @param in the stream to close
+ */
+ public static void safeClose(InputStream in)
+ {
+ if (in != null)
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException e)
+ {
+ log.error("Error while closing inputstream", e);
+ }
+ }
+ }
+
+ /**
+ * <p>Attempt to close an <code>Reader</code>. Null argument value is authorized and no operation will be performed in that
+ * use case.</p>
+ *
+ * @param reader the stream to close
+ */
+ public static void safeClose(Reader reader)
+ {
+ if (reader != null)
+ {
+ try
+ {
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ log.error("Error while closing reader", e);
+ }
+ }
+ }
+
+ /**
+ * <p>Attempt to close an <code>Writer</code>. Null argument value is authorized and no operation will be performed in that
+ * use case.</p>
+ *
+ * @param writer the stream to close
+ */
+ public static void safeClose(Writer writer)
+ {
+ if (writer != null)
+ {
+ try
+ {
+ writer.close();
+ }
+ catch (IOException e)
+ {
+ log.error("Error while closing writer", e);
+ }
+ }
+ }
+
+ /**
+ * @see #getBytes(java.io.InputStream, int)
+ * @param in the input stream
+ * @return the bytes read from the stream
+ * @throws java.io.IOException
+ * @throws IllegalArgumentException if the input stream is null
+ */
+ public static byte[] getBytes(InputStream in) throws IOException, IllegalArgumentException
+ {
+ return getBytes(in, Tools.DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Get the bytes from the provided input stream. No attempt will be made to close the stream.
+ *
+ * @param in the input stream
+ * @param bufferSize the buffer size used to copy the bytes
+ * @return the bytes read from the stream
+ * @throws java.io.IOException
+ * @throws IllegalArgumentException if the input stream is null or the buffer size < 1
+ */
+ public static byte[] getBytes(InputStream in, int bufferSize) throws IOException, IllegalArgumentException
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ copy(in, out, bufferSize);
+ return out.toByteArray();
+ }
+
+ /**
+ * @see #copy(java.io.InputStream, java.io.OutputStream, int)
+ * @param in the incoming stream
+ * @param out the outcoming stream
+ * @throws IllegalArgumentException if an argument is null
+ */
+ public static void copy(InputStream in, OutputStream out) throws IOException
+ {
+ copy(in, out, Tools.DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Pipe an incoming stream in an outcoming stream until no bytes is available from the input stream.
+ * No attempts will be made to close the streams.
+ *
+ * @param in the incoming stream
+ * @param out the outcoming stream
+ * @param bufferSize the buffer size
+ * @throws IllegalArgumentException if bufferSize < 1 or an argument is null
+ */
+ public static void copy(InputStream in, OutputStream out, int bufferSize) throws IOException
+ {
+ // arguments check
+ if (in == null)
+ {
+ throw new IllegalArgumentException("null in");
+ }
+ if (out == null)
+ {
+ throw new IllegalArgumentException("null out");
+ }
+ if (bufferSize < 1)
+ {
+ throw new IllegalArgumentException("Buffer size is too small");
+ }
+
+ // do the job
+ byte[] buffer = new byte[bufferSize];
+ while (true)
+ {
+ int i = in.read(buffer);
+ if (i == 0)
+ {
+ continue;
+ }
+ if (i == -1)
+ {
+ break;
+ }
+ out.write(buffer, 0, i);
+ }
+ }
+
+ /**
+ * Pipe an input stream in an output stream.
+ *
+ * @param reader the incoming reader
+ * @param writer the outcoming writer
+ * @throws IllegalArgumentException if an argument is null
+ */
+ public static void copy(Reader reader, Writer writer) throws IOException
+ {
+ copy(reader, writer, Tools.DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Pipe an incoming stream in an outcoming stream.
+ *
+ * @param reader the incoming reader
+ * @param writer the outcoming writer
+ * @param bufferSize the buffer size
+ * @throws IllegalArgumentException if bufferSize < 1 or an argument is null
+ */
+ public static void copy(Reader reader, Writer writer, int bufferSize) throws IOException
+ {
+ // arguments check
+ if (reader == null)
+ {
+ throw new IllegalArgumentException("null in");
+ }
+ if (writer == null)
+ {
+ throw new IllegalArgumentException("null out");
+ }
+ if (bufferSize < 1)
+ {
+ throw new IllegalArgumentException("Buffer size is too small");
+ }
+
+ // do the job
+ char[] buffer = new char[bufferSize];
+ while (true)
+ {
+ int i = reader.read(buffer);
+ if (i == 0)
+ {
+ continue;
+ }
+ if (i == -1)
+ {
+ break;
+ }
+ writer.write(buffer, 0, i);
+ }
+ }
+
+ /**
+ * Clone an object implementing the <code>Serializable</code> interface.
+ *
+ * @param serializable
+ * @return
+ * @throws IllegalArgumentException if the serializable object is null
+ * @throws IOException
+ */
+ public static Object clone(Serializable serializable) throws IllegalArgumentException, IOException
+ {
+ try
+ {
+ return unserialize(serialize(serializable));
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new Error("Got a class not found exception for a class that was used", e);
+ }
+ }
+
+ public static byte[] serialize(Serializable serializable) throws IllegalArgumentException, IOException
+ {
+ if (serializable == null)
+ {
+ throw new IllegalArgumentException("No null serializable accepted");
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = new ObjectOutputStream(baos);
+ oos.writeObject(serializable);
+ oos.close();
+ return baos.toByteArray();
+ }
+
+ public static Serializable unserialize(byte[] bytes) throws IllegalArgumentException, IOException, ClassNotFoundException
+ {
+ if (bytes == null)
+ {
+ throw new IllegalArgumentException("No null serializable accepted");
+ }
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ ObjectInputStream ois = new ObjectInputStream(bais);
+ return (Serializable)ois.readObject();
+ }
+
+ /**
+ * Check that the provided input stream is buffered. If the argument is already an instance of <code>BufferedInputStream</code>
+ * no operation will be performed, otherwise a instance of <code>BufferedInputStream</code> will be created and returned.
+ *
+ * If the provided argument is null, the null value is returned.
+ *
+ * @param in the stream
+ * @return a buffered wrapper
+ */
+ public static BufferedInputStream safeBufferedWrapper(InputStream in)
+ {
+ if (in != null)
+ {
+ if (in instanceof BufferedInputStream)
+ {
+ return (BufferedInputStream)in;
+ }
+ else
+ {
+ return new BufferedInputStream(in);
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Check that the provided output stream is buffered. If the argument is already an instance of <code>BufferedOutputStream</code>
+ * no operation will be performed, otherwise a instance of <code>BufferedOutputStream</code> will be created and returned.
+ *
+ * If the provided argument is null, the null value is returned.
+ *
+ * @param out the stream
+ * @return a buffered wrapper
+ */
+ public static BufferedOutputStream safeBufferedWrapper(OutputStream out)
+ {
+ if (out != null)
+ {
+ if (out instanceof BufferedOutputStream)
+ {
+ return (BufferedOutputStream)out;
+ }
+ else
+ {
+ return new BufferedOutputStream(out);
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+}
Modified: trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/junit/ExtendedAssert.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -52,13 +52,29 @@
fail(format(message, expected, actual));
}
+ /** @see #assertEquals(char[],char[]) */
+ public static void assertEquals(char[] expected, char[] actual)
+ {
+ assertEquals(null, expected, actual);
+ }
+
+ /** Test equality as defined by java.util.Array#equals(char[], char[]). */
+ public static void assertEquals(String message, char[] expected, char[] actual)
+ {
+ if (Arrays.equals(expected, actual))
+ {
+ return;
+ }
+ fail(format(message, expected, actual));
+ }
+
/** @see #assertEquals(byte[],byte[]) */
public static void assertEquals(byte[] expected, byte[] actual)
{
assertEquals(null, expected, actual);
}
- /** Test equality as defined by java.util.Array#equals(Object[], Object[]). */
+ /** Test equality as defined by java.util.Array#equals(char[], char[]). */
public static void assertEquals(String message, byte[] expected, byte[] actual)
{
if (Arrays.equals(expected, actual))
Modified: trunk/common/src/main/org/jboss/portal/common/logging/LoaderRepositorySelector.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/logging/LoaderRepositorySelector.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/logging/LoaderRepositorySelector.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -32,6 +32,7 @@
import org.apache.log4j.xml.DOMConfigurator;
import org.jboss.portal.common.util.ResourceLoader;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.w3c.dom.Document;
import javax.xml.parsers.DocumentBuilder;
@@ -106,7 +107,7 @@
}
finally
{
- Tools.safeClose(log4JConfig);
+ IOTools.safeClose(log4JConfig);
}
}
Modified: trunk/common/src/main/org/jboss/portal/common/util/LoaderResource.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/LoaderResource.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/util/LoaderResource.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -25,6 +25,7 @@
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
import org.apache.log4j.Logger;
+import org.jboss.portal.common.io.IOTools;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.ParserConfigurationException;
@@ -73,7 +74,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(asInputStream());
+ in = IOTools.safeBufferedWrapper(asInputStream());
return builder.parse(in);
}
catch (SAXException e)
@@ -90,7 +91,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
@@ -111,7 +112,7 @@
try
{
- in = Tools.safeBufferedWrapper(asInputStream());
+ in = IOTools.safeBufferedWrapper(asInputStream());
Properties props;
if (xml)
{
@@ -141,7 +142,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
@@ -162,9 +163,9 @@
try
{
- in = Tools.safeBufferedWrapper(asInputStream());
+ in = IOTools.safeBufferedWrapper(asInputStream());
ByteArrayOutputStream out = new ByteArrayOutputStream(in.available());
- Tools.copy(in, out);
+ IOTools.copy(in, out);
String result;
if (enc == null)
{
@@ -186,7 +187,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
}
Modified: trunk/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -26,24 +26,10 @@
import org.apache.log4j.Logger;
import org.jboss.portal.common.logging.Log4JWriter;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.Serializable;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Array;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
import java.math.BigInteger;
import java.net.URL;
import java.net.URLClassLoader;
@@ -74,243 +60,6 @@
public static final Logger log = Logger.getLogger(Tools.class);
- private static final Object[] EMPTY_ARGS = new Object[0];
-
- private static final Class[] EMPTY_PARAMETER_TYPES = new Class[0];
-
- /**
- * Close an object that implements a close() method.
- *
- * @param closable the object to close
- */
- public static void safeClose(Object closable)
- {
- if (closable != null)
- {
- try
- {
- Method m = closable.getClass().getMethod("close", Tools.EMPTY_PARAMETER_TYPES);
- if (!Modifier.isPublic(m.getModifiers()))
- {
- log.warn("close() method on closable object is not public");
- return;
- }
- if (Modifier.isStatic(m.getModifiers()))
- {
- log.warn("close() method on closable object is static");
- return;
- }
- m.invoke(closable, EMPTY_ARGS);
- }
- catch (NoSuchMethodException e)
- {
- log.warn("The closable object does not have a close() method", e);
- }
- catch (IllegalAccessException e)
- {
- log.warn("Cannot access close() method on closable object", e);
- }
- catch (InvocationTargetException e)
- {
- log.error("The close() method threw an exception", e.getTargetException());
- }
- }
- }
-
- /**
- * Close an output stream safely.
- *
- * @param out the stream to close
- */
- public static void safeClose(OutputStream out)
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (IOException e)
- {
- log.error("Error while closing putstream", e);
- }
- }
- }
-
- /**
- * Close an input stream safely.
- *
- * @param in the stream to close
- */
- public static void safeClose(InputStream in)
- {
- if (in != null)
- {
- try
- {
- in.close();
- }
- catch (IOException e)
- {
- log.error("Error while closing inputstream", e);
- }
- }
- }
-
- /**
- * Close a reader safely.
- *
- * @param reader the stream to close
- */
- public static void safeClose(Reader reader)
- {
- if (reader != null)
- {
- try
- {
- reader.close();
- }
- catch (IOException e)
- {
- log.error("Error while closing inputstream", e);
- }
- }
- }
-
- /**
- * @see #getBytes(java.io.InputStream, int)
- * @param in the input stream
- * @return the bytes read from the stream
- * @throws IOException
- * @throws IllegalArgumentException if the input stream is null
- */
- public static byte[] getBytes(InputStream in) throws IOException, IllegalArgumentException
- {
- return getBytes(in, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Get the bytes from the provided input stream. No attempt will be made to close the stream.
- *
- * @param in the input stream
- * @param bufferSize the buffer size used to copy the bytes
- * @return the bytes read from the stream
- * @throws IOException
- * @throws IllegalArgumentException if the input stream is null or the buffer size < 1
- */
- public static byte[] getBytes(InputStream in, int bufferSize) throws IOException, IllegalArgumentException
- {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- copy(in, out, bufferSize);
- return out.toByteArray();
- }
-
- /**
- * @see #copy(java.io.InputStream, java.io.OutputStream, int)
- * @param in the incoming stream
- * @param out the outcoming stream
- * @throws IllegalArgumentException if an argument is null
- */
- public static void copy(InputStream in, OutputStream out) throws IOException
- {
- copy(in, out, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Pipe an incoming stream in an outcoming stream until no bytes is available from the input stream.
- * No attempts will be made to close the streams.
- *
- * @param in the incoming stream
- * @param out the outcoming stream
- * @param bufferSize the buffer size
- * @throws IllegalArgumentException if bufferSize < 1 or an argument is null
- */
- public static void copy(InputStream in, OutputStream out, int bufferSize) throws IOException
- {
- // arguments check
- if (in == null)
- {
- throw new IllegalArgumentException("null in");
- }
- if (out == null)
- {
- throw new IllegalArgumentException("null out");
- }
- if (bufferSize < 1)
- {
- throw new IllegalArgumentException("Buffer size is too small");
- }
-
- // do the job
- byte[] buffer = new byte[bufferSize];
- while (true)
- {
- int i = in.read(buffer);
- if (i == 0)
- {
- continue;
- }
- if (i == -1)
- {
- break;
- }
- out.write(buffer, 0, i);
- }
- }
-
- /**
- * Pipe an input stream in an output stream.
- *
- * @param reader the incoming reader
- * @param writer the outcoming writer
- * @throws IllegalArgumentException if an argument is null
- */
- public static void copy(Reader reader, Writer writer) throws IOException
- {
- copy(reader, writer, DEFAULT_BUFFER_SIZE);
- }
-
- /**
- * Pipe an incoming stream in an outcoming stream.
- *
- * @param reader the incoming reader
- * @param writer the outcoming writer
- * @param bufferSize the buffer size
- * @throws IllegalArgumentException if bufferSize < 1 or an argument is null
- */
- public static void copy(Reader reader, Writer writer, int bufferSize) throws IOException
- {
- // arguments check
- if (reader == null)
- {
- throw new IllegalArgumentException("null in");
- }
- if (writer == null)
- {
- throw new IllegalArgumentException("null out");
- }
- if (bufferSize < 1)
- {
- throw new IllegalArgumentException("Buffer size is too small");
- }
-
- // do the job
- char[] buffer = new char[bufferSize];
- while (true)
- {
- int i = reader.read(buffer);
- if (i == 0)
- {
- continue;
- }
- if (i == -1)
- {
- break;
- }
- writer.write(buffer, 0, i);
- }
- }
-
/** 16 chars long VMID. */
public static final String VMID = VMID();
@@ -958,73 +707,6 @@
return buffer.toString();
}
- public static Object clone(Serializable serializable) throws IOException, ClassNotFoundException
- {
- return unserialize(serialize(serializable));
- }
-
- public static byte[] serialize(Serializable serializable) throws IllegalArgumentException, IOException
- {
- if (serializable == null)
- {
- throw new IllegalArgumentException("No null serializable accepted");
- }
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(baos);
- oos.writeObject(serializable);
- oos.close();
- return baos.toByteArray();
- }
-
- public static Serializable unserialize(byte[] bytes) throws IllegalArgumentException, IOException, ClassNotFoundException
- {
- if (bytes == null)
- {
- throw new IllegalArgumentException("No null serializable accepted");
- }
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- ObjectInputStream ois = new ObjectInputStream(bais);
- return (Serializable)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;
- }
- }
-
- public static BufferedOutputStream safeBufferedWrapper(OutputStream out)
- {
- if (out != null)
- {
- if (out instanceof BufferedOutputStream)
- {
- return (BufferedOutputStream)out;
- }
- else
- {
- return new BufferedOutputStream(out);
- }
- }
- else
- {
- return null;
- }
- }
-
public static Object[] appendTo(Object[] array, Object o)
{
if (array == null)
Modified: trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -25,6 +25,7 @@
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.portal.common.io.IOTools;
import java.io.UnsupportedEncodingException;
import java.io.IOException;
@@ -231,7 +232,7 @@
}
finally
{
- Tools.safeClose(thread.getInputStream());
+ IOTools.safeClose(thread.getInputStream());
}
}
Modified: trunk/common/src/main/org/jboss/portal/test/common/BufferedStreamTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/BufferedStreamTestCase.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/test/common/BufferedStreamTestCase.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.test.common;
import junit.framework.TestCase;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.InputStream;
import java.io.ByteArrayInputStream;
@@ -47,9 +47,9 @@
public void testInputStream() throws Exception
{
- assertNull(Tools.safeBufferedWrapper((InputStream)null));
- BufferedInputStream in = Tools.safeBufferedWrapper(new ByteArrayInputStream("abc".getBytes("UTF8")));
- assertEquals(System.identityHashCode(in), System.identityHashCode(Tools.safeBufferedWrapper(in)));
+ assertNull(IOTools.safeBufferedWrapper((InputStream)null));
+ BufferedInputStream in = IOTools.safeBufferedWrapper(new ByteArrayInputStream("abc".getBytes("UTF8")));
+ assertEquals(System.identityHashCode(in), System.identityHashCode(IOTools.safeBufferedWrapper(in)));
assertNotNull(in);
byte[] bytes = "abc".getBytes("UTF8");
Arrays.fill(bytes, (byte)0);
@@ -60,11 +60,11 @@
public void testOutputputStream() throws Exception
{
- assertNull(Tools.safeBufferedWrapper((OutputStream)null));
+ assertNull(IOTools.safeBufferedWrapper((OutputStream)null));
ByteArrayOutputStream out = new ByteArrayOutputStream();
- BufferedOutputStream buffered = Tools.safeBufferedWrapper(out);
+ BufferedOutputStream buffered = IOTools.safeBufferedWrapper(out);
assertNotNull(buffered);
- assertEquals(System.identityHashCode(buffered), System.identityHashCode(Tools.safeBufferedWrapper(buffered)));
+ assertEquals(System.identityHashCode(buffered), System.identityHashCode(IOTools.safeBufferedWrapper(buffered)));
buffered.write("abc".getBytes("UTF8"));
buffered.close();
assertEquals("abc", out.toString("UTF8"));
Modified: trunk/common/src/main/org/jboss/portal/test/common/JarTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/JarTestCase.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/common/src/main/org/jboss/portal/test/common/JarTestCase.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -35,9 +35,9 @@
import java.io.FileInputStream;
import java.io.OutputStream;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.jar.JarEntryInfo;
import org.jboss.portal.common.jar.JarInfo;
+import org.jboss.portal.common.io.IOTools;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -85,7 +85,7 @@
{
File jarFile = File.createTempFile("test", ".jar");
- OutputStream out = Tools.safeBufferedWrapper(new FileOutputStream(jarFile));
+ OutputStream out = IOTools.safeBufferedWrapper(new FileOutputStream(jarFile));
JarOutputStream jarOut = new JarOutputStream(out);
jarOut.putNextEntry(new JarEntry("a/c"));
jarOut.closeEntry();
@@ -101,7 +101,7 @@
jarFile.deleteOnExit();
- JarInputStream jarIn = new JarInputStream(Tools.safeBufferedWrapper(new FileInputStream(jarFile)));
+ JarInputStream jarIn = new JarInputStream(IOTools.safeBufferedWrapper(new FileInputStream(jarFile)));
Iterator i = new JarInfo(jarIn).entries();
while (i.hasNext())
{
Added: trunk/common/src/main/org/jboss/portal/test/common/io/IOToolsTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/io/IOToolsTestCase.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/io/IOToolsTestCase.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -0,0 +1,667 @@
+/******************************************************************************
+ * 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.test.common.io;
+
+import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.common.junit.ExtendedAssert;
+import junit.framework.TestCase;
+
+import java.io.OutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.CharArrayWriter;
+import java.io.CharArrayReader;
+import java.util.Random;
+
+import EDU.oswego.cs.dl.util.concurrent.SynchronizedBoolean;
+
+/**
+ * todo:
+ * <ul>
+ * <li>test safeBufferedWrapper</li>
+ * <li>test serialize</li>
+ * <li>test unserialize</li>
+ * <li>test clone</li>
+ * </ul>
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class IOToolsTestCase extends TestCase
+{
+
+ public void testGenericSafeClose()
+ {
+ IOTools.safeClose((Object)null);
+ IOTools.safeClose(new Object());
+
+ //
+ assertTrue(new GenericPublicSafeClose().apply().called);
+ assertFalse(new GenericProtectedSafeClose().apply().called);
+ assertFalse(new GenericPackageProtectedSafeClose().apply().called);
+ assertFalse(new GenericPrivateSafeClose().apply().called);
+
+ //
+ IOTools.safeClose(new GenericPublicStaticSafeClose());
+ assertFalse(GenericPublicStaticSafeClose.called);
+ IOTools.safeClose(new GenericProtectedStaticSafeClose());
+ assertFalse(GenericProtectedStaticSafeClose.called);
+ IOTools.safeClose(new GenericPackageProtectedStaticSafeClose());
+ assertFalse(GenericPackageProtectedStaticSafeClose.called);
+ IOTools.safeClose(new GenericPrivateStaticSafeClose());
+ assertFalse(GenericPrivateStaticSafeClose.called);
+ }
+
+ public static class GenericSafeClose
+ {
+ boolean called = false;
+ public GenericSafeClose apply()
+ {
+ IOTools.safeClose(this);
+ return this;
+ }
+ }
+
+ public static class GenericPublicSafeClose extends GenericSafeClose
+ {
+ public void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericProtectedSafeClose extends GenericSafeClose
+ {
+ protected void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPackageProtectedSafeClose extends GenericSafeClose
+ {
+ protected void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPrivateSafeClose extends GenericSafeClose
+ {
+ private void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPublicStaticSafeClose
+ {
+ static boolean called = false;
+ public static void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericProtectedStaticSafeClose
+ {
+ static boolean called = false;
+ protected static void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPackageProtectedStaticSafeClose
+ {
+ static boolean called = false;
+ static void close()
+ {
+ called = true;
+ }
+ }
+
+ public static class GenericPrivateStaticSafeClose
+ {
+ static boolean called = false;
+ private static void close()
+ {
+ called = true;
+ }
+ }
+
+
+ public void testGenericSafeCloseWithThrowable()
+ {
+ new FailingGenericSafeClose()
+ {
+ protected void internalClose() throws Throwable
+ {
+ throw new Exception();
+ }
+ }.apply(null);
+ new FailingGenericSafeClose()
+ {
+ protected void internalClose() throws Throwable
+ {
+ throw new Throwable();
+ }
+ }.apply(null);
+ final RuntimeException runtimeException = new RuntimeException();
+ new FailingGenericSafeClose()
+ {
+ protected void internalClose() throws Throwable
+ {
+ throw runtimeException;
+ }
+ }.apply(runtimeException);
+ final Error error = new Error();
+ new FailingGenericSafeClose()
+ {
+ protected void internalClose() throws Throwable
+ {
+ throw error;
+ }
+ }.apply(error);
+ }
+
+ public abstract static class FailingGenericSafeClose
+ {
+ public void apply(Throwable expectedThrowable)
+ {
+ try
+ {
+ IOTools.safeClose(this);
+ assertNull(expectedThrowable);
+ }
+ catch (Throwable t)
+ {
+ assertEquals(expectedThrowable, t);
+ }
+ }
+
+ public void close() throws Throwable
+ {
+ internalClose();
+ }
+
+ protected abstract void internalClose() throws Throwable;
+ }
+
+ public void testOutputStreamSafeClose()
+ {
+ IOTools.safeClose((OutputStream)null);
+ final SynchronizedBoolean called = new SynchronizedBoolean(false);
+ IOTools.safeClose(new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ called.set(true);
+ }
+ });
+ assertTrue(called.get());
+ IOTools.safeClose(new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ throw new IOException();
+ }
+ });
+ final Error error = new Error();
+ try
+ {
+ IOTools.safeClose(new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ throw error;
+ }
+ });
+ fail("Was expecting an error exception");
+ }
+ catch (Error expected)
+ {
+ assertEquals(error, expected);
+ }
+ final RuntimeException runtimeException = new RuntimeException();
+ try
+ {
+ IOTools.safeClose(new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ throw runtimeException;
+ }
+ });
+ fail("Was expecting a runtime exception");
+ }
+ catch (RuntimeException expected)
+ {
+ assertEquals(runtimeException, expected);
+ }
+ }
+
+ public abstract static class AbstractOutputStream extends OutputStream
+ {
+ public void write(int b) throws IOException
+ {
+ }
+ }
+
+ public void testInputStreamSafeClose()
+ {
+ IOTools.safeClose((InputStream)null);
+ final SynchronizedBoolean called = new SynchronizedBoolean(false);
+ IOTools.safeClose(new AbstractInputStream()
+ {
+ public void close() throws IOException
+ {
+ called.set(true);
+ }
+ });
+ assertTrue(called.get());
+ IOTools.safeClose(new AbstractInputStream()
+ {
+ public void close() throws IOException
+ {
+ throw new IOException();
+ }
+ });
+ final Error error = new Error();
+ try
+ {
+ IOTools.safeClose(new AbstractInputStream()
+ {
+ public void close() throws IOException
+ {
+ throw error;
+ }
+ });
+ fail("Was expecting an error exception");
+ }
+ catch (Error expected)
+ {
+ assertEquals(error, expected);
+ }
+ final RuntimeException runtimeException = new RuntimeException();
+ try
+ {
+ IOTools.safeClose(new AbstractInputStream()
+ {
+ public void close() throws IOException
+ {
+ throw runtimeException;
+ }
+ });
+ fail("Was expecting a runtime exception");
+ }
+ catch (RuntimeException expected)
+ {
+ assertEquals(runtimeException, expected);
+ }
+ }
+
+ public abstract static class AbstractInputStream extends InputStream
+ {
+ public int read() throws IOException
+ {
+ return 0;
+ }
+ }
+
+ public void testReaderSafeClose()
+ {
+ IOTools.safeClose((Reader)null);
+ final SynchronizedBoolean called = new SynchronizedBoolean(false);
+ IOTools.safeClose(new AbstractReader()
+ {
+ public void close() throws IOException
+ {
+ called.set(true);
+ }
+ });
+ assertTrue(called.get());
+ IOTools.safeClose(new AbstractReader()
+ {
+ public void close() throws IOException
+ {
+ throw new IOException();
+ }
+ });
+ final Error error = new Error();
+ try
+ {
+ IOTools.safeClose(new AbstractReader()
+ {
+ public void close() throws IOException
+ {
+ throw error;
+ }
+ });
+ fail("Was expecting an error exception");
+ }
+ catch (Error expected)
+ {
+ assertEquals(error, expected);
+ }
+ final RuntimeException runtimeException = new RuntimeException();
+ try
+ {
+ IOTools.safeClose(new AbstractReader()
+ {
+ public void close() throws IOException
+ {
+ throw runtimeException;
+ }
+ });
+ fail("Was expecting a runtime exception");
+ }
+ catch (RuntimeException expected)
+ {
+ assertEquals(runtimeException, expected);
+ }
+ }
+
+ public abstract static class AbstractReader extends Reader
+ {
+ public int read(char cbuf[], int off, int len) throws IOException
+ {
+ return 0;
+ }
+ }
+
+ public void testWriterSafeClose()
+ {
+ IOTools.safeClose((Writer)null);
+ final SynchronizedBoolean called = new SynchronizedBoolean(false);
+ IOTools.safeClose(new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ called.set(true);
+ }
+ });
+ assertTrue(called.get());
+ IOTools.safeClose(new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ throw new IOException();
+ }
+ });
+ final Error error = new Error();
+ try
+ {
+ IOTools.safeClose(new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ throw error;
+ }
+ });
+ fail("Was expecting an error exception");
+ }
+ catch (Error expected)
+ {
+ assertEquals(error, expected);
+ }
+ final RuntimeException runtimeException = new RuntimeException();
+ try
+ {
+ IOTools.safeClose(new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ throw runtimeException;
+ }
+ });
+ fail("Was expecting a runtime exception");
+ }
+ catch (RuntimeException expected)
+ {
+ assertEquals(runtimeException, expected);
+ }
+ }
+
+ public abstract static class AbstractWriter extends Writer
+ {
+ public void write(char cbuf[], int off, int len) throws IOException
+ {
+ }
+ public void flush() throws IOException
+ {
+ }
+ }
+
+ public void testCopyInputStreamToOutputStream() throws IOException
+ {
+ try
+ {
+ IOTools.copy(null, new ByteArrayOutputStream());
+ fail("Was expecting an IAE");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ try
+ {
+ IOTools.copy(new ByteArrayInputStream(new byte[0]), null);
+ fail("Was expecting an IOException");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ final SynchronizedBoolean closeCalled1 = new SynchronizedBoolean(false);
+ final IOException ioException1 = new IOException();
+ try
+ {
+ IOTools.copy(new AbstractInputStream()
+ {
+ public int read() throws IOException
+ {
+ throw ioException1;
+ }
+ public void close() throws IOException
+ {
+ closeCalled1.set(true);
+ }
+ }, new ByteArrayOutputStream());
+ fail("Was expecting an IOException");
+ }
+ catch (IOException expected)
+ {
+ assertEquals(ioException1, expected);
+ assertFalse(closeCalled1.get());
+ }
+
+ //
+ final SynchronizedBoolean closeCalled2 = new SynchronizedBoolean(false);
+ IOTools.copy(new AbstractInputStream()
+ {
+ public int read() throws IOException
+ {
+ return -1;
+ }
+ public void close() throws IOException
+ {
+ closeCalled2.set(true);
+ }
+ }, new ByteArrayOutputStream());
+ assertFalse(closeCalled2.get());
+
+ //
+ final IOException ioException2 = new IOException();
+ final SynchronizedBoolean closeCalled3 = new SynchronizedBoolean(false);
+ try
+ {
+ IOTools.copy(new ByteArrayInputStream(new byte[1]), new AbstractOutputStream()
+ {
+ public void write(int b) throws IOException
+ {
+ throw ioException2;
+ }
+ public void close() throws IOException
+ {
+ closeCalled3.set(true);
+ }
+ });
+ fail("Was expecting an IOException");
+ }
+ catch (IOException expected)
+ {
+ assertEquals(ioException2, expected);
+ }
+
+ //
+ final SynchronizedBoolean closeCalled4 = new SynchronizedBoolean(false);
+ IOTools.copy(new ByteArrayInputStream(new byte[1]), new AbstractOutputStream()
+ {
+ public void close() throws IOException
+ {
+ closeCalled4.set(true);
+ }
+ });
+
+ //
+ Random random = new Random();
+ byte[] bytes = new byte[2000];
+ random.nextBytes(bytes);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length);
+ IOTools.copy(new ByteArrayInputStream((byte[])bytes.clone()), baos);
+ ExtendedAssert.assertEquals(bytes, baos.toByteArray());
+ }
+
+ public void testCopyReaderToWriter() throws IOException
+ {
+ try
+ {
+ IOTools.copy(null, new CharArrayWriter());
+ fail("Was expecting an IAE");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ try
+ {
+ IOTools.copy(new CharArrayReader(new char[0]), null);
+ fail("Was expecting an IOException");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ //
+ final SynchronizedBoolean closeCalled1 = new SynchronizedBoolean(false);
+ final IOException ioException1 = new IOException();
+ try
+ {
+ IOTools.copy(new AbstractReader()
+ {
+ public int read(char cbuf[], int off, int len) throws IOException
+ {
+ throw ioException1;
+ }
+ public void close() throws IOException
+ {
+ closeCalled1.set(true);
+ }
+ }, new CharArrayWriter());
+ fail("Was expecting an IOException");
+ }
+ catch (IOException expected)
+ {
+ assertEquals(ioException1, expected);
+ assertFalse(closeCalled1.get());
+ }
+
+ //
+ final SynchronizedBoolean closeCalled2 = new SynchronizedBoolean(false);
+ IOTools.copy(new AbstractReader()
+ {
+ public int read(char cbuf[], int off, int len) throws IOException
+ {
+ return -1;
+ }
+ public void close() throws IOException
+ {
+ closeCalled2.set(true);
+ }
+ }, new CharArrayWriter());
+ assertFalse(closeCalled2.get());
+
+ //
+ final IOException ioException2 = new IOException();
+ final SynchronizedBoolean closeCalled3 = new SynchronizedBoolean(false);
+ try
+ {
+ IOTools.copy(new CharArrayReader(new char[1]), new AbstractWriter()
+ {
+ public void write(char cbuf[], int off, int len) throws IOException
+ {
+ throw ioException2;
+ }
+ public void close() throws IOException
+ {
+ closeCalled3.set(true);
+ }
+ });
+ fail("Was expecting an IOException");
+ }
+ catch (IOException expected)
+ {
+ assertEquals(ioException2, expected);
+ }
+
+ //
+ final SynchronizedBoolean closeCalled4 = new SynchronizedBoolean(false);
+ IOTools.copy(new CharArrayReader(new char[1]), new AbstractWriter()
+ {
+ public void close() throws IOException
+ {
+ closeCalled4.set(true);
+ }
+ });
+
+ //
+ Random random = new Random();
+ char[] chars = new char[2000];
+ for (int i = 0; i < chars.length; i++)
+ {
+ chars[i] = (char)random.nextInt();
+
+ }
+ CharArrayWriter caw = new CharArrayWriter(chars.length);
+ IOTools.copy(new CharArrayReader((char[])chars.clone()), caw);
+ ExtendedAssert.assertEquals(chars, caw.toCharArray());
+ }
+}
Modified: trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/core/src/main/org/jboss/portal/core/controller/handler/HTTPResponse.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.core.controller.handler;
import org.jboss.portal.server.ServerInvocationContext;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;
@@ -111,8 +111,8 @@
}
finally
{
- Tools.safeClose(in);
- Tools.safeClose(sout);
+ IOTools.safeClose(in);
+ IOTools.safeClose(sout);
}
}
}
Modified: trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/core/src/main/org/jboss/portal/core/deployment/jboss/ObjectDeployment.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -24,9 +24,9 @@
import org.jboss.deployment.DeploymentException;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.xml.NullEntityResolver;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.core.model.portal.metadata.PortalObjectMetaData;
import org.jboss.portal.core.model.portal.metadata.BuildContext;
import org.jboss.portal.core.model.portal.PortalObject;
@@ -109,7 +109,7 @@
{
// Load xml document
log.debug("Loading portal metadata from " + url);
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
DocumentBuilder builder = XML.getDocumentBuilderFactory().newDocumentBuilder();
EntityResolver entityResolver = factory.getPortalObjectEntityResolver();
if (entityResolver == null)
@@ -261,7 +261,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified: trunk/core/src/main/org/jboss/portal/core/deployment/jboss/PortletAppDeployment.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/deployment/jboss/PortletAppDeployment.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/core/src/main/org/jboss/portal/core/deployment/jboss/PortletAppDeployment.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -26,11 +26,11 @@
import org.jboss.mx.util.MBeanProxyExt;
import org.jboss.portal.common.net.URLNavigator;
import org.jboss.portal.common.net.URLVisitor;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.value.StringValue;
import org.jboss.portal.common.value.Value;
import org.jboss.portal.common.xml.NullEntityResolver;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.core.model.instance.metadata.InstanceMetaData;
import org.jboss.portal.core.model.instance.metadata.PreferencesMetaData;
import org.jboss.portal.core.metadata.ServiceMetaData;
@@ -173,7 +173,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
DocumentBuilder builder = XML.getDocumentBuilderFactory().newDocumentBuilder();
EntityResolver entityResolver = factory.getPortalObjectEntityResolver();
if (entityResolver == null)
@@ -222,7 +222,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
}
@@ -259,7 +259,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(pwa.getServletContext().getResourceAsStream("/WEB-INF/portlet-instances.xml"));
+ in = IOTools.safeBufferedWrapper(pwa.getServletContext().getResourceAsStream("/WEB-INF/portlet-instances.xml"));
if (in != null)
{
DocumentBuilder builder = XML.getDocumentBuilderFactory().newDocumentBuilder();
@@ -313,7 +313,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
// Create instances when we have
Modified: trunk/core/src/main/org/jboss/portal/test/core/Utils.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/Utils.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/core/src/main/org/jboss/portal/test/core/Utils.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -26,7 +26,7 @@
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.FileInputStream;
import java.sql.Connection;
@@ -44,7 +44,7 @@
public static IDataSet getDataSet(String file) throws Exception
{
- return new FlatXmlDataSet(Tools.safeBufferedWrapper(new FileInputStream(file)));
+ return new FlatXmlDataSet(IOTools.safeBufferedWrapper(new FileInputStream(file)));
}
public static IDatabaseConnection getConnection() throws Exception
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/servlet/CMSExportServlet.java
===================================================================
--- trunk/core-cms/src/main/org/jboss/portal/core/cms/servlet/CMSExportServlet.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/core-cms/src/main/org/jboss/portal/core/cms/servlet/CMSExportServlet.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.core.cms.servlet;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
@@ -55,7 +55,7 @@
response.setContentLength((int)file.length());
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
- InputStream in = Tools.safeBufferedWrapper(new FileInputStream(file));
+ InputStream in = IOTools.safeBufferedWrapper(new FileInputStream(file));
ServletOutputStream sout = response.getOutputStream();
byte[] buf = new byte[2048];
int len;
Modified: trunk/format/src/main/org/jboss/portal/format/template/TemplateLoader.java
===================================================================
--- trunk/format/src/main/org/jboss/portal/format/template/TemplateLoader.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/format/src/main/org/jboss/portal/format/template/TemplateLoader.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.format.template;
import org.dom4j.Document;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.format.util.CLLoader;
import org.jboss.portal.format.util.Loader;
@@ -162,7 +162,7 @@
}
finally
{
- Tools.safeClose(tin);
+ IOTools.safeClose(tin);
}
}
Modified: trunk/jems/src/main/org/jboss/portal/jems/hibernate/ByteArrayBlob.java
===================================================================
--- trunk/jems/src/main/org/jboss/portal/jems/hibernate/ByteArrayBlob.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/jems/src/main/org/jboss/portal/jems/hibernate/ByteArrayBlob.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.jems.hibernate;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -45,7 +45,7 @@
public ByteArrayBlob(InputStream in) throws IOException
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
- Tools.copy(in, out);
+ IOTools.copy(in, out);
_bytes = out.toByteArray();
}
Modified: trunk/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java
===================================================================
--- trunk/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/jems/src/main/org/jboss/portal/jems/hibernate/SessionFactoryBinder.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -35,8 +35,8 @@
import org.hibernate.tool.hbm2ddl.SchemaUpdate;
import org.jboss.portal.common.util.CLResourceLoader;
import org.jboss.portal.common.util.LoaderResource;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.URLTools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import javax.naming.InitialContext;
@@ -236,7 +236,7 @@
}
finally
{
- Tools.safeClose(conn);
+ IOTools.safeClose(conn);
}
}
log.debug("Using dialect " + dialectName);
@@ -304,7 +304,7 @@
}
finally
{
- Tools.safeClose(session);
+ IOTools.safeClose(session);
}
// There was no sql grammar exception - schema is ok!
if (bad == 0)
Modified: trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/portletrequests/PortletRequestsSequenceBuilder.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/portletrequests/PortletRequestsSequenceBuilder.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/portlet/src/main/org/jboss/portal/test/portlet/jsr168/ext/portletrequests/PortletRequestsSequenceBuilder.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -27,6 +27,7 @@
import org.jboss.portal.test.framework.driver.http.response.InvokeGetResponse;
import org.jboss.portal.common.test.driver.DriverResponse;
import org.jboss.portal.common.http.HttpRequest;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.test.framework.driver.http.response.InvokePostResponse;
import org.jboss.portal.test.framework.portlet.PortletTest;
import org.jboss.portal.test.framework.portlet.PortletTestDriver;
@@ -174,7 +175,7 @@
{
in = request.getPortletInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
- Tools.copy(in, out);
+ IOTools.copy(in, out);
out.close();
byte[] bytes = out.toByteArray();
assertEquals(-1, in.read());
@@ -190,7 +191,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
try
{
@@ -250,7 +251,7 @@
{
in = request.getReader();
StringWriter out = new StringWriter();
- Tools.copy(in, out);
+ IOTools.copy(in, out);
out.close();
byte[] bytes = out.toString().getBytes("UTF-8");
assertEquals(-1, in.read());
@@ -266,7 +267,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
try
{
Modified: trunk/portlet/src/main/org/jboss/portal/test/portlet/session/TestClassLoader.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/test/portlet/session/TestClassLoader.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/portlet/src/main/org/jboss/portal/test/portlet/session/TestClassLoader.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -22,7 +22,7 @@
******************************************************************************/
package org.jboss.portal.test.portlet.session;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -51,7 +51,7 @@
{
in = ReplicatedValue.class.getClassLoader().getResourceAsStream(ReplicatedValue.class.getName().replace('.', '/') + ".class");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Tools.copy(in, baos);
+ IOTools.copy(in, baos);
byte[] bytes = baos.toByteArray();
replicatedValueClass = defineClass(ReplicatedValue.class.getName(), bytes, 0, bytes.length);
}
@@ -61,7 +61,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
return replicatedValueClass;
Modified: trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeployment.java
===================================================================
--- trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeployment.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeployment.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,8 +23,8 @@
package org.jboss.portal.portlet.deployment.jboss;
import org.jboss.deployment.DeploymentException;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.xml.NullEntityResolver;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.portlet.deployment.JBossApplicationMetaDataFactory;
import org.jboss.portal.portlet.deployment.PortletApplicationMetaDataFactory;
import org.jboss.portal.portlet.deployment.ValueTrimmingFilter;
@@ -245,7 +245,7 @@
InputStream sourceTLD = null;
try
{
- sourceTLD = Tools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jboss/portal/portlet/portlet.tld"));
+ sourceTLD = IOTools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream("org/jboss/portal/portlet/portlet.tld"));
pwa.importFile("/WEB-INF", "portlet.tld", sourceTLD, false);
}
catch (IOException e)
@@ -254,7 +254,7 @@
}
finally
{
- Tools.safeClose(sourceTLD);
+ IOTools.safeClose(sourceTLD);
}
}
@@ -263,7 +263,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
PortletApplicationMetaDataFactory factory = new PortletApplicationMetaDataFactory();
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
PortletApplicationMetaData portletAppMD = (PortletApplicationMetaData)unmarshaller.unmarshal(in, new ValueTrimmingFilter(factory), null);
@@ -272,7 +272,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
@@ -284,7 +284,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(servletContext.getResourceAsStream("/WEB-INF/jboss-portlet.xml"));
+ in = IOTools.safeBufferedWrapper(servletContext.getResourceAsStream("/WEB-INF/jboss-portlet.xml"));
if (in != null)
{
log.info("Parsing " + contextPath + "jboss-portlet.xml");
@@ -312,7 +312,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
return jbossAppMD;
}
Modified: trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java
===================================================================
--- trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/portlet-server/src/main/org/jboss/portal/portlet/deployment/jboss/PortletAppDeploymentFactory.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.portlet.deployment.jboss;
import org.jboss.deployment.DeploymentException;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.portlet.container.PortletApplicationRegistry;
import org.jboss.portal.portlet.deployment.JBossApplicationMetaDataFactory;
import org.jboss.portal.portlet.deployment.ValueTrimmingFilter;
@@ -226,7 +226,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream(standardJBossApplicationMetaDataLocation));
+ in = IOTools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream(standardJBossApplicationMetaDataLocation));
if (in != null)
{
JBossApplicationMetaDataFactory factory = createJBossApplicationMetaDataFactory();
@@ -240,7 +240,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
}
Modified: trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebApp.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,9 +23,9 @@
package org.jboss.portal.server.deployment;
import org.apache.log4j.Logger;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.xml.NullEntityResolver;
+import org.jboss.portal.common.io.IOTools;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
@@ -160,14 +160,14 @@
OutputStream target = null;
try
{
- target = Tools.safeBufferedWrapper(new FileOutputStream(new File(parentDir, name)));
- Tools.copy(source, target);
+ target = IOTools.safeBufferedWrapper(new FileOutputStream(new File(parentDir, name)));
+ IOTools.copy(source, target);
done = true;
log.debug("Copied file" + name + " to location " + parentDirRelativePath);
}
finally
{
- Tools.safeClose(target);
+ IOTools.safeClose(target);
}
}
return done;
@@ -213,7 +213,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(getServletContext().getResourceAsStream("/WEB-INF/jboss-app.xml"));
+ in = IOTools.safeBufferedWrapper(getServletContext().getResourceAsStream("/WEB-INF/jboss-app.xml"));
if (in != null)
{
DocumentBuilder builder = XML.getDocumentBuilderFactory().newDocumentBuilder();
@@ -244,7 +244,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified: trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/test/src/main/org/jboss/portal/test/framework/embedded/DSConfig.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,9 +23,9 @@
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.portal.common.io.IOTools;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -125,7 +125,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
Document doc = XML.getDocumentBuilderFactory().newDocumentBuilder().parse(in);
for (Iterator i = XML.getChildrenIterator(doc.getDocumentElement(), "directory"); i.hasNext();)
{
@@ -177,7 +177,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified: trunk/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/test/src/main/org/jboss/portal/test/framework/embedded/DataSourceSupport.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,9 +23,9 @@
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.portal.common.io.IOTools;
import org.jboss.resource.adapter.jdbc.local.LocalTxDataSource;
import org.jboss.resource.connectionmanager.CachedConnectionManagerReference;
import org.w3c.dom.Document;
@@ -118,8 +118,8 @@
}
finally
{
- Tools.safeClose(st);
- Tools.safeClose(conn);
+ IOTools.safeClose(st);
+ IOTools.safeClose(conn);
}
}
catch (Exception e)
@@ -267,7 +267,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
Document doc = XML.getDocumentBuilderFactory().newDocumentBuilder().parse(in);
for (Iterator i = XML.getChildrenIterator(doc.getDocumentElement(), "datasource"); i.hasNext();)
{
@@ -303,7 +303,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
}
Modified: trunk/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/test/src/main/org/jboss/portal/test/framework/embedded/HibernateSupport.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -32,7 +32,7 @@
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.jboss.portal.common.io.IOTools;
import org.w3c.dom.Element;
import org.w3c.dom.Document;
@@ -350,7 +350,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
Document doc = XML.getDocumentBuilderFactory().newDocumentBuilder().parse(in);
for (Iterator i = XML.getChildrenIterator(doc.getDocumentElement(), "configuration"); i.hasNext();)
{
@@ -384,7 +384,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
}
Modified: trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeployment.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeployment.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutDeployment.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -24,7 +24,7 @@
import org.jboss.logging.Logger;
import org.jboss.deployment.DeploymentException;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.server.deployment.PortalWebApp;
import org.jboss.portal.server.deployment.jboss.Deployment;
import org.jboss.portal.theme.LayoutException;
@@ -76,7 +76,7 @@
InputStream in = null;
try
{
- in = Tools.safeBufferedWrapper(url.openStream());
+ in = IOTools.safeBufferedWrapper(url.openStream());
LayoutService layoutService = factory.getLayoutService();
RuntimeContext ctx = new RuntimeContext(pwa.getId(), pwa.getServletContext(), pwa.getContextPath(), pwa.getClassLoader());
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
@@ -94,7 +94,7 @@
}
finally
{
- Tools.safeClose(in);
+ IOTools.safeClose(in);
}
// Make sure that the portal-layout.tld is available in the local context
@@ -104,7 +104,7 @@
InputStream source = null;
try
{
- source = Tools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream("conf/theme/portal-layout.tld"));
+ source = IOTools.safeBufferedWrapper(Thread.currentThread().getContextClassLoader().getResourceAsStream("conf/theme/portal-layout.tld"));
pwa.importFile("/WEB-INF/theme", "portal-layout.tld", source, false);
}
catch (IOException e)
@@ -113,7 +113,7 @@
}
finally
{
- Tools.safeClose(source);
+ IOTools.safeClose(source);
}
}
else
Modified: trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeployment.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeployment.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/LayoutFeaturesDeployment.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -24,7 +24,7 @@
import org.jboss.deployment.DeploymentException;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.server.deployment.PortalWebApp;
import org.jboss.portal.server.deployment.jboss.Deployment;
import org.jboss.portal.theme.LayoutException;
@@ -96,7 +96,7 @@
InputStream stream = null;
try
{
- stream = Tools.safeBufferedWrapper(url.openStream());
+ stream = IOTools.safeBufferedWrapper(url.openStream());
if (isRenderSet)
{
List renderSets = (List)UnmarshallerFactory.newInstance().newUnmarshaller().unmarshal(stream, new RenderSetMetaDataFactory(), null);
@@ -109,7 +109,7 @@
}
finally
{
- Tools.safeClose(stream);
+ IOTools.safeClose(stream);
}
}
else
Modified: trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeployment.java
===================================================================
--- trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeployment.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/theme/src/main/org/jboss/portal/theme/deployment/jboss/ThemeDeployment.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -24,7 +24,7 @@
import org.jboss.logging.Logger;
import org.jboss.deployment.DeploymentException;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.server.deployment.PortalWebApp;
import org.jboss.portal.server.deployment.jboss.Deployment;
import org.jboss.portal.theme.RuntimeContext;
@@ -72,7 +72,7 @@
InputStream themeStream = null;
try
{
- themeStream = Tools.safeBufferedWrapper(url.openStream());
+ themeStream = IOTools.safeBufferedWrapper(url.openStream());
RuntimeContext ctx = new RuntimeContext(pwa.getId(), pwa.getServletContext(), pwa.getContextPath(), pwa.getClassLoader());
List portalThemes = (List)UnmarshallerFactory.newInstance().newUnmarshaller().unmarshal(themeStream, new PortalThemeMetaDataFactory(), null);
@@ -88,7 +88,7 @@
}
finally
{
- Tools.safeClose(themeStream);
+ IOTools.safeClose(themeStream);
}
}
Modified: trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -29,7 +29,7 @@
import org.jboss.portal.widget.google.GGPreferenceInfo;
import org.jboss.portal.widget.google.type.DataType;
import org.jboss.portal.widget.google.type.EnumType;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import java.net.URL;
import java.io.File;
@@ -146,7 +146,7 @@
{
File file = new File(url.getPath());
InputStream io = new FileInputStream(file);
- byte[] bytes = Tools.getBytes(io);
+ byte[] bytes = IOTools.getBytes(io);
io.close();
return bytes;
}
Modified: trunk/workflow/src/main/org/jboss/portal/workflow/cms/ApprovePublishImpl.java
===================================================================
--- trunk/workflow/src/main/org/jboss/portal/workflow/cms/ApprovePublishImpl.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/workflow/src/main/org/jboss/portal/workflow/cms/ApprovePublishImpl.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -37,6 +37,7 @@
import org.jboss.portal.jems.as.JNDI;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jbpm.JbpmContext;
import org.jbpm.db.GraphSession;
@@ -155,7 +156,7 @@
}
finally
{
- Tools.safeClose(is);
+ IOTools.safeClose(is);
Tools.safeClose(jbpmContext);
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/services/AbstractJNDIServiceFactory.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/services/AbstractJNDIServiceFactory.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/services/AbstractJNDIServiceFactory.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.wsrp.services;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import org.jboss.portal.jems.as.system.AbstractJBossService;
import javax.naming.InitialContext;
@@ -150,7 +150,7 @@
}
finally
{
- Tools.safeClose(ctx);
+ IOTools.safeClose(ctx);
}
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/services/RemoteSOAPInvokerServiceFactory.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -25,8 +25,8 @@
import org.jboss.logging.Logger;
import org.jboss.portal.common.util.ParameterValidation;
-import org.jboss.portal.common.util.Tools;
import org.jboss.portal.common.util.URLStreamOpeningThread;
+import org.jboss.portal.common.io.IOTools;
import org.xml.sax.InputSource;
import javax.wsdl.Definition;
@@ -224,7 +224,7 @@
{
// Timeout occurred; thread has not finished
// todo: do we need more clean up here?
- Tools.safeClose(thread.getInputStream());
+ IOTools.safeClose(thread.getInputStream());
throw new RuntimeException("Couldn't connect to " + wsdlURL + " within " + delayMillis / 1000
+ " seconds. Check your connection parameters or the URL.");
}
@@ -233,7 +233,7 @@
// Finished
if (thread.isConnected() && !thread.isError())
{
- InputStream is = Tools.safeBufferedWrapper(thread.getInputStream());
+ InputStream is = IOTools.safeBufferedWrapper(thread.getInputStream());
return new InputSource(is);
}
else
@@ -310,7 +310,7 @@
try
{
log.info("Resolved to: " + wsdlImport);
- InputStream is = Tools.safeBufferedWrapper(new URL(wsdlImport).openStream());
+ InputStream is = IOTools.safeBufferedWrapper(new URL(wsdlImport).openStream());
if (is == null)
{
throw new IllegalArgumentException("Cannot import wsdl from [" + wsdlImport + "]");
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java 2007-06-03 09:56:50 UTC (rev 7373)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/servlet/RequestDumperFilter.java 2007-06-03 19:20:39 UTC (rev 7374)
@@ -23,7 +23,7 @@
package org.jboss.portal.wsrp.servlet;
import org.jboss.logging.Logger;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.io.IOTools;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
@@ -94,7 +94,7 @@
if (reader != null)
{
StringWriter buffer = new StringWriter();
- Tools.copy(reader, buffer);
+ IOTools.copy(reader, buffer);
tmp.append("body=").append(buffer.toString());
}
16 years, 11 months
JBoss Portal SVN: r7373 - in trunk/common: src/main/org/jboss/portal/common/reflect and 6 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-06-03 05:56:50 -0400 (Sun, 03 Jun 2007)
New Revision: 7373
Added:
trunk/common/src/main/org/jboss/portal/common/reflect/Reflection.java
trunk/common/src/main/org/jboss/portal/test/common/reflect/
trunk/common/src/main/org/jboss/portal/test/common/reflect/Class1.java
trunk/common/src/main/org/jboss/portal/test/common/reflect/Class2.java
trunk/common/src/main/org/jboss/portal/test/common/reflect/Class3.java
trunk/common/src/main/org/jboss/portal/test/common/reflect/ModifierTestCase.java
trunk/common/src/main/org/jboss/portal/test/common/reflect/ReflectionTestCase.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/
trunk/common/src/main/org/jboss/portal/test/common/test/junit/BaseTest.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/POJOJunitTestTestCase.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleInheritedTest.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleSuperTest.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleTest.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleInheritedTest.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleSuperTest.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleTest.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleInheritedTest.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleSuperTest.java
trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleTest.java
Removed:
trunk/common/src/main/org/jboss/portal/test/common/ModifierTestCase.java
Modified:
trunk/common/build.xml
trunk/common/src/main/org/jboss/portal/common/test/driver/command/StartTestCommand.java
trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java
Log:
- added util to find methods on classes that are either public or declared by the class or its super classes
- added test case for POJOJunitTest life cycle call backs
Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml 2007-06-02 23:51:26 UTC (rev 7372)
+++ trunk/common/build.xml 2007-06-03 09:56:50 UTC (rev 7373)
@@ -210,6 +210,12 @@
</x-sysproperty>
<x-test>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.reflect.ReflectionTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.reflect.ModifierTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.test.junit.POJOJunitTestTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.test.InfoTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.test.TestParameterValueTestCase"/>
+ <test todir="${test.reports}" name="org.jboss.portal.test.common.test.TestParametrizationTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.adapter.AdapterTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.BundleNameIteratorTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.BundleNameParserTestCase"/>
@@ -217,9 +223,6 @@
<test todir="${test.reports}" name="org.jboss.portal.test.common.ObjectLoaderTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.MarkupTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.TypedMapTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.common.test.InfoTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.common.test.TestParameterValueTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.common.test.TestParametrizationTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.FastURLEncoderTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.AbstractInvocationContextTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.LocaleFormatTestCase"/>
@@ -242,7 +245,6 @@
<test todir="${test.reports}" name="org.jboss.portal.test.common.CopyOnWriteRegistryTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.URLToolsTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.ToolsTestCase"/>
- <test todir="${test.reports}" name="org.jboss.portal.test.common.ModifierTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.IteratorStatusTestCase"/>
<test todir="${test.reports}" name="org.jboss.portal.test.common.PathMapperTestCase"/>
</x-test>
Added: trunk/common/src/main/org/jboss/portal/common/reflect/Reflection.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/reflect/Reflection.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/reflect/Reflection.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,142 @@
+/******************************************************************************
+ * 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.reflect;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class Reflection
+{
+
+ /**
+ * Search a method on the specified class. The search will try find methods with any scope and will
+ * start with the provided class. First it will inspect the public method on the class, if one is found
+ * then this method is returned. If no public method is found then it will inspect the declared methods
+ * of the provided class and its super classes.
+ *
+ * @param clazz the class to inspect
+ * @param methodName the method name
+ * @param parameterTypes the parameter types
+ * @return the matched method or null
+ * @throws IllegalArgumentException if one argument is null
+ */
+ public static Method findMethod(
+ Class clazz,
+ String methodName,
+ Class[] parameterTypes) throws IllegalArgumentException
+ {
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("No class provided");
+ }
+ if (methodName == null)
+ {
+ throw new IllegalArgumentException("No method name provided");
+ }
+ if (parameterTypes == null)
+ {
+ throw new IllegalArgumentException("No parameter types provided");
+ }
+ for (int i = 0; i < parameterTypes.length; i++)
+ {
+ if (parameterTypes[i] == null)
+ {
+ throw new IllegalArgumentException("Null parameter type at element=" + i);
+ }
+ }
+
+ // First try a public method, which could be an implemented from an interface
+ try
+ {
+ return clazz.getMethod(methodName, parameterTypes);
+ }
+ catch (NoSuchMethodException ignore)
+ {
+ }
+
+ //
+ return findDeclaredMethod(clazz, methodName, parameterTypes);
+ }
+
+ /**
+ * Search a declared method on the specified class and its super classes.
+ *
+ * @param clazz the class to inspect
+ * @param methodName the method name
+ * @param parameterTypes the parameter types
+ * @return the matched method or null
+ * @throws IllegalArgumentException if one argument is null
+ */
+ private static Method findDeclaredMethod(
+ Class clazz,
+ String methodName,
+ Class[] parameterTypes) throws IllegalArgumentException
+ {
+ if (clazz == null)
+ {
+ throw new IllegalArgumentException("No class provided");
+ }
+ if (methodName == null)
+ {
+ throw new IllegalArgumentException("No method name provided");
+ }
+ if (parameterTypes == null)
+ {
+ throw new IllegalArgumentException("No parameter types provided");
+ }
+ for (int i = 0; i < parameterTypes.length; i++)
+ {
+ if (parameterTypes[i] == null)
+ {
+ throw new IllegalArgumentException("Null parameter type at element=" + i);
+ }
+ }
+
+ //
+ try
+ {
+ return clazz.getDeclaredMethod(methodName, parameterTypes);
+ }
+ catch (NoSuchMethodException ignore)
+ {
+ }
+
+ //
+ Class parentClass = clazz.getSuperclass();
+ if (parentClass != null)
+ {
+ Method method = findDeclaredMethod(parentClass, methodName, parameterTypes);
+ if (method != null)
+ {
+ return method;
+ }
+ }
+
+ // Nothing found
+ return null;
+ }
+
+}
Modified: trunk/common/src/main/org/jboss/portal/common/test/driver/command/StartTestCommand.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/test/driver/command/StartTestCommand.java 2007-06-02 23:51:26 UTC (rev 7372)
+++ trunk/common/src/main/org/jboss/portal/common/test/driver/command/StartTestCommand.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -50,6 +50,11 @@
this.parametrization = parametrization;
}
+ public StartTestCommand() throws IllegalArgumentException
+ {
+ this(new TestParametrization());
+ }
+
/**
* Return the test parametrization.
*
Modified: trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java 2007-06-02 23:51:26 UTC (rev 7372)
+++ trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -39,6 +39,7 @@
import org.jboss.portal.common.test.info.TestInfo;
import org.jboss.portal.common.test.info.TestItemInfo;
import org.jboss.portal.common.test.info.TestParameterInfo;
+import org.jboss.portal.common.reflect.Reflection;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@@ -146,14 +147,11 @@
}
// Invoke setUp() if it exists
- try
+ Method setUp = Reflection.findMethod(testClass, "setUp", new Class[0]);
+ if (setUp != null && (setUp.getModifiers() & (Modifier.PRIVATE | Modifier.STATIC | Modifier.ABSTRACT)) == 0)
{
- Method setUp = testClass.getMethod("setUp", new Class[0]);
invokeNoArg(test, setUp, true);
}
- catch (NoSuchMethodException ignore)
- {
- }
// Invoke test joinpoint
Method method = (Method)testMap.get(testId);
@@ -187,12 +185,12 @@
// Invoke tearDown() if it exists
try
{
- Method tearDown = testClass.getMethod("tearDown", new Class[0]);
- invokeNoArg(test, tearDown, true);
+ Method tearDown = Reflection.findMethod(testClass, "tearDown", new Class[0]);
+ if (tearDown != null && (tearDown.getModifiers() & (Modifier.PRIVATE | Modifier.STATIC | Modifier.ABSTRACT)) == 0)
+ {
+ invokeNoArg(test, tearDown, true);
+ }
}
- catch (NoSuchMethodException ignore)
- {
- }
catch (Exception e)
{
e.printStackTrace();
Deleted: trunk/common/src/main/org/jboss/portal/test/common/ModifierTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/ModifierTestCase.java 2007-06-02 23:51:26 UTC (rev 7372)
+++ trunk/common/src/main/org/jboss/portal/test/common/ModifierTestCase.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -1,121 +0,0 @@
-/******************************************************************************
- * 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.test.common;
-
-import junit.framework.TestCase;
-import org.jboss.portal.common.reflect.Modifier;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class ModifierTestCase extends TestCase
-{
-
- public void testIsReadableProperty() throws Exception
- {
- try
- {
- Modifier.isReadableProperty(null);
- fail("Was expecting an IAE");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- assertTrue(Modifier.isReadableProperty(Bean.class.getDeclaredField("publicField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("privateField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("protectedField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("packageProtectedField")));
-
- assertTrue(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalPublicField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalPrivateField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalProtectedField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalPackageProtectedField")));
-
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("staticPublicField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("staticPrivateField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("staticProtectedField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("staticPackageProtectedField")));
-
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalStaticPublicField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalStaticPrivateField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalStaticProtectedField")));
- assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalStaticPackageProtectedField")));
- }
-
- public void testIsWritableProperty() throws Exception
- {
- try
- {
- Modifier.isWritableProperty(null);
- fail("Was expecting an IAE");
- }
- catch (IllegalArgumentException expected)
- {
- }
-
- assertTrue(Modifier.isWritableProperty(Bean.class.getDeclaredField("publicField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("privateField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("protectedField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("packageProtectedField")));
-
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalPublicField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalPrivateField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalProtectedField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalPackageProtectedField")));
-
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("staticPublicField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("staticPrivateField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("staticProtectedField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("staticPackageProtectedField")));
-
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalStaticPublicField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalStaticPrivateField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalStaticProtectedField")));
- assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalStaticPackageProtectedField")));
- }
-
- private static class Bean
- {
- public Object publicField;
- private Object privateField;
- protected Object protectedField;
- Object packageProtectedField;
-
- final public Object finalPublicField = new Object();
- final private Object finalPrivateField = new Object();
- final protected Object finalProtectedField = new Object();
- final Object finalPackageProtectedField = new Object();
-
- static public Object staticPublicField;
- static private Object staticPrivateField;
- static protected Object staticProtectedField;
- static Object staticPackageProtectedField;
-
- final static public Object finalStaticPublicField = new Object();
- final static private Object finalStaticPrivateField = new Object();
- final static protected Object finalStaticProtectedField = new Object();
- final static Object finalStaticPackageProtectedField = new Object();
- }
-}
Added: trunk/common/src/main/org/jboss/portal/test/common/reflect/Class1.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/reflect/Class1.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/reflect/Class1.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * 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.test.common.reflect;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class Class1
+{
+
+ private void privateMethod()
+ {
+ }
+
+ public abstract void publicAbstractMethodOfClass1();
+
+ protected abstract void protectedAbstractMethodOfClass1();
+
+ private void privateMethodOfClass1()
+ {
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/reflect/Class2.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/reflect/Class2.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/reflect/Class2.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * 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.test.common.reflect;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class Class2 extends Class1
+{
+
+ private void privateMethod()
+ {
+ }
+
+ public void publicAbstractMethodOfClass1()
+ {
+ }
+
+ protected void protectedAbstractMethodOfClass1()
+ {
+ }
+
+ public void publicMethodOfClass2()
+ {
+ }
+
+ protected void protectedMethodOfClass2()
+ {
+ }
+
+ private void privateMethodOfClass2()
+ {
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/reflect/Class3.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/reflect/Class3.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/reflect/Class3.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * 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.test.common.reflect;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class Class3 extends Class2
+{
+ private void privateMethod()
+ {
+ }
+
+ private void privateMethodOfClass3()
+ {
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/reflect/ModifierTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/reflect/ModifierTestCase.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/reflect/ModifierTestCase.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,121 @@
+/******************************************************************************
+ * 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.test.common.reflect;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.reflect.Modifier;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ModifierTestCase extends TestCase
+{
+
+ public void testIsReadableProperty() throws Exception
+ {
+ try
+ {
+ Modifier.isReadableProperty(null);
+ fail("Was expecting an IAE");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ assertTrue(Modifier.isReadableProperty(Bean.class.getDeclaredField("publicField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("privateField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("protectedField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("packageProtectedField")));
+
+ assertTrue(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalPublicField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalPrivateField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalProtectedField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalPackageProtectedField")));
+
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("staticPublicField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("staticPrivateField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("staticProtectedField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("staticPackageProtectedField")));
+
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalStaticPublicField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalStaticPrivateField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalStaticProtectedField")));
+ assertFalse(Modifier.isReadableProperty(Bean.class.getDeclaredField("finalStaticPackageProtectedField")));
+ }
+
+ public void testIsWritableProperty() throws Exception
+ {
+ try
+ {
+ Modifier.isWritableProperty(null);
+ fail("Was expecting an IAE");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ assertTrue(Modifier.isWritableProperty(Bean.class.getDeclaredField("publicField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("privateField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("protectedField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("packageProtectedField")));
+
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalPublicField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalPrivateField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalProtectedField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalPackageProtectedField")));
+
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("staticPublicField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("staticPrivateField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("staticProtectedField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("staticPackageProtectedField")));
+
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalStaticPublicField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalStaticPrivateField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalStaticProtectedField")));
+ assertFalse(Modifier.isWritableProperty(Bean.class.getDeclaredField("finalStaticPackageProtectedField")));
+ }
+
+ private static class Bean
+ {
+ public Object publicField;
+ private Object privateField;
+ protected Object protectedField;
+ Object packageProtectedField;
+
+ final public Object finalPublicField = new Object();
+ final private Object finalPrivateField = new Object();
+ final protected Object finalProtectedField = new Object();
+ final Object finalPackageProtectedField = new Object();
+
+ static public Object staticPublicField;
+ static private Object staticPrivateField;
+ static protected Object staticProtectedField;
+ static Object staticPackageProtectedField;
+
+ final static public Object finalStaticPublicField = new Object();
+ final static private Object finalStaticPrivateField = new Object();
+ final static protected Object finalStaticProtectedField = new Object();
+ final static Object finalStaticPackageProtectedField = new Object();
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/reflect/ReflectionTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/reflect/ReflectionTestCase.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/reflect/ReflectionTestCase.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -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.test.common.reflect;
+
+import junit.framework.TestCase;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.jboss.portal.common.reflect.Reflection;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ReflectionTestCase extends TestCase
+{
+
+ public void testClass1()
+ {
+ assertEquals(Class1.class, "privateMethod", Modifier.PRIVATE, Reflection.findMethod(Class1.class, "privateMethod", new Class[0]));
+
+ //
+ assertEquals(Class1.class, "privateMethodOfClass1", Modifier.PRIVATE, Reflection.findMethod(Class1.class, "privateMethodOfClass1", new Class[0]));
+ assertEquals(Class1.class, "publicAbstractMethodOfClass1", Modifier.PUBLIC | Modifier.ABSTRACT, Reflection.findMethod(Class1.class, "publicAbstractMethodOfClass1", new Class[0]));
+ assertEquals(Class1.class, "protectedAbstractMethodOfClass1", Modifier.PROTECTED | Modifier.ABSTRACT, Reflection.findMethod(Class1.class, "protectedAbstractMethodOfClass1", new Class[0]));
+ }
+
+ public void testClass2()
+ {
+ assertEquals(Class2.class, "privateMethod", Modifier.PRIVATE, Reflection.findMethod(Class2.class, "privateMethod", new Class[0]));
+
+ //
+ assertEquals(Class1.class, "privateMethodOfClass1", Modifier.PRIVATE, Reflection.findMethod(Class2.class, "privateMethodOfClass1", new Class[0]));
+ assertEquals(Class2.class, "publicAbstractMethodOfClass1", Modifier.PUBLIC, Reflection.findMethod(Class2.class, "publicAbstractMethodOfClass1", new Class[0]));
+ assertEquals(Class2.class, "protectedAbstractMethodOfClass1", Modifier.PROTECTED, Reflection.findMethod(Class2.class, "protectedAbstractMethodOfClass1", new Class[0]));
+
+ //
+ assertEquals(Class2.class, "privateMethodOfClass2", Modifier.PRIVATE, Reflection.findMethod(Class2.class, "privateMethodOfClass2", new Class[0]));
+ assertEquals(Class2.class, "publicMethodOfClass2", Modifier.PUBLIC, Reflection.findMethod(Class2.class, "publicMethodOfClass2", new Class[0]));
+ assertEquals(Class2.class, "protectedMethodOfClass2", Modifier.PROTECTED, Reflection.findMethod(Class2.class, "protectedMethodOfClass2", new Class[0]));
+ }
+
+ public void testClass3()
+ {
+ assertEquals(Class3.class, "privateMethod", Modifier.PRIVATE, Reflection.findMethod(Class3.class, "privateMethod", new Class[0]));
+
+ //
+ assertEquals(Class1.class, "privateMethodOfClass1", Modifier.PRIVATE, Reflection.findMethod(Class3.class, "privateMethodOfClass1", new Class[0]));
+ assertEquals(Class2.class, "publicAbstractMethodOfClass1", Modifier.PUBLIC, Reflection.findMethod(Class3.class, "publicAbstractMethodOfClass1", new Class[0]));
+ assertEquals(Class2.class, "protectedAbstractMethodOfClass1", Modifier.PROTECTED, Reflection.findMethod(Class3.class, "protectedAbstractMethodOfClass1", new Class[0]));
+
+ //
+ assertEquals(Class2.class, "privateMethodOfClass2", Modifier.PRIVATE, Reflection.findMethod(Class3.class, "privateMethodOfClass2", new Class[0]));
+ assertEquals(Class2.class, "publicMethodOfClass2", Modifier.PUBLIC, Reflection.findMethod(Class3.class, "publicMethodOfClass2", new Class[0]));
+ assertEquals(Class2.class, "protectedMethodOfClass2", Modifier.PROTECTED, Reflection.findMethod(Class3.class, "protectedMethodOfClass2", new Class[0]));
+
+ //
+ assertEquals(Class3.class, "privateMethodOfClass3", Modifier.PRIVATE, Reflection.findMethod(Class3.class, "privateMethodOfClass3", new Class[0]));
+ }
+
+ private void assertEquals(Class declaringClass, String methodName, int modifiers, Method effectiveMethod)
+ {
+ assertNotNull(effectiveMethod);
+ assertEquals(declaringClass, effectiveMethod.getDeclaringClass());
+ assertEquals(modifiers, effectiveMethod.getModifiers());
+ assertEquals(methodName, effectiveMethod.getName());
+ }
+
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/BaseTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/BaseTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/BaseTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,44 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class BaseTest
+{
+ protected final Map state = new HashMap();
+ protected final void add(String methodName)
+ {
+ Integer count = (Integer)state.get(methodName);
+ if (count == null)
+ {
+ count = new Integer(0);
+ }
+ state.put(methodName, new Integer(count.intValue() + 1));
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/POJOJunitTestTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/POJOJunitTestTestCase.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/POJOJunitTestTestCase.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,92 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+import junit.framework.TestCase;
+import org.jboss.portal.common.test.junit.POJOJUnitTest;
+import org.jboss.portal.common.test.driver.command.StartTestCommand;
+import org.jboss.portal.common.util.MapBuilder;
+
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class POJOJunitTestTestCase extends TestCase
+{
+
+ /** . */
+ private static final Map lifeCycleCalledState = new MapBuilder().put("testFoo", new Integer(1)).put("setUp", new Integer(1)).put("tearDown", new Integer(1)).toHashMap();
+
+ /** . */
+ private static final Map lifeCycleNotCalledState = new MapBuilder().put("testFoo", new Integer(1)).toHashMap();
+
+ public void testDeclaredPublicLifeCycle() throws Exception
+ {
+ PublicLifecycleTest publicLifecycle = new PublicLifecycleTest();
+ POJOJUnitTest test = new POJOJUnitTest(publicLifecycle);
+ test.invoke("testFoo", new StartTestCommand());
+ assertEquals(lifeCycleCalledState, publicLifecycle.state);
+ }
+
+ public void testDeclaredProtectedLifeCycle() throws Exception
+ {
+ ProtectedLifecycleTest protectedLifecycle = new ProtectedLifecycleTest();
+ POJOJUnitTest test = new POJOJUnitTest(protectedLifecycle);
+ test.invoke("testFoo", new StartTestCommand());
+ assertEquals(lifeCycleCalledState, protectedLifecycle.state);
+ }
+
+ public void testDeclaredPrivateLifeCycle() throws Exception
+ {
+ PrivateLifecycleTest privateLifecycle = new PrivateLifecycleTest();
+ POJOJUnitTest test = new POJOJUnitTest(privateLifecycle);
+ test.invoke("testFoo", new StartTestCommand());
+ assertEquals(lifeCycleNotCalledState, privateLifecycle.state);
+ }
+
+ public void testInheritedPublicLifeCycle() throws Exception
+ {
+ PublicLifecycleInheritedTest publicLifecycleInherited = new PublicLifecycleInheritedTest();
+ POJOJUnitTest test = new POJOJUnitTest(publicLifecycleInherited);
+ test.invoke("testFoo", new StartTestCommand());
+ assertEquals(lifeCycleCalledState, publicLifecycleInherited.state);
+ }
+
+ public void testInheritedProtectedLifeCycle() throws Exception
+ {
+ ProtectedLifecycleInheritedTest protectedLifecycleInherited = new ProtectedLifecycleInheritedTest();
+ POJOJUnitTest test = new POJOJUnitTest(protectedLifecycleInherited);
+ test.invoke("testFoo", new StartTestCommand());
+ assertEquals(lifeCycleCalledState, protectedLifecycleInherited.state);
+ }
+
+ public void testInheritedPrivateLifeCycle() throws Exception
+ {
+ PrivateLifecycleInheritedTest privateLifecycleInherited = new PrivateLifecycleInheritedTest();
+ POJOJUnitTest test = new POJOJUnitTest(privateLifecycleInherited);
+ test.invoke("testFoo", new StartTestCommand());
+ assertEquals(lifeCycleNotCalledState, privateLifecycleInherited.state);
+ }
+}
\ No newline at end of file
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleInheritedTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleInheritedTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleInheritedTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PrivateLifecycleInheritedTest extends PrivateLifecycleSuperTest
+{
+ public void testFoo()
+ {
+ add("testFoo");
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleSuperTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleSuperTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleSuperTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class PrivateLifecycleSuperTest extends BaseTest
+{
+ private void setUp()
+ {
+ add("setUp");
+ }
+ private void tearDown()
+ {
+ add("tearDown");
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/PrivateLifecycleTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PrivateLifecycleTest extends BaseTest
+{
+ private void setUp()
+ {
+ add("setUp");
+ }
+ private void tearDown()
+ {
+ add("tearDown");
+ }
+ public void testFoo()
+ {
+ add("testFoo");
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleInheritedTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleInheritedTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleInheritedTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ProtectedLifecycleInheritedTest extends ProtectedLifecycleSuperTest
+{
+ public void testFoo()
+ {
+ add("testFoo");
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleSuperTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleSuperTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleSuperTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class ProtectedLifecycleSuperTest extends BaseTest
+{
+ protected void setUp()
+ {
+ add("setUp");
+ }
+ protected void tearDown()
+ {
+ add("tearDown");
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/ProtectedLifecycleTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ProtectedLifecycleTest extends BaseTest
+{
+ protected void setUp()
+ {
+ add("setUp");
+ }
+ protected void tearDown()
+ {
+ add("tearDown");
+ }
+ public void testFoo()
+ {
+ add("testFoo");
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleInheritedTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleInheritedTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleInheritedTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PublicLifecycleInheritedTest extends PublicLifecycleSuperTest
+{
+ public void testFoo()
+ {
+ add("testFoo");
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleSuperTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleSuperTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleSuperTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class PublicLifecycleSuperTest extends BaseTest
+{
+ public void setUp()
+ {
+ add("setUp");
+ }
+ public void tearDown()
+ {
+ add("tearDown");
+ }
+}
Added: trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleTest.java (rev 0)
+++ trunk/common/src/main/org/jboss/portal/test/common/test/junit/PublicLifecycleTest.java 2007-06-03 09:56:50 UTC (rev 7373)
@@ -0,0 +1,43 @@
+/******************************************************************************
+ * 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.test.common.test.junit;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PublicLifecycleTest extends BaseTest
+{
+ public void setUp()
+ {
+ add("setUp");
+ }
+ public void tearDown()
+ {
+ add("tearDown");
+ }
+ public void testFoo()
+ {
+ add("testFoo");
+ }
+}
16 years, 11 months
JBoss Portal SVN: r7372 - trunk/common/src/main/org/jboss/portal/common/test/junit.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-06-02 19:51:26 -0400 (Sat, 02 Jun 2007)
New Revision: 7372
Modified:
trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java
Log:
- make isInvokable not have side effect (state mutation)
- revert to getMethod() rather than getDeclaredMethod() as getDeclaredMethod() would not pick up the method from a parent class
Modified: trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java 2007-06-01 21:54:37 UTC (rev 7371)
+++ trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java 2007-06-02 23:51:26 UTC (rev 7372)
@@ -148,15 +148,8 @@
// Invoke setUp() if it exists
try
{
- Method setUpMethod = testClass.getDeclaredMethod("setUp", new Class[0]);
- if (isInvokable(setUpMethod, true))
- {
- setUpMethod.invoke(test, new Object[0]);
- }
- else
- {
- // Maybe print a warn !!! ???
- }
+ Method setUp = testClass.getMethod("setUp", new Class[0]);
+ invokeNoArg(test, setUp, true);
}
catch (NoSuchMethodException ignore)
{
@@ -194,11 +187,8 @@
// Invoke tearDown() if it exists
try
{
- Method tearDown = testClass.getDeclaredMethod("tearDown", new Class[0]);
- if (isInvokable(tearDown, true))
- {
- tearDown.invoke(test, new Object[0]);
- }
+ Method tearDown = testClass.getMethod("tearDown", new Class[0]);
+ invokeNoArg(test, tearDown, true);
}
catch (NoSuchMethodException ignore)
{
@@ -223,7 +213,8 @@
Method method = methods[j];
//
- if (isInvokable(method))
+ int modifiers = method.getModifiers();
+ if (Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers))
{
String methodName = method.getName();
if (methodName.startsWith("test") &&
@@ -266,27 +257,36 @@
this.containerInfo = containerInfo;
}
- /** Return true if the method is invokable. */
- private boolean isInvokable(Method m)
+ /**
+ * Invoke a method that takes no argument.
+ *
+ * @param m the method to invoke
+ * @param allowProtected enable the invocation of non accessible methods
+ * @throws IllegalAccessException
+ * @throws InvocationTargetException
+ */
+ private static void invokeNoArg(Object test, Method m, boolean allowProtected) throws IllegalAccessException, InvocationTargetException
{
- return isInvokable(m, false);
- }
-
- private boolean isInvokable(Method m, boolean allowProtected)
- {
int modifiers = m.getModifiers();
- boolean accessible = Modifier.isPublic(modifiers);
- if (allowProtected)
+ //
+ if (Modifier.isStatic(modifiers) || Modifier.isAbstract(modifiers))
{
- accessible |= Modifier.isProtected(modifiers);
- if (accessible)
+ return;
+ }
+
+ //
+ if (!Modifier.isPublic(modifiers))
+ {
+ if (!allowProtected)
{
- m.setAccessible(true);
+ return;
}
+ m.setAccessible(true);
}
- return accessible && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers);
+ //
+ m.invoke(test, new Object[0]);
}
public static TestSuite createTestSuite(Class testClass, Map parameterMap) throws Exception
16 years, 11 months
JBoss Portal SVN: r7371 - in trunk/wsrp: src/resources/tests/test-consumer-jar/org/jboss/portal/test/wsrp/consumer and 1 other directory.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-06-01 17:54:37 -0400 (Fri, 01 Jun 2007)
New Revision: 7371
Modified:
trunk/wsrp/build.xml
trunk/wsrp/src/resources/tests/test-consumer-jar/org/jboss/portal/test/wsrp/consumer/persistent-jboss-beans.xml
Log:
More work on ConsumerRegistryTestCase: (still not working, now failing to get a JTA transaction, probably need to look into AOP for that):
- Added necessary dependencies for ConsumerRegistryTestCase.
- Fixed bean injections in ConsumerRegistryService.
Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml 2007-06-01 21:46:43 UTC (rev 7370)
+++ trunk/wsrp/build.xml 2007-06-01 21:54:37 UTC (rev 7371)
@@ -781,11 +781,20 @@
<sysproperty key="test.root" value="${build.lib}/tests"/>
</x-sysproperty>
<x-classpath>
- <fileset dir="${build.lib}" includes="portal-wsrp-lib.jar"/>
- <fileset dir="${build.lib.test}" includes="test-consumer-lib.jar"/>
+ <pathelement location="${build.lib}/portal-wsrp.sar"/>
+ <!-- Access to conf/consumer/hibernate/domain.hbm.xml -->
+ <pathelement location="${build.lib}/portal-wsrp-lib.jar"/>
+ <pathelement location="${build.lib.test}/test-consumer-lib.jar"/>
<pathelement location="${jboss.portal-test.root}/etc"/>
<!-- Needed to access datasources.xml -->
<path refid="jboss.microcontainer.classpath"/>
+
+ <!-- Required for test framework -->
+ <path refid="apache.collections.classpath"/>
+ <path refid="cglib.cglib.classpath"/>
+ <path refid="aop.classpath"/>
+ <path refid="asm.asm.classpath"/>
+
<path refid="library.classpath"/>
<path refid="dependentmodule.classpath"/>
<path refid="ws.classpath"/>
Modified: trunk/wsrp/src/resources/tests/test-consumer-jar/org/jboss/portal/test/wsrp/consumer/persistent-jboss-beans.xml
===================================================================
--- trunk/wsrp/src/resources/tests/test-consumer-jar/org/jboss/portal/test/wsrp/consumer/persistent-jboss-beans.xml 2007-06-01 21:46:43 UTC (rev 7370)
+++ trunk/wsrp/src/resources/tests/test-consumer-jar/org/jboss/portal/test/wsrp/consumer/persistent-jboss-beans.xml 2007-06-01 21:54:37 UTC (rev 7371)
@@ -74,12 +74,8 @@
<bean name="ConsumerRegistry" class="org.jboss.portal.wsrp.consumer.ConsumerRegistryService">
<property name="sessionFactoryJNDIName">java:/SessionFactory</property>
- <property name="federatingPortletInvoker">
- <inject bean="FederatingPortletInvoker" property="federatingPortletInvoker"/>
- </property>
- <property name="portalEventListenerRegistry">
- <inject bean="PortalEventListenerRegistry" property="portalEventListenerRegistry"/>
- </property>
+ <property name="federatingPortletInvoker"><inject bean="FederatingPortletInvoker"/></property>
+ <property name="portalEventListenerRegistry"><inject bean="PortalEventListenerRegistry"/></property>
</bean>
<bean name="TestBean" class="org.jboss.portal.test.wsrp.consumer.ConsumerRegistryTestCase">
16 years, 11 months
JBoss Portal SVN: r7370 - in trunk: test/src/main/org/jboss/portal/test/framework and 1 other directory.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-06-01 17:46:43 -0400 (Fri, 01 Jun 2007)
New Revision: 7370
Modified:
trunk/core/src/main/org/jboss/portal/test/core/PortalBaseTestCase.java
trunk/test/src/main/org/jboss/portal/test/framework/AbstractPortalTestCase.java
Log:
- Moved security related code back to PortalBaseTestCase to avoid leaking JEE stuff to test.
Modified: trunk/core/src/main/org/jboss/portal/test/core/PortalBaseTestCase.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/test/core/PortalBaseTestCase.java 2007-06-01 08:50:47 UTC (rev 7369)
+++ trunk/core/src/main/org/jboss/portal/test/core/PortalBaseTestCase.java 2007-06-01 21:46:43 UTC (rev 7370)
@@ -35,8 +35,11 @@
import org.jboss.security.SecurityAssociation;
import org.jboss.security.SimpleGroup;
import org.jboss.security.SimplePrincipal;
+import org.jboss.security.jacc.DelegatingPolicy;
import javax.security.auth.Subject;
+import javax.security.jacc.PolicyContext;
+import java.security.Policy;
import java.security.Principal;
import java.security.acl.Group;
import java.util.HashSet;
@@ -51,6 +54,29 @@
*/
public abstract class PortalBaseTestCase extends AbstractPortalTestCase
{
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ // Security
+ PolicyContext.setContextID("ctxid");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ /**
+ * Need to delete the context information set in the policy provider
+ * for this test as it will affect the next test that is being run.
+ * The alternative is that each test sets its own context id.
+ */
+ DelegatingPolicy p = (DelegatingPolicy)Policy.getPolicy();
+ p.delete("ctxid");
+ p.refresh();
+
+ super.tearDown();
+ }
+
protected Set getDefaultSecurityConstraints()
{
Set constraints = new HashSet();
Modified: trunk/test/src/main/org/jboss/portal/test/framework/AbstractPortalTestCase.java
===================================================================
--- trunk/test/src/main/org/jboss/portal/test/framework/AbstractPortalTestCase.java 2007-06-01 08:50:47 UTC (rev 7369)
+++ trunk/test/src/main/org/jboss/portal/test/framework/AbstractPortalTestCase.java 2007-06-01 21:46:43 UTC (rev 7370)
@@ -35,11 +35,8 @@
import org.jboss.portal.common.test.junit.POJOJUnitTest;
import org.jboss.portal.test.framework.embedded.DataSourceSupport;
import org.jboss.portal.test.framework.embedded.HibernateSupport;
-import org.jboss.security.jacc.DelegatingPolicy;
-import javax.security.jacc.PolicyContext;
import java.net.URL;
-import java.security.Policy;
/**
* @author <a href="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
@@ -96,23 +93,10 @@
runtimeContext.addBean("DataSourceConfig", dataSourceConfigParameter);
runtimeContext.addBean("HibernateConfig", HibernateSupport.getConfig(dataSourceConfigParameter.getName()));
runtimeContext.start();
-
- //
- PolicyContext.setContextID("ctxid");
-
- System.out.println("AbstractPortalTestCase.setUp");
}
protected void tearDown() throws Exception
{
- /**
- * Need to delete the context information set in the policy provider
- * for this test as it will affect the next test that is being run.
- * The alternative is that each test sets its own context id.
- */
- DelegatingPolicy p = (DelegatingPolicy)Policy.getPolicy();
- p.delete("ctxid");
- p.refresh();
runtimeContext.stop();
}
16 years, 11 months
JBoss Portal SVN: r7369 - trunk/common/src/main/org/jboss/portal/common/test/junit.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-06-01 04:50:47 -0400 (Fri, 01 Jun 2007)
New Revision: 7369
Modified:
trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java
Log:
- Now allow invocation of setUp and tearDown by overriding protected status of these methods.
Modified: trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java 2007-05-31 06:02:24 UTC (rev 7368)
+++ trunk/common/src/main/org/jboss/portal/common/test/junit/POJOJUnitTest.java 2007-06-01 08:50:47 UTC (rev 7369)
@@ -148,8 +148,8 @@
// Invoke setUp() if it exists
try
{
- Method setUpMethod = testClass.getMethod("setUp", new Class[0]);
- if (isInvokable(setUpMethod))
+ Method setUpMethod = testClass.getDeclaredMethod("setUp", new Class[0]);
+ if (isInvokable(setUpMethod, true))
{
setUpMethod.invoke(test, new Object[0]);
}
@@ -194,8 +194,8 @@
// Invoke tearDown() if it exists
try
{
- Method tearDown = testClass.getMethod("tearDown", new Class[0]);
- if (isInvokable(tearDown))
+ Method tearDown = testClass.getDeclaredMethod("tearDown", new Class[0]);
+ if (isInvokable(tearDown, true))
{
tearDown.invoke(test, new Object[0]);
}
@@ -269,8 +269,24 @@
/** Return true if the method is invokable. */
private boolean isInvokable(Method m)
{
+ return isInvokable(m, false);
+ }
+
+ private boolean isInvokable(Method m, boolean allowProtected)
+ {
int modifiers = m.getModifiers();
- return Modifier.isPublic(modifiers) && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers);
+
+ boolean accessible = Modifier.isPublic(modifiers);
+ if (allowProtected)
+ {
+ accessible |= Modifier.isProtected(modifiers);
+ if (accessible)
+ {
+ m.setAccessible(true);
+ }
+ }
+
+ return accessible && !Modifier.isAbstract(modifiers) && !Modifier.isStatic(modifiers);
}
public static TestSuite createTestSuite(Class testClass, Map parameterMap) throws Exception
16 years, 11 months