[jboss-cvs] JBoss Messaging SVN: r6611 - in trunk: src/main/org/jboss/messaging/ra and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Apr 28 20:56:44 EDT 2009
Author: clebert.suconic at jboss.com
Date: 2009-04-28 20:56:44 -0400 (Tue, 28 Apr 2009)
New Revision: 6611
Added:
trunk/tests/src/org/jboss/messaging/tests/unit/ra/ResourceAdapterTest.java
Modified:
trunk/build-messaging.xml
trunk/src/main/org/jboss/messaging/ra/JBMConnectionMetaData.java
trunk/src/main/org/jboss/messaging/ra/JBMCredential.java
trunk/src/main/org/jboss/messaging/ra/JBMManagedConnection.java
trunk/src/main/org/jboss/messaging/ra/JBMManagedConnectionFactory.java
trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java
trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivation.java
trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivationSpec.java
trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java
trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
Log:
Adding basic test on the resoruce-adapter. (Validating properties and creating a basic activation). and some basic cleanup
Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/build-messaging.xml 2009-04-29 00:56:44 UTC (rev 6611)
@@ -206,6 +206,7 @@
<path refid="jboss.jboss.mdr.classpath"/>
<path refid="easymock.easymock.classpath"/>
<path refid="easymock.classextension.classpath"/>
+ <path location="${build.jars.dir}/${ra.jar.name}"/>
<path location="${build.jars.dir}/${jms.jar.name}"/>
<path location="${build.jars.dir}/${transports.jar.name}"/>
<path location="${build.jars.dir}/${security.jar.name}"/>
Modified: trunk/src/main/org/jboss/messaging/ra/JBMConnectionMetaData.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMConnectionMetaData.java 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/src/main/org/jboss/messaging/ra/JBMConnectionMetaData.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -140,9 +140,9 @@
* Get the JMS XPropertyNames
* @return The names
*/
- public Enumeration getJMSXPropertyNames()
+ public Enumeration<Object> getJMSXPropertyNames()
{
- Vector v = new Vector();
+ Vector<Object> v = new Vector<Object>();
return v.elements();
}
}
Modified: trunk/src/main/org/jboss/messaging/ra/JBMCredential.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMCredential.java 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/src/main/org/jboss/messaging/ra/JBMCredential.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -22,18 +22,15 @@
package org.jboss.messaging.ra;
import java.io.Serializable;
-import java.util.Set;
-import java.util.Iterator;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Set;
-import javax.security.auth.Subject;
-
+import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.SecurityException;
-import javax.resource.spi.ConnectionRequestInfo;
-
import javax.resource.spi.security.PasswordCredential;
+import javax.security.auth.Subject;
import org.jboss.messaging.core.logging.Logger;
@@ -171,7 +168,7 @@
/**
* Privileged class to get credentials
*/
- private static class GetCredentialAction implements PrivilegedAction
+ private static class GetCredentialAction implements PrivilegedAction<PasswordCredential>
{
/** The subject */
private Subject subject;
@@ -197,17 +194,16 @@
* Run
* @return The credential
*/
- public Object run()
+ public PasswordCredential run()
{
if (trace)
log.trace("run()");
- Set creds = subject.getPrivateCredentials(PasswordCredential.class);
+ Set<PasswordCredential> creds = subject.getPrivateCredentials(PasswordCredential.class);
PasswordCredential pwdc = null;
- Iterator credentials = creds.iterator();
- while (credentials.hasNext())
+
+ for (PasswordCredential curCred: creds)
{
- PasswordCredential curCred = (PasswordCredential) credentials.next();
if (curCred.getManagedConnectionFactory().equals(mcf))
{
pwdc = curCred;
Modified: trunk/src/main/org/jboss/messaging/ra/JBMManagedConnection.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMManagedConnection.java 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/src/main/org/jboss/messaging/ra/JBMManagedConnection.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@@ -93,10 +92,10 @@
private AtomicBoolean isDestroyed = new AtomicBoolean(false);
/** Event listeners */
- private List eventListeners;
+ private List<ConnectionEventListener> eventListeners;
/** Handles */
- private Set handles;
+ private Set<JBMSession> handles;
/** Lock */
private ReentrantLock lock = new ReentrantLock();
@@ -132,8 +131,8 @@
this.cri = cri;
this.userName = userName;
this.password = password;
- this.eventListeners = Collections.synchronizedList(new ArrayList());
- this.handles = Collections.synchronizedSet(new HashSet());
+ this.eventListeners = Collections.synchronizedList(new ArrayList<ConnectionEventListener>());
+ this.handles = Collections.synchronizedSet(new HashSet<JBMSession>());
this.connection = null;
this.xaConnection = null;
@@ -188,7 +187,7 @@
if (isDestroyed.get())
throw new IllegalStateException("The managed connection is already destroyed");
- Object session = new JBMSession(this, (JBMConnectionRequestInfo)cxRequestInfo);
+ JBMSession session = new JBMSession(this, (JBMConnectionRequestInfo)cxRequestInfo);
handles.add(session);
return session;
}
@@ -215,9 +214,10 @@
log.trace("Ignored error stopping connection", t);
}
- Iterator it = handles.iterator();
- while (it.hasNext())
- ((JBMSession)it.next()).destroy();
+ for (JBMSession session: handles)
+ {
+ session.destroy();
+ }
handles.clear();
}
Modified: trunk/src/main/org/jboss/messaging/ra/JBMManagedConnectionFactory.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMManagedConnectionFactory.java 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/src/main/org/jboss/messaging/ra/JBMManagedConnectionFactory.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -333,7 +333,7 @@
*/
public String getConnectorClassName()
{
- return mcfProperties.getConnectionParameters();
+ return mcfProperties.getConnectorClassName();
}
public void setConnectorClassName(String value)
Modified: trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/src/main/org/jboss/messaging/ra/JBMResourceAdapter.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -21,6 +21,20 @@
*/
package org.jboss.messaging.ra;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import javax.jms.Session;
+import javax.resource.ResourceException;
+import javax.resource.spi.ActivationSpec;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.ResourceAdapterInternalException;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.work.WorkManager;
+import javax.transaction.xa.XAResource;
+
import org.jboss.messaging.core.client.ClientSession;
import org.jboss.messaging.core.client.ClientSessionFactory;
import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
@@ -33,20 +47,6 @@
import org.jboss.messaging.ra.inflow.JBMActivation;
import org.jboss.messaging.ra.inflow.JBMActivationSpec;
-import javax.jms.Session;
-import javax.resource.ResourceException;
-import javax.resource.spi.ActivationSpec;
-import javax.resource.spi.BootstrapContext;
-import javax.resource.spi.ResourceAdapter;
-import javax.resource.spi.ResourceAdapterInternalException;
-import javax.resource.spi.endpoint.MessageEndpointFactory;
-import javax.resource.spi.work.WorkManager;
-import javax.transaction.xa.XAResource;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.atomic.AtomicBoolean;
-
/**
* The resource adapter for JBoss Messaging
*
@@ -90,7 +90,7 @@
/**
* The activations by activation spec
*/
- private Map activations;
+ private Map<ActivationSpec, JBMActivation> activations;
private JBossConnectionFactory jBossConnectionFactory;
@@ -107,7 +107,7 @@
raProperties = new JBMRAProperties();
sessionFactory = null;
configured = new AtomicBoolean(false);
- activations = new ConcurrentHashMap();
+ activations = new ConcurrentHashMap<ActivationSpec, JBMActivation>();
}
/**
@@ -153,7 +153,7 @@
log.trace("endpointDeactivation(" + endpointFactory + ", " + spec + ")");
}
- JBMActivation activation = (JBMActivation)activations.remove(spec);
+ JBMActivation activation = activations.remove(spec);
if (activation != null)
{
activation.stop();
@@ -206,23 +206,19 @@
log.trace("stop()");
}
- for (Iterator i = activations.entrySet().iterator(); i.hasNext();)
+ for (Map.Entry<ActivationSpec, JBMActivation> entry: activations.entrySet())
{
- Map.Entry entry = (Map.Entry)i.next();
try
{
- JBMActivation activation = (JBMActivation)entry.getValue();
- if (activation != null)
- {
- activation.stop();
- }
+ entry.getValue().stop();
}
catch (Exception ignored)
{
log.debug("Ignored", ignored);
}
- i.remove();
}
+
+ activations.clear();
log.info("JBoss Messaging resource adapter stopped");
}
@@ -1018,6 +1014,16 @@
}
/**
+ * Get failover on server shutdown
+ *
+ * @return The value
+ */
+ public Boolean getFailoverOnServerShutdown()
+ {
+ return isFailoverOnServerShutdown();
+ }
+
+ /**
* Set failover on server shutdown
*
* @param failoverOnServerShutdown The value
Modified: trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivation.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivation.java 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivation.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -23,9 +23,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.jms.Destination;
@@ -397,62 +395,77 @@
protected void setupDestination() throws Exception
{
- Context ctx = new InitialContext();
- log.debug("Using context " + ctx.getEnvironment() + " for " + spec);
- if (trace)
- log.trace("setupDestination(" + ctx + ")");
-
+
String destinationName = spec.getDestination();
- String destinationTypeString = spec.getDestinationType();
- if (destinationTypeString != null && !destinationTypeString.trim().equals(""))
+ if (spec.isUseJNDI())
{
- log.debug("Destination type defined as " + destinationTypeString);
-
- Class<?> destinationType;
- if (Topic.class.getName().equals(destinationTypeString))
+ Context ctx = new InitialContext();
+ log.debug("Using context " + ctx.getEnvironment() + " for " + spec);
+ if (trace)
+ log.trace("setupDestination(" + ctx + ")");
+
+ String destinationTypeString = spec.getDestinationType();
+ if (destinationTypeString != null && !destinationTypeString.trim().equals(""))
{
- destinationType = Topic.class;
- isTopic = true;
- }
- else
- {
- destinationType = Queue.class;
- }
-
- log.debug("Retrieving destination " + destinationName + " of type " + destinationType.getName());
- try
- {
- destination = (JBossDestination)Util.lookup(ctx, destinationName, destinationType);
- }
- catch (Exception e)
- {
- if (destinationName == null)
+ log.debug("Destination type defined as " + destinationTypeString);
+
+ Class<?> destinationType;
+ if (Topic.class.getName().equals(destinationTypeString))
{
- System.out.println("destination is null, rethrowing exception");
- throw e;
+ destinationType = Topic.class;
+ isTopic = true;
}
- // If there is no binding on naming, we will just create a new instance
- if (isTopic)
+ else
{
- destination = new JBossTopic(destinationName.substring(destinationName.lastIndexOf('/') + 1));
+ destinationType = Queue.class;
}
- else
+
+ log.debug("Retrieving destination " + destinationName + " of type " + destinationType.getName());
+ try
{
- destination = new JBossQueue(destinationName.substring(destinationName.lastIndexOf('/') + 1));
+ destination = (JBossDestination)Util.lookup(ctx, destinationName, destinationType);
}
+ catch (Exception e)
+ {
+ if (destinationName == null)
+ {
+ System.out.println("destination is null, rethrowing exception");
+ throw e;
+ }
+ // If there is no binding on naming, we will just create a new instance
+ if (isTopic)
+ {
+ destination = new JBossTopic(destinationName.substring(destinationName.lastIndexOf('/') + 1));
+ }
+ else
+ {
+ destination = new JBossQueue(destinationName.substring(destinationName.lastIndexOf('/') + 1));
+ }
+ }
}
+ else
+ {
+ log.debug("Destination type not defined");
+ log.debug("Retrieving destination " + destinationName + " of type " + Destination.class.getName());
+
+ destination = (JBossDestination)Util.lookup(ctx, destinationName, Destination.class);
+ if (destination instanceof Topic)
+ {
+ isTopic = true;
+ }
+ }
}
else
{
- log.debug("Destination type not defined");
- log.debug("Retrieving destination " + destinationName + " of type " + Destination.class.getName());
-
- destination = (JBossDestination)Util.lookup(ctx, destinationName, Destination.class);
- if (destination instanceof Topic)
+ if (Topic.class.getName().equals(spec.getDestinationType()))
{
- isTopic = true;
+ destination = new JBossTopic(spec.getDestination());
}
+ else
+ {
+ destination = new JBossQueue(spec.getDestination());
+ }
}
log.debug("Got destination " + destination + " from " + destinationName);
Modified: trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivationSpec.java
===================================================================
--- trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivationSpec.java 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/src/main/org/jboss/messaging/ra/inflow/JBMActivationSpec.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -114,6 +114,8 @@
/** Is same RM override */
private Boolean isSameRMOverrideValue;
+ private boolean useJNDI = true;
+
/** Force clear on shutdown */
private Boolean forceClearOnShutdown;
@@ -166,7 +168,25 @@
return ra;
}
+
+
/**
+ * @return the useJNDI
+ */
+ public boolean isUseJNDI()
+ {
+ return useJNDI;
+ }
+
+ /**
+ * @param useJNDI the useJNDI to set
+ */
+ public void setUseJNDI(boolean value)
+ {
+ this.useJNDI = value;
+ }
+
+ /**
* Set the resource adapter
* @param ra The resource adapter
* @exception ResourceException Thrown if incorrect resource adapter
@@ -329,7 +349,7 @@
if (trace)
log.trace("setSubscriptionDurability(" + value + ")");
- this.subscriptionDurability = "Durable".equals(subscriptionDurability);
+ this.subscriptionDurability = "Durable".equals(value);
}
/**
@@ -377,6 +397,10 @@
if (trace)
log.trace("getClientId()");
+ if (clientId == null)
+ {
+ return ra.getClientID();
+ }
return clientId;
}
@@ -400,8 +424,15 @@
{
if (trace)
log.trace("getUser()");
-
- return user;
+
+ if (user == null)
+ {
+ return ra.getUserName();
+ }
+ else
+ {
+ return user;
+ }
}
/**
@@ -424,8 +455,15 @@
{
if (trace)
log.trace("getPassword()");
-
- return password;
+
+ if (password == null)
+ {
+ return ra.getPassword();
+ }
+ else
+ {
+ return password;
+ }
}
/**
Modified: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/message/LargeMessageTest.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -93,7 +93,6 @@
for (int i = 0; i < 1024 * 1024; i += 1024)
{
- System.out.println("Read message chunk " + i);
int numberOfBytes = rm.readBytes(data);
assertEquals(1024, numberOfBytes);
for (int j = 0; j < 1024; j++)
Added: trunk/tests/src/org/jboss/messaging/tests/unit/ra/ResourceAdapterTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/ra/ResourceAdapterTest.java (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/ra/ResourceAdapterTest.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -0,0 +1,234 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * 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.messaging.tests.unit.ra;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.Timer;
+
+import javax.jms.Connection;
+import javax.resource.spi.BootstrapContext;
+import javax.resource.spi.UnavailableException;
+import javax.resource.spi.XATerminator;
+import javax.resource.spi.endpoint.MessageEndpoint;
+import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.resource.spi.work.WorkManager;
+import javax.transaction.xa.XAResource;
+
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.jms.JBossQueue;
+import org.jboss.messaging.jms.client.JBossConnectionFactory;
+import org.jboss.messaging.ra.JBMManagedConnectionFactory;
+import org.jboss.messaging.ra.JBMResourceAdapter;
+import org.jboss.messaging.ra.inflow.JBMActivation;
+import org.jboss.messaging.ra.inflow.JBMActivationSpec;
+import org.jboss.messaging.tests.util.ServiceTestBase;
+
+/**
+ * A ResourceAdapterTest
+ *
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class ResourceAdapterTest extends ServiceTestBase
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ public void testValidateProperties() throws Exception
+ {
+ validateGettersAndSetters(new JBMResourceAdapter(), "backupTransportConfiguration");
+ validateGettersAndSetters(new JBMManagedConnectionFactory(), "connectionParameters", "sessionDefaultType");
+ validateGettersAndSetters(new JBMActivationSpec(),
+ "connectionParameters",
+ "acknowledgeMode",
+ "subscriptionDurability");
+
+ JBMActivationSpec spec = new JBMActivationSpec();
+
+ spec.setAcknowledgeMode("DUPS_OK_ACKNOWLEDGE");
+ spec.setSessionTransacted(false);
+ assertEquals("Dups-ok-acknowledge", spec.getAcknowledgeMode());
+
+ spec.setSessionTransacted(true);
+
+ assertEquals("Transacted", spec.getAcknowledgeMode());
+
+ spec.setSubscriptionDurability("Durable");
+ assertEquals("Durable", spec.getSubscriptionDurability());
+
+ spec.setSubscriptionDurability("NonDurable");
+ assertEquals("NonDurable", spec.getSubscriptionDurability());
+
+
+ spec = new JBMActivationSpec();
+ JBMResourceAdapter adapter = new JBMResourceAdapter();
+
+ adapter.setUserName("us1");
+ adapter.setPassword("ps1");
+ adapter.setClientID("cl1");
+
+ spec.setResourceAdapter(adapter);
+
+ assertEquals("us1", spec.getUser());
+ assertEquals("ps1", spec.getPassword());
+ assertEquals("cl1", spec.getClientId());
+
+ spec.setUser("us2");
+ spec.setPassword("ps2");
+ spec.setClientId("cl2");
+
+
+ assertEquals("us2", spec.getUser());
+ assertEquals("ps2", spec.getPassword());
+ assertEquals("cl2", spec.getClientId());
+
+
+ }
+
+ public void testStartActivation() throws Exception
+ {
+ MessagingServer server = createServer(false);
+
+ try
+ {
+
+ server.start();
+
+ ClientSessionFactory factory = createInVMFactory();
+ ClientSession session = factory.createSession(false, false, false);
+ JBossQueue queue = new JBossQueue("test");
+ session.createQueue(queue.getSimpleAddress(), queue.getSimpleAddress(), true);
+ session.close();
+
+ JBMResourceAdapter ra = new JBMResourceAdapter();
+ ra.setConnectorClassName("org.jboss.messaging.core.remoting.impl.invm.InVMConnectorFactory");
+ ra.setConnectionParameters("bm.remoting.invm.serverid=0");
+ ra.setUseXA(true);
+ ra.setUserName("userGlobal");
+ ra.setPassword("passwordGlobal");
+ ra.start(fakeCTX);
+
+ Connection conn = ra.getJBossConnectionFactory().createConnection();
+
+ conn.close();
+
+ JBMActivationSpec spec = new JBMActivationSpec();
+
+ spec.setResourceAdapter(ra);
+
+ spec.setUseJNDI(false);
+
+ spec.setUser("user");
+ spec.setPassword("password");
+
+ spec.setDestinationType("Topic");
+ spec.setDestination("test");
+
+ spec.setMinSession(1);
+ spec.setMaxSession(1);
+
+ JBMActivation activation = new JBMActivation(ra, new FakeMessageEndpointFactory(), spec);
+
+ activation.start();
+ activation.stop();
+
+ }
+ finally
+ {
+ server.stop();
+ }
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+ class MockJBMResourceAdapter extends JBMResourceAdapter
+ {
+ public JBossConnectionFactory createRemoteFactory(String connectorClassName,
+ Map<String, Object> connectionParameters)
+ {
+ JBossConnectionFactory factory = super.createRemoteFactory(connectorClassName, connectionParameters);
+
+ return factory;
+ }
+ }
+
+ BootstrapContext fakeCTX = new BootstrapContext()
+ {
+
+ public Timer createTimer() throws UnavailableException
+ {
+ return null;
+ }
+
+ public WorkManager getWorkManager()
+ {
+ return null;
+ }
+
+ public XATerminator getXATerminator()
+ {
+ return null;
+ }
+
+ };
+
+
+ class FakeMessageEndpointFactory implements MessageEndpointFactory
+ {
+
+ /* (non-Javadoc)
+ * @see javax.resource.spi.endpoint.MessageEndpointFactory#createEndpoint(javax.transaction.xa.XAResource)
+ */
+ public MessageEndpoint createEndpoint(XAResource arg0) throws UnavailableException
+ {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see javax.resource.spi.endpoint.MessageEndpointFactory#isDeliveryTransacted(java.lang.reflect.Method)
+ */
+ public boolean isDeliveryTransacted(Method arg0) throws NoSuchMethodException
+ {
+ return false;
+ }
+
+ }
+}
Modified: trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java 2009-04-28 22:29:07 UTC (rev 6610)
+++ trunk/tests/src/org/jboss/messaging/tests/util/UnitTestCase.java 2009-04-29 00:56:44 UTC (rev 6611)
@@ -22,6 +22,9 @@
package org.jboss.messaging.tests.util;
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
@@ -33,6 +36,7 @@
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.ByteBuffer;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -428,7 +432,66 @@
}
-
+ /** It validates a Bean (POJO) using simple setters and getters with random values.
+ * You can pass a list of properties to be ignored, as some properties will have a pre-defined domain (not being possible to use random-values on them) */
+ protected void validateGettersAndSetters(Object pojo, String...IgnoredProperties) throws Exception
+ {
+ HashSet<String> ignoreSet = new HashSet<String>();
+
+ for (String ignore: IgnoredProperties)
+ {
+ ignoreSet.add(ignore);
+ }
+
+ BeanInfo info = Introspector.getBeanInfo(pojo.getClass());
+
+ PropertyDescriptor properties[] = info.getPropertyDescriptors();
+
+ for (PropertyDescriptor prop : properties)
+ {
+ Object value;
+
+ if (prop.getPropertyType() == String.class)
+ {
+ value = RandomUtil.randomString();
+ }
+ else if (prop.getPropertyType() == Integer.class || prop.getPropertyType() == Integer.TYPE)
+ {
+ value = RandomUtil.randomInt();
+ }
+ else if (prop.getPropertyType() == Long.class || prop.getPropertyType() == Long.TYPE)
+ {
+ value = RandomUtil.randomLong();
+ }
+ else if (prop.getPropertyType() == Boolean.class || prop.getPropertyType() == Boolean.TYPE)
+ {
+ value = RandomUtil.randomBoolean();
+ }
+ else if (prop.getPropertyType() == Double.class || prop.getPropertyType() == Double.TYPE)
+ {
+ value = RandomUtil.randomDouble();
+ }
+ else
+ {
+ System.out.println("Can't validate property of type " + prop.getPropertyType() + " on " + prop.getName());
+ value = null;
+ }
+
+ if (value != null && prop.getWriteMethod() != null && prop.getReadMethod() == null)
+ {
+ System.out.println("WriteOnly property " + prop.getName() + " on " + pojo.getClass());
+ }
+ else
+ if (value != null & prop.getWriteMethod() != null && prop.getReadMethod() != null && !ignoreSet.contains(prop.getName()))
+ {
+ System.out.println("Validating " + prop.getName() + " type = " + prop.getPropertyType());
+ prop.getWriteMethod().invoke(pojo, value);
+
+ assertEquals("Property " + prop.getName(), value, prop.getReadMethod().invoke(pojo));
+ }
+ }
+ }
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
More information about the jboss-cvs-commits
mailing list