[jboss-cvs] JBoss Messaging SVN: r3590 - in trunk: src/main/org/jboss/jms/client and 15 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jan 18 08:36:40 EST 2008
Author: timfox
Date: 2008-01-18 08:36:40 -0500 (Fri, 18 Jan 2008)
New Revision: 3590
Added:
trunk/src/main/org/jboss/jms/client/SelectorTranslator.java
trunk/tests/src/org/jboss/messaging/core/filter/
trunk/tests/src/org/jboss/messaging/core/filter/impl/
trunk/tests/src/org/jboss/messaging/core/filter/impl/test/
Removed:
trunk/src/main/org/jboss/jms/server/selector/
trunk/src/main/org/jboss/messaging/core/impl/FilterImpl.java
trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorParserTest.java
trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorSyntaxTest.java
Modified:
trunk/build-messaging.xml
trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java
trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java
trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java
trunk/src/main/org/jboss/jms/message/JBossMessage.java
trunk/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
trunk/src/main/org/jboss/messaging/core/Message.java
trunk/src/main/org/jboss/messaging/core/impl/bdbje/BDBJEPersistenceManager.java
trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerManagementImpl.java
trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java
trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java
trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
Log:
Created core messaging filter and filter syntax
Modified: trunk/build-messaging.xml
===================================================================
--- trunk/build-messaging.xml 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/build-messaging.xml 2008-01-18 13:36:40 UTC (rev 3590)
@@ -200,10 +200,10 @@
<target name="compile-parsers">
- <mkdir dir="${build.parsers}/org/jboss/jms/server/selector"/>
+ <mkdir dir="${build.parsers}/org/jboss/messaging/core/impl/filter"/>
<echo message="${sun.javacc.lib}"/>
- <javacc target="${source.java}/org/jboss/jms/server/selector/SelectorParser.jj"
- outputdirectory="${build.parsers}/org/jboss/jms/server/selector"
+ <javacc target="${source.java}/org/jboss/messaging/core/impl/filter/FilterParser.jj"
+ outputdirectory="${build.parsers}/org/jboss/messaging/core/impl/filter"
javacchome="${sun.javacc.lib}"
static="false"/>
@@ -221,15 +221,15 @@
failonerror="${javac.fail.onerror}">
<src path="${build.parsers}"/>
<src path="${source.java}"/>
- <include name="org/jboss/jms/server/selector/ASCII_CharStream.java"/>
- <include name="org/jboss/jms/server/selector/ParserException.java"/>
- <include name="org/jboss/jms/server/selector/SelectorParser.java"/>
- <include name="org/jboss/jms/server/selector/SelectorParserConstants.java"/>
- <include name="org/jboss/jms/server/selector/SelectorParserTokenManager.java"/>
- <include name="org/jboss/jms/server/selector/Token.java"/>
- <include name="org/jboss/jms/server/selector/TokenMgrError.java"/>
- <include name="org/jboss/jms/server/selector/Operator.java"/>
- <include name="org/jboss/jms/server/selector/Identifier.java"/>
+ <include name="org/jboss/messaging/core/impl/filter/ASCII_CharStream.java"/>
+ <include name="org/jboss/messaging/core/impl/filter/ParserException.java"/>
+ <include name="org/jboss/messaging/core/impl/filter/FilterParser.java"/>
+ <include name="org/jboss/messaging/core/impl/filter/FilterParserConstants.java"/>
+ <include name="org/jboss/messaging/core/impl/filter/FilterParserTokenManager.java"/>
+ <include name="org/jboss/messaging/core/impl/filter/Token.java"/>
+ <include name="org/jboss/messaging/core/impl/filter/TokenMgrError.java"/>
+ <include name="org/jboss/messaging/core/impl/filter/Operator.java"/>
+ <include name="org/jboss/messaging/core/impl/filter/Identifier.java"/>
<classpath refid="compilation.classpath"/>
</javac>
</target>
Added: trunk/src/main/org/jboss/jms/client/SelectorTranslator.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/SelectorTranslator.java (rev 0)
+++ trunk/src/main/org/jboss/jms/client/SelectorTranslator.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -0,0 +1,166 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., 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.jms.client;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * This class converts a JMS selector expression into a JBM core filter expression.
+ *
+ * JMS selector and JBM filters use the same syntax but have different identifiers.
+ *
+ * We basically just need to replace the JMS header and property Identifier names
+ * with the corresponding JBM field and header Identifier names.
+ *
+ * We must be careful not to substitute any literals, or identifers whose name contains the name
+ * of one we want to substitute.
+ *
+ * This makes it less trivial than a simple search and replace.
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ */
+public class SelectorTranslator
+{
+ public static String convertToJBMFilterString(String selectorString)
+ {
+ if (selectorString == null)
+ {
+ return null;
+ }
+
+ //First convert any JMS header identifiers
+
+ String filterString = parse(selectorString, "JMSDeliveryMode", "JBMDurable");
+ filterString = parse(filterString, "'PERSISTENT'", "'DURABLE'");
+ filterString = parse(filterString, "'NON_PERSISTENT'", "'NON_DURABLE'");
+
+ filterString = parse(filterString, "JMSPriority", "JBMPriority");
+
+ // filterString = parse(selectorString, "JMSMessageID", "JMSMessageID"); //SAME
+
+ filterString = parse(filterString, "JMSTimestamp", "JBMTimestamp");
+
+ // filterString = parse(selectorString, "JMSCorrelationID", "JMSCorrelationID"); //SAME
+
+ // filterString = parse(selectorString, "JMSType", "JMSType"); //SAME
+
+ return filterString;
+
+ }
+
+ private static String parse(String input, String match, String replace)
+ {
+ final char quote = '\'';
+
+ boolean inQuote = false;
+
+ int matchPos = 0;
+
+ List<Integer> positions = new ArrayList<Integer>();
+
+ boolean replaceInQuotes = match.charAt(0) == quote;
+
+ for (int i = 0; i < input.length(); i++)
+ {
+ char c = input.charAt(i);
+
+ if (c == quote)
+ {
+ inQuote = !inQuote;
+ }
+
+ if ((!inQuote || replaceInQuotes) && c == match.charAt(matchPos))
+ {
+ matchPos++;
+
+ if (matchPos == match.length())
+ {
+
+ boolean matched = true;
+
+ //Check that name is not part of another identifier name
+
+ //Check character after match
+ if (i < input.length() -1 && Character.isJavaIdentifierPart(input.charAt(i + 1)))
+ {
+ matched = false;
+ }
+
+
+ //Check character before match
+ int posBeforeStart = i - match.length();
+
+ if (posBeforeStart >= 0 && Character.isJavaIdentifierPart(input.charAt(posBeforeStart)))
+ {
+ matched = false;
+ }
+
+ if (matched)
+ {
+ positions.add(i - match.length() + 1);
+ }
+
+ //check previous character too
+
+ matchPos = 0;
+ }
+ }
+ else
+ {
+ matchPos = 0;
+ }
+ }
+
+ if (!positions.isEmpty())
+ {
+ StringBuffer buff = new StringBuffer();
+
+ int startPos = 0;
+
+ for (int pos: positions)
+ {
+ String substr = input.substring(startPos, pos);
+
+ buff.append(substr);
+
+ buff.append(replace);
+
+ startPos = pos + match.length();
+ }
+
+ if (startPos < input.length())
+ {
+ buff.append(input.substring(startPos, input.length()));
+ }
+
+ return buff.toString();
+ }
+ else
+ {
+ return input;
+ }
+ }
+}
Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientBrowserDelegate.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -73,6 +73,7 @@
super(objectID);
this.session = session;
this.jmsDestination = jmsDestination;
+
this.messageSelector = messageSelector;
}
Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientConsumerDelegate.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -314,19 +314,7 @@
{
return redeliveryDelay;
}
-
-
- public String getSelector()
- {
- return selector;
- }
-
- public boolean isNoLocal()
- {
- return noLocal;
- }
-
public String getConsumerID()
{
return consumerID;
Modified: trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java
===================================================================
--- trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/jms/client/delegate/ClientSessionDelegate.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -40,6 +40,7 @@
import javax.jms.TransactionInProgressException;
import javax.transaction.xa.XAResource;
import org.jboss.jms.client.Closeable;
+import org.jboss.jms.client.SelectorTranslator;
import org.jboss.jms.client.api.ClientBrowser;
import org.jboss.jms.client.api.ClientConnection;
import org.jboss.jms.client.api.ClientSession;
@@ -436,7 +437,8 @@
public ClientBrowser createBrowserDelegate(Destination queue, String messageSelector)
throws JMSException
{
- CreateBrowserRequest request = new CreateBrowserRequest(queue, messageSelector);
+ String coreSelector = SelectorTranslator.convertToJBMFilterString(messageSelector);
+ CreateBrowserRequest request = new CreateBrowserRequest(queue, coreSelector);
CreateBrowserResponse response = (CreateBrowserResponse) sendBlocking(request);
ClientBrowserDelegate delegate = new ClientBrowserDelegate(this, response.getBrowserID(), queue, messageSelector);
ClientBrowser proxy = (ClientBrowser)ProxyFactory.proxy(delegate, ClientBrowser.class);
@@ -459,9 +461,9 @@
boolean noLocal, String subscriptionName,
boolean isCC) throws JMSException
{
-
+ String coreSelector = SelectorTranslator.convertToJBMFilterString(selector);
CreateConsumerRequest request =
- new CreateConsumerRequest(destination, selector, noLocal, subscriptionName, isCC);
+ new CreateConsumerRequest(destination, coreSelector, noLocal, subscriptionName, isCC);
CreateConsumerResponse response = (CreateConsumerResponse) sendBlocking(request);
Modified: trunk/src/main/org/jboss/jms/message/JBossMessage.java
===================================================================
--- trunk/src/main/org/jboss/jms/message/JBossMessage.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/jms/message/JBossMessage.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -66,22 +66,18 @@
{
// Constants -----------------------------------------------------
- private static final char PROPERTY_PREFIX_CHAR = 'P';
+ //FIXME - this will disappear
+ private static final String DESTINATION_HEADER_NAME = "JMSDestination2";
- private static final String PROPERTY_PREFIX = "P";
+ private static final String REPLYTO_HEADER_NAME = "JMSReplyTo";
- private static final String DESTINATION_HEADER_NAME = "H.DEST";
-
- private static final String REPLYTO_HEADER_NAME = "H.REPLYTO";
-
- private static final String CORRELATIONID_HEADER_NAME = "H.CORRELATIONID";
+ private static final String CORRELATIONID_HEADER_NAME = "JMSCorrelationID";
- // When the message is sent through the cluster, it needs to keep the original messageID
- private static final String JBM_MESSAGE_ID = "JBM_MESSAGE_ID";
+ private static final String JBM_MESSAGE_ID = "JMSMessageID";
- private static final String CORRELATIONIDBYTES_HEADER_NAME = "H.CORRELATIONIDBYTES";
+ //private static final String CORRELATIONIDBYTES_HEADER_NAME = "JMSCorre";
- private static final String TYPE_HEADER_NAME = "H.TYPE";
+ private static final String TYPE_HEADER_NAME = "JMSType";
public static final String JMS_JBOSS_SCHEDULED_DELIVERY_PROP_NAME = "JMS_JBOSS_SCHEDULED_DELIVERY";
@@ -276,7 +272,16 @@
public byte[] getJMSCorrelationIDAsBytes() throws JMSException
{
- return (byte[]) message.getHeader(CORRELATIONIDBYTES_HEADER_NAME);
+ Object obj = message.getHeader(CORRELATIONID_HEADER_NAME);
+
+ if (obj instanceof byte[])
+ {
+ return (byte[])obj;
+ }
+ else
+ {
+ return null;
+ }
}
public void setJMSCorrelationIDAsBytes(byte[] correlationID) throws JMSException
@@ -285,21 +290,26 @@
{
throw new JMSException("Please specify a non-zero length byte[]");
}
- message.putHeader(CORRELATIONIDBYTES_HEADER_NAME, correlationID);
-
- message.removeHeader(CORRELATIONID_HEADER_NAME);
+ message.putHeader(CORRELATIONID_HEADER_NAME, correlationID);
}
public void setJMSCorrelationID(String correlationID) throws JMSException
{
message.putHeader(CORRELATIONID_HEADER_NAME, correlationID);
-
- message.removeHeader(CORRELATIONIDBYTES_HEADER_NAME);
}
public String getJMSCorrelationID() throws JMSException
{
- return (String)message.getHeader(CORRELATIONID_HEADER_NAME);
+ Object obj = message.getHeader(CORRELATIONID_HEADER_NAME);
+
+ if (obj instanceof String)
+ {
+ return (String)obj;
+ }
+ else
+ {
+ return null;
+ }
}
public Destination getJMSReplyTo() throws JMSException
@@ -408,8 +418,21 @@
{
String propName = iter.next();
- if (propName.charAt(0) == PROPERTY_PREFIX_CHAR)
+ boolean remove = false;
+ if (!propName.startsWith("JMS"))
{
+ remove = true;
+ }
+ else
+ {
+ if (propName.startsWith("JMSX") || propName.startsWith("JMS_"))
+ {
+ remove = true;
+ }
+ }
+
+ if (remove)
+ {
iter.remove();
}
}
@@ -422,13 +445,13 @@
public boolean propertyExists(String name) throws JMSException
{
- return message.containsHeader(PROPERTY_PREFIX + name)
+ return message.containsHeader(name)
|| name.equals("JMSXDeliveryCount");
}
public boolean getBooleanProperty(String name) throws JMSException
{
- Object value = message.getHeader(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(name);
if (value == null)
return Boolean.valueOf(null).booleanValue();
@@ -442,7 +465,7 @@
public byte getByteProperty(String name) throws JMSException
{
- Object value = message.getHeader(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(name);
if (value == null)
throw new NumberFormatException("Message property '" + name + "' not set.");
@@ -456,7 +479,7 @@
public short getShortProperty(String name) throws JMSException
{
- Object value = message.getHeader(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(name);
if (value == null)
throw new NumberFormatException("Message property '" + name + "' not set.");
@@ -477,7 +500,7 @@
return deliveryCount;
}
- Object value = message.getHeader(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(name);
if (value == null)
{
@@ -513,7 +536,7 @@
return deliveryCount;
}
- Object value = message.getHeader(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(name);
if (value == null)
{
@@ -548,7 +571,7 @@
public float getFloatProperty(String name) throws JMSException
{
- Object value = message.getHeader(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(name);
if (value == null)
return Float.valueOf(null).floatValue();
@@ -562,7 +585,7 @@
public double getDoubleProperty(String name) throws JMSException
{
- Object value = message.getHeader(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(name);
if (value == null)
return Double.valueOf(null).doubleValue();
@@ -583,7 +606,7 @@
return Integer.toString(deliveryCount);
}
- Object value = message.getHeader(PROPERTY_PREFIX + name);
+ Object value = message.getHeader(name);
if (value == null)
return null;
@@ -627,7 +650,7 @@
public Object getObjectProperty(String name) throws JMSException
{
- return message.getHeader(PROPERTY_PREFIX + name);
+ return message.getHeader(name);
}
public Enumeration getPropertyNames() throws JMSException
@@ -636,11 +659,23 @@
for (String propName: message.getHeaders().keySet())
{
- if (propName.charAt(0) == PROPERTY_PREFIX_CHAR)
+ boolean add = false;
+ if (!propName.startsWith("JMS"))
{
- String name = propName.substring(1);
- set.add(name);
+ add = true;
}
+ else
+ {
+ if (propName.startsWith("JMSX") || propName.startsWith("JMS_"))
+ {
+ add = true;
+ }
+ }
+
+ if (add)
+ {
+ set.add(propName);
+ }
}
return Collections.enumeration(set);
@@ -650,97 +685,73 @@
{
Boolean b = Primitives.valueOf(value);
checkProperty(name, b);
- message.putHeader(PROPERTY_PREFIX + name, b);
+ message.putHeader(name, b);
}
public void setByteProperty(String name, byte value) throws JMSException
{
Byte b = new Byte(value);
checkProperty(name, b);
- message.putHeader(PROPERTY_PREFIX + name, b);
+ message.putHeader(name, b);
}
public void setShortProperty(String name, short value) throws JMSException
{
Short s = new Short(value);
checkProperty(name, s);
- message.putHeader(PROPERTY_PREFIX + name, s);
+ message.putHeader(name, s);
}
public void setIntProperty(String name, int value) throws JMSException
{
Integer i = new Integer(value);
checkProperty(name, i);
- message.putHeader(PROPERTY_PREFIX + name, i);
+ message.putHeader(name, i);
}
public void setLongProperty(String name, long value) throws JMSException
{
Long l = new Long(value);
checkProperty(name, l);
- message.putHeader(PROPERTY_PREFIX + name, l);
+ message.putHeader(name, l);
}
public void setFloatProperty(String name, float value) throws JMSException
{
Float f = new Float(value);
checkProperty(name, f);
- message.putHeader(PROPERTY_PREFIX + name, f);
+ message.putHeader(name, f);
}
public void setDoubleProperty(String name, double value) throws JMSException
{
Double d = new Double(value);
checkProperty(name, d);
- message.putHeader(PROPERTY_PREFIX + name, d);
+ message.putHeader(name, d);
}
public void setStringProperty(String name, String value) throws JMSException
{
checkProperty(name, value);
- message.putHeader(PROPERTY_PREFIX + name, value);
+ message.putHeader(name, value);
}
public void setObjectProperty(String name, Object value) throws JMSException
{
checkProperty(name, value);
- if (value instanceof Boolean)
+ if ((value instanceof Boolean)
+ || (value instanceof Byte)
+ || (value instanceof Short)
+ || (value instanceof Integer)
+ || (value instanceof Long)
+ || (value instanceof Float)
+ || (value instanceof Double)
+ || (value instanceof String)
+ || (value == null))
{
- message.putHeader(PROPERTY_PREFIX + name, value);
+ message.putHeader(name, value);
}
- else if (value instanceof Byte)
- {
- message.putHeader(PROPERTY_PREFIX + name, value);
- }
- else if (value instanceof Short)
- {
- message.putHeader(PROPERTY_PREFIX + name, value);
- }
- else if (value instanceof Integer)
- {
- message.putHeader(PROPERTY_PREFIX + name, value);
- }
- else if (value instanceof Long)
- {
- message.putHeader(PROPERTY_PREFIX + name, value);
- }
- else if (value instanceof Float)
- {
- message.putHeader(PROPERTY_PREFIX + name, value);
- }
- else if (value instanceof Double)
- {
- message.putHeader(PROPERTY_PREFIX + name, value);
- }
- else if (value instanceof String)
- {
- message.putHeader(PROPERTY_PREFIX + name, value);
- }
- else if (value == null)
- {
- message.putHeader(PROPERTY_PREFIX + name, null);
- }
else
{
throw new MessageFormatException("Invalid object type");
@@ -894,14 +905,39 @@
throw new IllegalArgumentException("The property name '" + name +
"' is reserved due to selector syntax.");
}
-
- if (name.startsWith("JMSX") &&
- !name.equals("JMSXGroupID") &&
- !name.equals("JMSXGroupSeq") &&
- !name.equals("JMSXDeliveryCount"))
+
+ if (name.startsWith("JMS"))
{
- throw new JMSException("Can only set JMSXGroupId, JMSXGroupSeq, JMSXDeliveryCount");
- }
+ if (name.length() > 3)
+ {
+ char c = name.charAt(3);
+ if (c == 'X')
+ {
+ if (!name.equals("JMSXGroupID") &&
+ !name.equals("JMSXGroupSeq") &&
+ !name.equals("JMSXDeliveryCount"))
+ {
+ throw new JMSException("Can only set JMSXGroupId, JMSXGroupSeq, JMSXDeliveryCount");
+ }
+ }
+ else if (c == '_')
+ {
+ //OK
+ }
+ else
+ {
+ //See http://java.sun.com/javaee/5/docs/api/
+ //(java.jms.Message javadoc)
+ //"Property names must obey the rules for a message selector identifier"
+ //"Any name that does not begin with 'JMS' is an application-specific property name"
+ throw new IllegalArgumentException("The property name '" + name + "' is illegal since it starts with JMS");
+ }
+ }
+ else
+ {
+ throw new IllegalArgumentException("The property name '" + name + "' is illegal since it starts with JMS");
+ }
+ }
}
// Inner classes -------------------------------------------------
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerBrowserEndpoint.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -32,16 +32,17 @@
import java.util.List;
import javax.jms.IllegalStateException;
+import javax.jms.InvalidSelectorException;
import javax.jms.JMSException;
import org.jboss.jms.delegate.BrowserEndpoint;
import org.jboss.jms.exception.MessagingJMSException;
-import org.jboss.jms.server.selector.Selector;
import org.jboss.logging.Logger;
import org.jboss.messaging.core.Filter;
import org.jboss.messaging.core.Message;
import org.jboss.messaging.core.MessageReference;
import org.jboss.messaging.core.Queue;
+import org.jboss.messaging.core.impl.filter.FilterImpl;
import org.jboss.messaging.core.remoting.PacketHandler;
import org.jboss.messaging.core.remoting.PacketSender;
import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
@@ -85,15 +86,22 @@
// Constructors ---------------------------------------------------------------------------------
ServerBrowserEndpoint(ServerSessionEndpoint session, String id,
- Queue destination, String messageSelector) throws JMSException
+ Queue destination, String messageFilter) throws Exception
{
this.session = session;
this.id = id;
this.destination = destination;
- if (messageSelector != null)
+ if (messageFilter != null)
{
- filter = new Selector(messageSelector);
+ try
+ {
+ filter = new FilterImpl(messageFilter);
+ }
+ catch (Exception e)
+ {
+ throw new InvalidSelectorException("Invalid selector " + messageFilter);
+ }
}
}
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerConsumerEndpoint.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -25,17 +25,16 @@
import static org.jboss.messaging.core.remoting.wireformat.PacketType.MSG_CLOSE;
import static org.jboss.messaging.core.remoting.wireformat.PacketType.REQ_CLOSING;
-import javax.jms.InvalidSelectorException;
import javax.jms.JMSException;
import org.jboss.jms.delegate.ConsumerEndpoint;
import org.jboss.jms.exception.MessagingJMSException;
-import org.jboss.jms.server.selector.Selector;
import org.jboss.logging.Logger;
import org.jboss.messaging.core.Condition;
import org.jboss.messaging.core.Consumer;
import org.jboss.messaging.core.Destination;
import org.jboss.messaging.core.DestinationType;
+import org.jboss.messaging.core.Filter;
import org.jboss.messaging.core.HandleStatus;
import org.jboss.messaging.core.Message;
import org.jboss.messaging.core.MessageReference;
@@ -44,6 +43,7 @@
import org.jboss.messaging.core.PostOffice;
import org.jboss.messaging.core.Queue;
import org.jboss.messaging.core.impl.ConditionImpl;
+import org.jboss.messaging.core.impl.filter.FilterImpl;
import org.jboss.messaging.core.remoting.PacketHandler;
import org.jboss.messaging.core.remoting.PacketSender;
import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
@@ -91,7 +91,7 @@
private boolean noLocal;
- private Selector messageSelector;
+ private Filter filter;
private Destination destination;
@@ -126,10 +126,10 @@
// Constructors ---------------------------------------------------------------------------------
ServerConsumerEndpoint(MessagingServer sp, String id, Queue messageQueue, String queueName,
- ServerSessionEndpoint sessionEndpoint, String selector,
+ ServerSessionEndpoint sessionEndpoint, Filter filter,
boolean noLocal, Destination destination, Queue dlq,
Queue expiryQueue, long redeliveryDelay, int maxDeliveryAttempts,
- int prefetchSize) throws InvalidSelectorException
+ int prefetchSize)
{
if (trace)
{
@@ -162,6 +162,8 @@
this.startStopLock = new Object();
this.prefetchSize = prefetchSize;
+
+ this.filter = filter;
//FIXME - we shouldn't have checks like this on the server side
//It should be the jms client that decides whether to retain deliveries or not
@@ -176,14 +178,6 @@
this.retainDeliveries = true;
}
- if (selector != null)
- {
- if (trace) { log.trace("creating selector:" + selector); }
-
- this.messageSelector = new Selector(selector);
- if (trace) { log.trace("created selector"); }
- }
-
this.started = this.sessionEndpoint.getConnectionEndpoint().isStarted();
// adding the consumer to the queue
@@ -308,16 +302,16 @@
boolean accept = true;
//FIXME - we shouldn't have checks like this - it should be the client side which decides whether
- //to have a selector on the consumer
+ //to have a filter on the consumer
if (destination.getType() == DestinationType.QUEUE)
{
// For subscriptions message selection is handled in the Subscription itself we do not want
// to do the check twice
- if (messageSelector != null)
+ if (filter != null)
{
- accept = messageSelector.match(msg);
+ accept = filter.match(msg);
- if (trace) { log.trace("message selector " + (accept ? "accepts " : "DOES NOT accept ") + "the message"); }
+ if (trace) { log.trace("message filter " + (accept ? "accepts " : "DOES NOT accept ") + "the message"); }
}
}
Modified: trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -47,6 +47,7 @@
import javax.jms.IllegalStateException;
import javax.jms.InvalidDestinationException;
+import javax.jms.InvalidSelectorException;
import javax.jms.JMSException;
import org.jboss.jms.client.api.ClientBrowser;
@@ -54,9 +55,7 @@
import org.jboss.jms.client.delegate.ClientBrowserDelegate;
import org.jboss.jms.client.delegate.ClientConsumerDelegate;
import org.jboss.jms.delegate.Ack;
-import org.jboss.jms.delegate.BrowserDelegate;
import org.jboss.jms.delegate.Cancel;
-import org.jboss.jms.delegate.ConsumerDelegate;
import org.jboss.jms.delegate.DefaultAck;
import org.jboss.jms.delegate.DeliveryInfo;
import org.jboss.jms.delegate.SessionEndpoint;
@@ -67,12 +66,12 @@
import org.jboss.jms.server.DestinationManager;
import org.jboss.jms.server.container.SecurityAspect;
import org.jboss.jms.server.security.CheckType;
-import org.jboss.jms.server.selector.Selector;
import org.jboss.logging.Logger;
import org.jboss.messaging.core.Binding;
import org.jboss.messaging.core.Condition;
import org.jboss.messaging.core.Destination;
import org.jboss.messaging.core.DestinationType;
+import org.jboss.messaging.core.Filter;
import org.jboss.messaging.core.Message;
import org.jboss.messaging.core.MessageReference;
import org.jboss.messaging.core.MessagingServer;
@@ -82,7 +81,7 @@
import org.jboss.messaging.core.TransactionSynchronization;
import org.jboss.messaging.core.impl.ConditionImpl;
import org.jboss.messaging.core.impl.TransactionImpl;
-import org.jboss.messaging.core.remoting.PacketDispatcher;
+import org.jboss.messaging.core.impl.filter.FilterImpl;
import org.jboss.messaging.core.remoting.PacketHandler;
import org.jboss.messaging.core.remoting.PacketSender;
import org.jboss.messaging.core.remoting.wireformat.AbstractPacket;
@@ -237,7 +236,7 @@
}
public Consumer createConsumerDelegate(Destination destination,
- String selector,
+ String filterString,
boolean noLocal,
String subscriptionName,
boolean isCC) throws JMSException
@@ -247,7 +246,7 @@
try
{
- return createConsumerDelegateInternal(destination, selector, noLocal, subscriptionName);
+ return createConsumerDelegateInternal(destination, filterString, noLocal, subscriptionName);
}
catch (Throwable t)
{
@@ -256,14 +255,14 @@
}
public ClientBrowser createBrowserDelegate(Destination destination,
- String selector)
+ String filterString)
throws JMSException
{
security.check(destination, CheckType.READ, this.getConnectionEndpoint());
try
{
- return createBrowserDelegateInternal(destination, selector);
+ return createBrowserDelegateInternal(destination, filterString);
}
catch (Throwable t)
{
@@ -467,8 +466,6 @@
{
if (trace) {log.trace(this + " cancels deliveries " + cancels); }
- log.info("Cancelling deliveries " + cancels.size());
-
try
{
// deliveries must be cancelled in reverse order
@@ -821,8 +818,6 @@
DeliveryRecord rec = (DeliveryRecord)entry.getValue();
- log.info("Cancelling delivery " + rec.ref);
-
rec.ref.cancel(this.sp.getPersistenceManager());
}
@@ -1040,8 +1035,6 @@
private void cancelDeliveryInternal(Cancel cancel) throws Exception
{
- log.info("Cancelling delivery " + cancel);
-
DeliveryRecord rec = (DeliveryRecord)deliveries.remove(cancel.getDeliveryId());
if (rec == null)
@@ -1208,9 +1201,9 @@
}
private Consumer createConsumerDelegateInternal(Destination destination,
- String selectorString,
- boolean noLocal,
- String subscriptionName)
+ String filterString,
+ boolean noLocal,
+ String subscriptionName)
throws Exception
{
if (closed)
@@ -1218,15 +1211,15 @@
throw new IllegalStateException("Session is closed");
}
- if ("".equals(selectorString))
+ if ("".equals(filterString))
{
- selectorString = null;
+ filterString = null;
}
if (trace)
{
log.trace(this + " creating consumer for " + destination +
- (selectorString == null ? "" : ", selector '" + selectorString + "'") +
+ (filterString == null ? "" : ", filter '" + filterString + "'") +
(subscriptionName == null ? "" : ", subscription '" + subscriptionName + "'") +
(noLocal ? ", noLocal" : ""));
}
@@ -1252,12 +1245,19 @@
String consumerID = UUID.randomUUID().toString();
- // Always validate the selector first
- Selector selector = null;
+ // Always validate the filter first
+ Filter filter = null;
- if (selectorString != null)
+ if (filterString != null)
{
- selector = new Selector(selectorString);
+ try
+ {
+ filter = new FilterImpl(filterString);
+ }
+ catch (Exception e)
+ {
+ throw new InvalidSelectorException("Invalid selector " + filterString);
+ }
}
Queue queue;
@@ -1271,7 +1271,7 @@
// non-durable subscription
if (log.isTraceEnabled()) { log.trace(this + " creating new non-durable subscription on " + destination); }
- queue = postOffice.addQueue(condition, UUID.randomUUID().toString(), selector, false, false, false);
+ queue = postOffice.addQueue(condition, UUID.randomUUID().toString(), filter, false, false, false);
//TODO - message counters should be applied by the queue configurator factory
@@ -1309,7 +1309,7 @@
if (trace) { log.trace(this + " creating new durable subscription on " + destination); }
- queue = postOffice.addQueue(condition, name, selector, true, false,
+ queue = postOffice.addQueue(condition, name, filter, true, false,
sp.getConfiguration().isClustered());
//TODO message counters handled by queue configurator
@@ -1339,13 +1339,13 @@
// Changing a durable subscriber is equivalent to unsubscribing (deleting) the old
// one and creating a new one.
- String filterString = queue.getFilter() != null ? queue.getFilter().getFilterString() : null;
+ String oldFilterString = queue.getFilter() != null ? queue.getFilter().getFilterString() : null;
boolean selectorChanged =
- (selectorString == null && filterString != null) ||
- (filterString == null && selectorString != null) ||
- (filterString != null && selectorString != null &&
- !filterString.equals(selectorString));
+ (filterString == null && oldFilterString != null) ||
+ (oldFilterString == null && filterString != null) ||
+ (oldFilterString != null && filterString != null &&
+ !oldFilterString.equals(filterString));
if (trace) { log.trace("selector " + (selectorChanged ? "has" : "has NOT") + " changed"); }
@@ -1371,7 +1371,7 @@
queue.removeAllReferences();
- queue = postOffice.addQueue(condition, name, selector, true, false, sp.getConfiguration().isClustered());
+ queue = postOffice.addQueue(condition, name, filter, true, false, sp.getConfiguration().isClustered());
}
@@ -1406,7 +1406,7 @@
ServerConsumerEndpoint ep =
new ServerConsumerEndpoint(sp, consumerID, queue,
- queue.getName(), this, selectorString, noLocal,
+ queue.getName(), this, filter, noLocal,
destination, dlqToUse, expiryQueueToUse, redeliveryDelayToUse,
maxDeliveryAttemptsToUse, prefetchSize);
Modified: trunk/src/main/org/jboss/messaging/core/Message.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/Message.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/messaging/core/Message.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -39,7 +39,7 @@
public interface Message extends Streamable
{
//FIXME - temp
- public static final String TEMP_DEST_HEADER_NAME = "DEST";
+ public static final String TEMP_DEST_HEADER_NAME = "JMSDestination";
/**
Deleted: trunk/src/main/org/jboss/messaging/core/impl/FilterImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/FilterImpl.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/messaging/core/impl/FilterImpl.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -1,55 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., 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.messaging.core.impl;
-
-import org.jboss.messaging.core.Filter;
-import org.jboss.messaging.core.Message;
-
-/**
- *
- * A FilterImpl
- *
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- *
- */
-public class FilterImpl implements Filter
-{
- private String filterString;
-
- public FilterImpl(String filterString)
- {
- this.filterString = filterString;
- }
-
- public String getFilterString()
- {
- return filterString;
- }
-
- public boolean match(Message message)
- {
- //TODO implement properly
-
- return false;
- }
-
-}
Modified: trunk/src/main/org/jboss/messaging/core/impl/bdbje/BDBJEPersistenceManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/bdbje/BDBJEPersistenceManager.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/messaging/core/impl/bdbje/BDBJEPersistenceManager.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -45,8 +45,8 @@
import org.jboss.messaging.core.QueueFactory;
import org.jboss.messaging.core.impl.BindingImpl;
import org.jboss.messaging.core.impl.ConditionImpl;
-import org.jboss.messaging.core.impl.FilterImpl;
import org.jboss.messaging.core.impl.MessageImpl;
+import org.jboss.messaging.core.impl.filter.FilterImpl;
import org.jboss.messaging.util.Pair;
/**
Modified: trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerManagementImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerManagementImpl.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/src/main/org/jboss/messaging/core/impl/server/MessagingServerManagementImpl.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -29,18 +29,20 @@
import java.util.StringTokenizer;
import org.jboss.aop.microcontainer.aspects.jmx.JMX;
+import org.jboss.jms.client.SelectorTranslator;
import org.jboss.jms.server.endpoint.ServerConnectionEndpoint;
-import org.jboss.jms.server.selector.Selector;
import org.jboss.messaging.core.Binding;
import org.jboss.messaging.core.Condition;
import org.jboss.messaging.core.Configuration;
import org.jboss.messaging.core.DestinationType;
+import org.jboss.messaging.core.Filter;
import org.jboss.messaging.core.Message;
import org.jboss.messaging.core.MessageReference;
import org.jboss.messaging.core.MessagingServer;
import org.jboss.messaging.core.MessagingServerManagement;
import org.jboss.messaging.core.Queue;
import org.jboss.messaging.core.impl.ConditionImpl;
+import org.jboss.messaging.core.impl.filter.FilterImpl;
import org.jboss.messaging.core.impl.messagecounter.MessageCounter;
import org.jboss.messaging.util.MessageQueueNameHelper;
@@ -633,23 +635,23 @@
- private List<Message> listMessages(Queue queue, ListType type, String selector) throws Exception
- {
- Selector sel = null;
-
- if (selector != null && "".equals(selector.trim()))
+ private List<Message> listMessages(Queue queue, ListType type, String jmsSelector) throws Exception
+ {
+ if (jmsSelector != null && "".equals(jmsSelector.trim()))
{
- selector = null;
+ jmsSelector = null;
}
- if (selector != null)
+ Filter filter = null;
+
+ if (jmsSelector != null)
{
- sel = new Selector(selector);
+ filter = new FilterImpl(SelectorTranslator.convertToJBMFilterString(jmsSelector));
}
List<Message> msgs = new ArrayList<Message>();
- List<MessageReference> allRefs = queue.list(sel);
+ List<MessageReference> allRefs = queue.list(filter);
for (MessageReference ref: allRefs)
{
@@ -801,7 +803,7 @@
}
- private List<Message> listMessagesForSubscription(ListType type, String subId, String selector) throws Exception
+ private List<Message> listMessagesForSubscription(ListType type, String subId, String jmsSelector) throws Exception
{
List<Message> msgs = new ArrayList<Message>();
@@ -817,16 +819,17 @@
throw new IllegalArgumentException("Cannot find subscription with id " + subId);
}
- Selector sel = null;
- if (selector != null && "".equals(selector.trim()))
+ if (jmsSelector != null && "".equals(jmsSelector.trim()))
{
- selector = null;
+ jmsSelector = null;
}
-
- if (selector != null)
+
+ Filter sel = null;
+
+ if (jmsSelector != null)
{
- sel = new Selector(selector);
+ sel = new FilterImpl(SelectorTranslator.convertToJBMFilterString(jmsSelector));
}
Binding binding = bindings.get(0);
Modified: trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/tests/src/org/jboss/messaging/core/impl/bdbje/test/unit/BDBJEPersistenceManagerTest.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -37,7 +37,6 @@
import org.jboss.messaging.core.Queue;
import org.jboss.messaging.core.impl.BindingImpl;
import org.jboss.messaging.core.impl.ConditionImpl;
-import org.jboss.messaging.core.impl.FilterImpl;
import org.jboss.messaging.core.impl.MessageImpl;
import org.jboss.messaging.core.impl.QueueFactoryImpl;
import org.jboss.messaging.core.impl.QueueImpl;
@@ -45,6 +44,7 @@
import org.jboss.messaging.core.impl.bdbje.BDBJEEnvironment;
import org.jboss.messaging.core.impl.bdbje.BDBJEPersistenceManager;
import org.jboss.messaging.core.impl.bdbje.test.unit.fakes.FakeBDBJEEnvironment;
+import org.jboss.messaging.core.impl.filter.FilterImpl;
import org.jboss.messaging.test.unit.UnitTestCase;
/**
@@ -665,13 +665,13 @@
public void testAddRemoveBindings() throws Exception
{
- Queue queue1 = new QueueImpl(1, "queue1", new FilterImpl("filter1"), false, true, false, -1);
+ Queue queue1 = new QueueImpl(1, "queue1", new FilterImpl("a=1"), false, true, false, -1);
- Queue queue2 = new QueueImpl(2, "queue2", new FilterImpl("filter2"), false, true, false, -1);
+ Queue queue2 = new QueueImpl(2, "queue2", new FilterImpl("a=1"), false, true, false, -1);
- Queue queue3 = new QueueImpl(3, "queue3", new FilterImpl("filter3"), false, true, false, -1);
+ Queue queue3 = new QueueImpl(3, "queue3", new FilterImpl("a=1"), false, true, false, -1);
- Queue queue4 = new QueueImpl(4, "queue4", new FilterImpl("filter4"), false, true, false, -1);
+ Queue queue4 = new QueueImpl(4, "queue4", new FilterImpl("a=1"), false, true, false, -1);
Condition condition1 = new ConditionImpl(DestinationType.QUEUE, "condition1");
Modified: trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/tests/src/org/jboss/messaging/core/impl/postoffice/test/unit/PostOfficeTest.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -38,10 +38,10 @@
import org.jboss.messaging.core.Transaction;
import org.jboss.messaging.core.impl.BindingImpl;
import org.jboss.messaging.core.impl.ConditionImpl;
-import org.jboss.messaging.core.impl.FilterImpl;
import org.jboss.messaging.core.impl.QueueFactoryImpl;
import org.jboss.messaging.core.impl.QueueImpl;
import org.jboss.messaging.core.impl.TransactionImpl;
+import org.jboss.messaging.core.impl.filter.FilterImpl;
import org.jboss.messaging.core.impl.postoffice.PostOfficeImpl;
import org.jboss.messaging.test.unit.UnitTestCase;
Modified: trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/tests/src/org/jboss/test/messaging/jms/message/MessageHeaderTest.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -293,6 +293,9 @@
while (en.hasMoreElements())
{
String propName = (String)en.nextElement();
+
+ log.info("Prop name is " + propName);
+
propNames.add(propName);
}
Deleted: trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorParserTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorParserTest.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorParserTest.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -1,335 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., 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.test.messaging.jms.selector;
-
-import org.jboss.jms.server.selector.ISelectorParser;
-import org.jboss.jms.server.selector.Identifier;
-import org.jboss.jms.server.selector.Operator;
-import org.jboss.jms.server.selector.SelectorParser;
-import org.jboss.test.messaging.JBMBaseTestCase;
-
-import java.io.ByteArrayInputStream;
-import java.util.HashMap;
-
-
-/** Tests of the JavaCC LL(1) parser.
-
- @author Scott.Stark at jboss.org
- @author d_jencks at users.sourceforge.net
-
- @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a> Ported from JBossMQ
-
- @version $Revision$
-
- * (david jencks) Used constructor of SelectorParser taking a stream
- * to avoid reInit npe in all tests. Changed to JBossTestCase and logging.
- */
-public class SelectorParserTest extends JBMBaseTestCase
-{
- static HashMap identifierMap = new HashMap();
- static ISelectorParser parser;
-
- public SelectorParserTest(String name)
- {
- super(name);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
- identifierMap.clear();
- if( parser == null )
- {
- parser = new SelectorParser(new ByteArrayInputStream(new byte[0]));
- }
- }
-
- public void testSimpleUnary() throws Exception
- {
- // Neg Long
- log.trace("parse(-12345 = -1 * 12345)");
- Operator result = (Operator) parser.parse("-12345 = -1 * 12345", identifierMap);
- log.trace("result -> "+result);
- Boolean b = (Boolean) result.apply();
- assertTrue("is true", b.booleanValue());
-
- // Neg Double
- log.trace("parse(-1 * 12345.67 = -12345.67)");
- result = (Operator) parser.parse("-1 * 12345.67 = -12345.67", identifierMap);
- log.trace("result -> "+result);
- b = (Boolean) result.apply();
- assertTrue("is true", b.booleanValue());
-
- log.trace("parse(-(1 * 12345.67) = -12345.67)");
- result = (Operator) parser.parse("-(1 * 12345.67) = -12345.67", identifierMap);
- log.trace("result -> "+result);
- b = (Boolean) result.apply();
- assertTrue("is true", b.booleanValue());
- }
-
- public void testPrecedenceNAssoc() throws Exception
- {
- log.trace("parse(4 + 2 * 3 / 2 = 7)");
- Operator result = (Operator) parser.parse("4 + 2 * 3 / 2 = 7", identifierMap);
- log.trace("result -> "+result);
- Boolean b = (Boolean) result.apply();
- assertTrue("is true", b.booleanValue());
-
- log.trace("parse(4 + ((2 * 3) / 2) = 7)");
- result = (Operator) parser.parse("4 + ((2 * 3) / 2) = 7", identifierMap);
- log.trace("result -> "+result);
- b = (Boolean) result.apply();
- assertTrue("is true", b.booleanValue());
-
- log.trace("parse(4 * -2 / -1 - 4 = 4)");
- result = (Operator) parser.parse("4 * -2 / -1 - 4 = 4", identifierMap);
- log.trace("result -> "+result);
- b = (Boolean) result.apply();
- assertTrue("is true", b.booleanValue());
-
- log.trace("parse(4 * ((-2 / -1) - 4) = -8)");
- result = (Operator) parser.parse("4 * ((-2 / -1) - 4) = -8", identifierMap);
- log.trace("result -> "+result);
- b = (Boolean) result.apply();
- assertTrue("is true", b.booleanValue());
- }
-
- public void testIds() throws Exception
- {
- log.trace("parse(a + b * c / d = e)");
- Operator result = (Operator) parser.parse("a + b * c / d = e", identifierMap);
- // 4 + 2 * 3 / 2 = 7
- Identifier a = (Identifier) identifierMap.get("a");
- a.setValue(new Long(4));
- Identifier b = (Identifier) identifierMap.get("b");
- b.setValue(new Long(2));
- Identifier c = (Identifier) identifierMap.get("c");
- c.setValue(new Long(3));
- Identifier d = (Identifier) identifierMap.get("d");
- d.setValue(new Long(2));
- Identifier e = (Identifier) identifierMap.get("e");
- e.setValue(new Long(7));
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is true", bool.booleanValue());
-
- }
-
- public void testTrueINOperator() throws Exception
- {
- log.trace("parse(Status IN ('new', 'cleared', 'acknowledged'))");
- Operator result = (Operator) parser.parse("Status IN ('new', 'cleared', 'acknowledged')", identifierMap);
- Identifier a = (Identifier) identifierMap.get("Status");
- a.setValue("new");
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is true", bool.booleanValue());
- }
- public void testFalseINOperator() throws Exception
- {
- log.trace("parse(Status IN ('new', 'cleared', 'acknowledged'))");
- Operator result = (Operator) parser.parse("Status IN ('new', 'cleared', 'acknowledged')", identifierMap);
- Identifier a = (Identifier) identifierMap.get("Status");
- a.setValue("none");
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is false", !bool.booleanValue());
- }
-
- public void testTrueOROperator() throws Exception
- {
- log.trace("parse((Status = 'new') OR (Status = 'cleared') OR (Status = 'acknowledged'))");
- Operator result = (Operator) parser.parse("(Status = 'new') OR (Status = 'cleared') OR (Status= 'acknowledged')", identifierMap);
- Identifier a = (Identifier) identifierMap.get("Status");
- a.setValue("new");
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is true", bool.booleanValue());
- }
- public void testFalseOROperator() throws Exception
- {
- log.trace("parse((Status = 'new') OR (Status = 'cleared') OR (Status = 'acknowledged'))");
- Operator result = (Operator) parser.parse("(Status = 'new') OR (Status = 'cleared') OR (Status = 'acknowledged')", identifierMap);
- Identifier a = (Identifier) identifierMap.get("Status");
- a.setValue("none");
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is false", !bool.booleanValue());
- }
-
- public void testInvalidSelector() throws Exception
- {
- log.trace("parse(definitely not a message selector!)");
- try
- {
- Object result = parser.parse("definitely not a message selector!", identifierMap);
- log.trace("result -> "+result);
- fail("Should throw an Exception.\n");
- }
- catch (Exception e)
- {
- log.trace("testInvalidSelector failed as expected", e);
- }
- }
-
- /**
- * Test diffent syntax for approximate numeric literal (+6.2, -95.7, 7.)
- */
- public void testApproximateNumericLiteral1()
- {
- try
- {
- log.trace("parse(average = +6.2)");
- Object result = parser.parse("average = +6.2", identifierMap);
- log.trace("result -> "+result);
- } catch (Exception e)
- {
- fail(""+e);
- }
- }
-
- public void testApproximateNumericLiteral2()
- {
- try
- {
- log.trace("parse(average = -95.7)");
- Object result = parser.parse("average = -95.7", identifierMap);
- log.trace("result -> "+result);
- } catch (Exception e)
- {
- fail(""+e);
- }
- }
- public void testApproximateNumericLiteral3()
- {
- try
- {
- log.trace("parse(average = 7.)");
- Object result = parser.parse("average = 7.", identifierMap);
- log.trace("result -> "+result);
- } catch (Exception e)
- {
- fail(""+e);
- }
- }
-
- public void testGTExact()
- {
- try
- {
- log.trace("parse(weight > 2500)");
- Operator result = (Operator)parser.parse("weight > 2500", identifierMap);
- ((Identifier) identifierMap.get("weight")).setValue(new Integer(3000));
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is true", bool.booleanValue());
- } catch (Exception e)
- {
- log.trace("failed", e);
- fail(""+e);
- }
- }
-
- public void testGTFloat()
- {
- try
- {
- log.trace("parse(weight > 2500)");
- Operator result = (Operator)parser.parse("weight > 2500", identifierMap);
- ((Identifier) identifierMap.get("weight")).setValue(new Float(3000));
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is true", bool.booleanValue());
- } catch (Exception e)
- {
- log.trace("failed", e);
- fail(""+e);
- }
- }
-
- public void testLTDouble()
- {
- try
- {
- log.trace("parse(weight < 1.5)");
- Operator result = (Operator)parser.parse("weight < 1.5", identifierMap);
- ((Identifier) identifierMap.get("weight")).setValue(new Double(1.2));
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is true", bool.booleanValue());
- } catch (Exception e)
- {
- log.trace("failed", e);
- fail(""+e);
- }
- }
-
- public void testAndCombination()
- {
- try
- {
- log.trace("parse(JMSType = 'car' AND color = 'blue' AND weight > 2500)");
- Operator result = (Operator)parser.parse("JMSType = 'car' AND color = 'blue' AND weight > 2500", identifierMap);
- ((Identifier) identifierMap.get("JMSType")).setValue("car");
- ((Identifier) identifierMap.get("color")).setValue("blue");
- ((Identifier) identifierMap.get("weight")).setValue("3000");
-
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is false", !bool.booleanValue());
- } catch (Exception e)
- {
- log.trace("failed", e);
- fail(""+e);
- }
- }
-
- public void testINANDCombination()
- {
- try
- {
- log.trace("parse(Cateogry IN ('category1') AND Rating >= 2");
- Operator result = (Operator)parser.parse("Cateogry IN ('category1') AND Rating >= 2", identifierMap);
- ((Identifier) identifierMap.get("Cateogry")).setValue("category1");
- ((Identifier) identifierMap.get("Rating")).setValue(new Integer(3));
- log.trace("result -> "+result);
- Boolean bool = (Boolean) result.apply();
- assertTrue("is true", bool.booleanValue());
- } catch (Exception e)
- {
- log.trace("failed", e);
- fail(""+e);
- }
- }
-
- /** This testcase does not use the JBossServer so override
- the testServerFound to be a noop
- */
- public void testServerFound()
- {
- }
-
- public static void main(java.lang.String[] args)
- {
- junit.textui.TestRunner.run(SelectorParserTest.class);
- }
-}
Deleted: trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorSyntaxTest.java
===================================================================
--- trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorSyntaxTest.java 2008-01-18 04:19:56 UTC (rev 3589)
+++ trunk/tests/src/org/jboss/test/messaging/jms/selector/SelectorSyntaxTest.java 2008-01-18 13:36:40 UTC (rev 3590)
@@ -1,505 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005, JBoss Inc., 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.test.messaging.jms.selector;
-
-import org.jboss.jms.message.JBossMessage;
-import org.jboss.jms.server.selector.Selector;
-import org.jboss.test.messaging.JBMBaseTestCase;
-
-/**
- * Tests the complinace with the JMS Selector syntax.
- *
- * <p>Needs a lot of work...
- *
- * @author <a href="mailto:jason at planet57.com">Jason Dillon</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a> Ported from JBossMQ
- * @version $Revision$
- */
-public class SelectorSyntaxTest
- extends JBMBaseTestCase
-{
- private Selector selector;
- private JBossMessage message;
-
- public SelectorSyntaxTest(String name)
- {
- super(name);
- }
-
- protected void setUp() throws Exception
- {
- super.setUp();
- message = new JBossMessage();
- }
-
- public void testBooleanTrue() throws Exception
- {
- selector = new Selector("MyBoolean=true");
- testBoolean("MyBoolean", true);
- }
-
- public void testBooleanFalse() throws Exception
- {
- selector = new Selector("MyBoolean=false");
- testBoolean("MyBoolean", false);
- }
-
- private void testBoolean(String name, boolean flag) throws Exception
- {
- message.setBooleanProperty(name, flag);
- assertTrue(selector.match(message.getCoreMessage()));
-
- message.setBooleanProperty(name, !flag);
- assertTrue(!selector.match(message.getCoreMessage()));
- }
-
- public void testStringEquals() throws Exception
- {
- // First, simple test of string equality and inequality
- selector = new Selector("MyString='astring'");
-
- message.setStringProperty("MyString", "astring");
- assertTrue(selector.match(message.getCoreMessage()));
-
- message.setStringProperty("MyString", "NOTastring");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test empty string
- selector = new Selector("MyString=''");
-
- message.setStringProperty("MyString", "");
- assertTrue("test 1", selector.match(message.getCoreMessage()));
-
- message.setStringProperty("MyString", "NOTastring");
- assertTrue("test 2", !selector.match(message.getCoreMessage()));
-
- // test literal apostrophes (which are escaped using two apostrophes
- // in selectors)
- selector = new Selector("MyString='test JBoss''s selector'");
-
- // note: apostrophes are not escaped in string properties
- message.setStringProperty("MyString", "test JBoss's selector");
- // this test fails -- bug 530120
- //assertTrue("test 3", selector.match(message.getCoreMessage()));
-
- message.setStringProperty("MyString", "NOTastring");
- assertTrue("test 4", !selector.match(message.getCoreMessage()));
-
- }
-
- public void testStringLike() throws Exception
- {
- // test LIKE operator with no wildcards
- selector = new Selector("MyString LIKE 'astring'");
-
- // test where LIKE operand matches
- message.setStringProperty("MyString", "astring");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // test one character string
- selector = new Selector("MyString LIKE 'a'");
- message.setStringProperty("MyString","a");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // test empty string
- selector = new Selector("MyString LIKE ''");
- message.setStringProperty("MyString", "");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // tests where operand does not match
- selector = new Selector("MyString LIKE 'astring'");
-
- // test with extra characters at beginning
- message.setStringProperty("MyString", "NOTastring");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test with extra characters at end
- message.setStringProperty("MyString", "astringNOT");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test with extra characters in the middle
- message.setStringProperty("MyString", "astNOTring");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test where operand is entirely different
- message.setStringProperty("MyString", "totally different");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test case sensitivity
- message.setStringProperty("MyString", "ASTRING");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test empty string
- message.setStringProperty("MyString", "");
- assertTrue(!selector.match(message.getCoreMessage()));
-
-
- // test lower-case 'like' operator?
- }
-
- public void testStringLikeUnderbarWildcard() throws Exception
- {
- // test LIKE operator with the _ wildcard, which
- // matches any single character
-
- // first, some tests with the wildcard by itself
- selector = new Selector("MyString LIKE '_'");
-
- // test match against single character
- message.setStringProperty("MyString", "a");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // test match failure against multiple characters
- message.setStringProperty("MyString", "aaaaa");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test match failure against the empty string
- message.setStringProperty("MyString", "");
- assertTrue(!selector.match(message.getCoreMessage()));
-
-
- // next, tests with wildcard at the beginning of the string
- selector = new Selector("MyString LIKE '_bcdf'");
-
- // test match at beginning of string
- message.setStringProperty("MyString", "abcdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // match failure in first character after wildcard
- message.setStringProperty("MyString", "aXcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in middle character
- message.setStringProperty("MyString", "abXdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in last character
- message.setStringProperty("MyString", "abcdX");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure with empty string
- message.setStringProperty("MyString", "");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at beginning
- message.setStringProperty("MyString", "XXXabcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at the end
- message.setStringProperty("MyString", "abcdfXXX");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test that the _ wildcard does not match the 'empty' character
- message.setStringProperty("MyString", "bcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // next, tests with wildcard at the end of the string
- selector = new Selector("MyString LIKE 'abcd_'");
-
- // test match at end of string
- message.setStringProperty("MyString", "abcdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // match failure in first character before wildcard
- message.setStringProperty("MyString", "abcXf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in middle character
- message.setStringProperty("MyString", "abXdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in first character
- message.setStringProperty("MyString", "Xbcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure with empty string
- message.setStringProperty("MyString", "");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at beginning
- message.setStringProperty("MyString", "XXXabcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at the end
- message.setStringProperty("MyString", "abcdfXXX");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test that the _ wildcard does not match the 'empty' character
- message.setStringProperty("MyString", "abcd");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test match in middle of string
-
- // next, tests with wildcard in the middle of the string
- selector = new Selector("MyString LIKE 'ab_df'");
-
- // test match in the middle of string
- message.setStringProperty("MyString", "abcdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // match failure in first character before wildcard
- message.setStringProperty("MyString", "aXcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in first character after wildcard
- message.setStringProperty("MyString", "abcXf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in last character
- message.setStringProperty("MyString", "abcdX");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure with empty string
- message.setStringProperty("MyString", "");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at beginning
- message.setStringProperty("MyString", "XXXabcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at the end
- message.setStringProperty("MyString", "abcdfXXX");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test that the _ wildcard does not match the 'empty' character
- message.setStringProperty("MyString", "abdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test match failures
- }
-
- public void testStringLikePercentWildcard() throws Exception
- {
- // test LIKE operator with the % wildcard, which
- // matches any sequence of characters
- // note many of the tests are similar to those for _
-
-
- // first, some tests with the wildcard by itself
- selector = new Selector("MyString LIKE '%'");
-
- // test match against single character
- message.setStringProperty("MyString", "a");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // test match against multiple characters
- message.setStringProperty("MyString", "aaaaa");
- assertTrue(selector.match(message.getCoreMessage()));
-
- message.setStringProperty("MyString", "abcdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // test match against the empty string
- message.setStringProperty("MyString", "");
- assertTrue(selector.match(message.getCoreMessage()));
-
-
- // next, tests with wildcard at the beginning of the string
- selector = new Selector("MyString LIKE '%bcdf'");
-
- // test match with single character at beginning of string
- message.setStringProperty("MyString", "Xbcdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // match with multiple characters at beginning
- message.setStringProperty("MyString", "XXbcdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // match failure in middle character
- message.setStringProperty("MyString", "abXdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in last character
- message.setStringProperty("MyString", "abcdX");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure with empty string
- message.setStringProperty("MyString", "");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at the end
- message.setStringProperty("MyString", "abcdfXXX");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test that the % wildcard matches the empty string
- message.setStringProperty("MyString", "bcdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // next, tests with wildcard at the end of the string
- selector = new Selector("MyString LIKE 'abcd%'");
-
- // test match of single character at end of string
- message.setStringProperty("MyString", "abcdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // test match of multiple characters at end of string
- message.setStringProperty("MyString", "abcdfgh");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // match failure in first character before wildcard
- message.setStringProperty("MyString", "abcXf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in middle character
- message.setStringProperty("MyString", "abXdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in first character
- message.setStringProperty("MyString", "Xbcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure with empty string
- message.setStringProperty("MyString", "");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at beginning
- message.setStringProperty("MyString", "XXXabcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test that the % wildcard matches the empty string
- message.setStringProperty("MyString", "abcd");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // next, tests with wildcard in the middle of the string
- selector = new Selector("MyString LIKE 'ab%df'");
-
- // test match with single character in the middle of string
- message.setStringProperty("MyString", "abXdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // test match with multiple characters in the middle of string
- message.setStringProperty("MyString", "abXXXdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // match failure in first character before wildcard
- message.setStringProperty("MyString", "aXcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in first character after wildcard
- message.setStringProperty("MyString", "abcXf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure in last character
- message.setStringProperty("MyString", "abcdX");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure with empty string
- message.setStringProperty("MyString", "");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at beginning
- message.setStringProperty("MyString", "XXXabcdf");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // match failure due to extra characters at the end
- message.setStringProperty("MyString", "abcdfXXX");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- // test that the % wildcard matches the empty string
- message.setStringProperty("MyString", "abdf");
- assertTrue(selector.match(message.getCoreMessage()));
-
- }
-
- public void testStringLikePunctuation() throws Exception
- {
- // test proper handling of some punctuation characters.
- // non-trivial since the underlying implementation might
- // (and in fact currently does) use a general-purpose
- // RE library, which has a different notion of which
- // characters are wildcards
-
- // the particular tests here are motivated by the
- // wildcards of the current underlying RE engine,
- // GNU regexp.
-
- selector = new Selector("MyString LIKE 'a^$b'");
- message.setStringProperty("MyString", "a^$b");
- assertTrue(selector.match(message.getCoreMessage()));
-
- // this one has a double backslash since backslash
- // is interpreted specially by Java
- selector = new Selector("MyString LIKE 'a\\dc'");
- message.setStringProperty("MyString", "a\\dc");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE 'a.c'");
- message.setStringProperty("MyString", "abc");
- assertTrue(!selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '[abc]'");
- message.setStringProperty("MyString", "[abc]");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '[^abc]'");
- message.setStringProperty("MyString", "[^abc]");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '[a-c]'");
- message.setStringProperty("MyString", "[a-c]");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '[:alpha]'");
- message.setStringProperty("MyString", "[:alpha]");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '(abc)'");
- message.setStringProperty("MyString", "(abc)");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE 'a|bc'");
- message.setStringProperty("MyString", "a|bc");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '(abc)?'");
- message.setStringProperty("MyString", "(abc)?");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '(abc)*'");
- message.setStringProperty("MyString", "(abc)*");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '(abc)+'");
- message.setStringProperty("MyString", "(abc)+");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '(abc){3}'");
- message.setStringProperty("MyString", "(abc){3}");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '(abc){3,5}'");
- message.setStringProperty("MyString", "(abc){3,5}");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '(abc){3,}'");
- message.setStringProperty("MyString", "(abc){3,}");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '(?=abc)'");
- message.setStringProperty("MyString", "(?=abc)");
- assertTrue(selector.match(message.getCoreMessage()));
-
- selector = new Selector("MyString LIKE '(?!abc)'");
- message.setStringProperty("MyString", "(?!abc)");
- assertTrue(selector.match(message.getCoreMessage()));
- }
-}
More information about the jboss-cvs-commits
mailing list