activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r783414 - in /activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org: ./ apache/ apache/activemq/ apache/activemq/selector/ apache/activemq/selector/SelectorParserTest.java apache/activemq/selector/SelectorTest.java
Date Wed, 10 Jun 2009 16:28:54 GMT
Author: chirino
Date: Wed Jun 10 16:28:54 2009
New Revision: 783414

URL: http://svn.apache.org/viewvc?rev=783414&view=rev
Log:
Adding selector tests from  trunk

Added:
    activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/
    activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/
    activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/
    activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/
      - copied from r783310, activemq/trunk/activemq-core/src/test/java/org/apache/activemq/selector/
Modified:
    activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java
    activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java

Modified: activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java?rev=783414&r1=783310&r2=783414&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java
(original)
+++ activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorParserTest.java
Wed Jun 10 16:28:54 2009
@@ -17,13 +17,13 @@
 package org.apache.activemq.selector;
 
 import junit.framework.TestCase;
+
 import org.apache.activemq.filter.BooleanExpression;
 import org.apache.activemq.filter.ComparisonExpression;
 import org.apache.activemq.filter.Expression;
 import org.apache.activemq.filter.LogicExpression;
 import org.apache.activemq.filter.PropertyExpression;
 import org.apache.activemq.filter.XPathExpression;
-import org.apache.activemq.spring.ConsumerBean;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 

Modified: activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java?rev=783414&r1=783310&r2=783414&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java
(original)
+++ activemq/sandbox/activemq-flow/activemq-selector/src/test/java/org/apache/activemq/selector/SelectorTest.java
Wed Jun 10 16:28:54 2009
@@ -16,24 +16,113 @@
  */
 package org.apache.activemq.selector;
 
-import javax.jms.InvalidSelectorException;
-import javax.jms.JMSException;
-import javax.jms.Message;
+import java.util.HashMap;
 
 import junit.framework.TestCase;
-import org.apache.activemq.command.ActiveMQMessage;
-import org.apache.activemq.command.ActiveMQTextMessage;
-import org.apache.activemq.command.ActiveMQTopic;
+
 import org.apache.activemq.filter.BooleanExpression;
+import org.apache.activemq.filter.Expression;
+import org.apache.activemq.filter.FilterException;
 import org.apache.activemq.filter.MessageEvaluationContext;
 
 /**
  * @version $Revision: 1.7 $
  */
 public class SelectorTest extends TestCase {
+		
+    class MockMessage implements MessageEvaluationContext {
+
+    	HashMap<String, Object> properties = new HashMap<String, Object>();
+		private String text;
+		private Object destination;
+		private String messageId;
+		private String type;
+		private Object localConnectionId;
+    	
+		public void setDestination(Object destination) {
+			this.destination=destination;
+		}
+		public void setJMSMessageID(String messageId) {
+			this.messageId = messageId;
+		}
+		public void setJMSType(String type) {
+			this.type = type;
+		}
+		public void setText(String text) {
+			this.text = text;
+		}
+
+		public void setBooleanProperty(String key, boolean value) {
+			properties.put(key, value);
+		}
+
+		public void setStringProperty(String key, String value) {
+			properties.put(key, value);
+		}
+
+		public void setByteProperty(String key, byte value) {
+			properties.put(key, value);
+		}
+
+		public void setDoubleProperty(String key, double value) {
+			properties.put(key, value);
+		}
+
+		public void setFloatProperty(String key, float value) {
+			properties.put(key, value);
+		}
+
+		public void setLongProperty(String key, long value) {
+			properties.put(key, value);
+		}
+
+		public void setIntProperty(String key, int value) {
+			properties.put(key, value);
+		}
+
+		public void setShortProperty(String key, short value) {
+			properties.put(key, value);
+		}
+
+		public void setObjectProperty(String key, Object value) {
+			properties.put(key, value);
+		}
+
+		public <T> T getBodyAs(Class<T> type) throws FilterException {
+			if( type == String.class ) {
+				return type.cast(text);
+			}
+			return null;
+		}
+
+		public <T> T getDestination() {
+			return (T)destination;
+		}
+
+		public Object getLocalConnectionId() {
+			return localConnectionId;
+		}
+
+		public Expression getPropertyExpression(final String name) {
+			return new Expression() {
+		        public Object evaluate(MessageEvaluationContext mc) throws FilterException {
+	                MockMessage mockMessage = (MockMessage)mc;
+	    			if( "JMSType".equals(name) ) {
+	    				return mockMessage.type;
+	    			}
+	    			if( "JMSMessageID".equals(name) ) {
+	    				return mockMessage.messageId;
+	    			}
+					return mockMessage.properties.get(name);
+		        }
+			};
+		}
+    	
+    }
+
 
     public void testBooleanSelector() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "(trueProp OR falseProp) AND trueProp", true);
         assertSelector(message, "(trueProp OR falseProp) AND falseProp", false);
@@ -41,7 +130,7 @@
     }
 
     public void testXPathSelectors() throws Exception {
-        ActiveMQTextMessage message = new ActiveMQTextMessage();
+        MockMessage message = new MockMessage();
 
         message.setJMSType("xml");
         message.setText("<root><a key='first' num='1'/><b key='second' num='2'>b</b></root>");
@@ -83,7 +172,7 @@
     }
 
     public void testJMSPropertySelectors() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
         message.setJMSType("selector-test");
         message.setJMSMessageID("id:test:1:1:1:1");
 
@@ -102,7 +191,7 @@
     }
 
     public void testBasicSelectors() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "name = 'James'", true);
         assertSelector(message, "rank > 100", true);
@@ -112,7 +201,7 @@
     }
 
     public void testPropertyTypes() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
         assertSelector(message, "byteProp = 123", true);
         assertSelector(message, "byteProp = 10", false);
         assertSelector(message, "byteProp2 = 33", true);
@@ -138,7 +227,7 @@
     }
 
     public void testAndSelectors() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "name = 'James' and rank < 200", true);
         assertSelector(message, "name = 'James' and rank > 200", false);
@@ -147,7 +236,7 @@
     }
 
     public void testOrSelectors() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "name = 'James' or rank < 200", true);
         assertSelector(message, "name = 'James' or rank > 200", true);
@@ -157,7 +246,7 @@
     }
 
     public void testPlus() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "rank + 2 = 125", true);
         assertSelector(message, "(rank + 2) = 125", true);
@@ -168,7 +257,7 @@
     }
 
     public void testMinus() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "rank - 2 = 121", true);
         assertSelector(message, "rank - version = 121", true);
@@ -176,7 +265,7 @@
     }
 
     public void testMultiply() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "rank * 2 = 246", true);
         assertSelector(message, "rank * version = 246", true);
@@ -184,7 +273,7 @@
     }
 
     public void testDivide() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "rank / version = 61.5", true);
         assertSelector(message, "rank / 3 > 100.0", false);
@@ -194,14 +283,14 @@
     }
 
     public void testBetween() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "rank between 100 and 150", true);
         assertSelector(message, "rank between 10 and 120", false);
     }
 
     public void testIn() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "name in ('James', 'Bob', 'Gromit')", true);
         assertSelector(message, "name in ('Bob', 'James', 'Gromit')", true);
@@ -212,7 +301,7 @@
     }
 
     public void testIsNull() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "dummy is null", true);
         assertSelector(message, "dummy is not null", false);
@@ -221,7 +310,7 @@
     }
 
     public void testLike() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
         message.setStringProperty("modelClassId", "com.whatever.something.foo.bar");
         message.setStringProperty("modelInstanceId", "170");
         message.setStringProperty("modelRequestError", "abc");
@@ -248,7 +337,7 @@
      * Test cases from Mats Henricson
      */
     public void testMatsHenricsonUseCases() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
         assertSelector(message, "SessionserverId=1870414179", false);
 
         message.setLongProperty("SessionserverId", 1870414179);
@@ -269,7 +358,7 @@
     }
 
     public void testFloatComparisons() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         // JMS 1.1 Section 3.8.1.1 : Approximate literals use the Java
         // floating-point literal syntax.
@@ -318,12 +407,12 @@
     }
 
     public void testStringQuoteParsing() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
         assertSelector(message, "quote = '''In God We Trust'''", true);
     }
 
     public void testLikeComparisons() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
 
         assertSelector(message, "quote LIKE '''In G_d We Trust'''", true);
         assertSelector(message, "quote LIKE '''In Gd_ We Trust'''", false);
@@ -344,14 +433,14 @@
     }
 
     public void testInvalidSelector() throws Exception {
-        Message message = createMessage();
+        MockMessage message = createMessage();
         assertInvalidSelector(message, "3+5");
         assertInvalidSelector(message, "True AND 3+5");
         assertInvalidSelector(message, "=TEST 'test'");
     }
 
-    protected Message createMessage() throws JMSException {
-        Message message = createMessage("FOO.BAR");
+    protected MockMessage createMessage() {
+        MockMessage message = createMessage("FOO.BAR");
         message.setJMSType("selector-test");
         message.setJMSMessageID("connection:1:1:1:1");
         message.setObjectProperty("name", "James");
@@ -375,26 +464,24 @@
         return message;
     }
 
-    protected void assertInvalidSelector(Message message, String text) throws JMSException
{
+    protected void assertInvalidSelector(MockMessage message, String text) {
         try {
             SelectorParser.parse(text);
             fail("Created a valid selector");
-        } catch (InvalidSelectorException e) {
+        } catch (FilterException e) {
         }
     }
-
-    protected void assertSelector(Message message, String text, boolean expected) throws
JMSException {
+    
+    protected void assertSelector(MockMessage message, String text, boolean expected) throws
FilterException {
         BooleanExpression selector = SelectorParser.parse(text);
         assertTrue("Created a valid selector", selector != null);
-        MessageEvaluationContext context = new MessageEvaluationContext();
-        context.setMessageReference((org.apache.activemq.command.Message)message);
-        boolean value = selector.matches(context);
+        boolean value = selector.matches(message);
         assertEquals("Selector for: " + text, expected, value);
     }
 
-    protected Message createMessage(String subject) throws JMSException {
-        ActiveMQMessage message = new ActiveMQMessage();
-        message.setJMSDestination(new ActiveMQTopic(subject));
+    protected MockMessage createMessage(String subject) {
+    	MockMessage message = new MockMessage();
+        message.setDestination(subject);
         return message;
     }
 }



Mime
View raw message