mirror of https://github.com/apache/activemq.git
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1157433 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0885c60c4d
commit
a6f1d756ef
|
@ -160,6 +160,7 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
return UnaryExpression.createNOT(createLike(left, right, escape));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static BooleanExpression createInFilter(Expression left, List elements) {
|
||||
|
||||
if (!(left instanceof PropertyExpression)) {
|
||||
|
@ -169,6 +170,7 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public static BooleanExpression createNotInFilter(Expression left, List elements) {
|
||||
|
||||
if (!(left instanceof PropertyExpression)) {
|
||||
|
@ -197,6 +199,7 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
return doCreateEqual(left, right);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
private static BooleanExpression doCreateEqual(Expression left, Expression right) {
|
||||
return new ComparisonExpression(left, right) {
|
||||
|
||||
|
@ -204,7 +207,7 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
Object lv = left.evaluate(message);
|
||||
Object rv = right.evaluate(message);
|
||||
|
||||
// Iff one of the values is null
|
||||
// If one of the values is null
|
||||
if (lv == null ^ rv == null) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
@ -333,6 +336,7 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public Object evaluate(MessageEvaluationContext message) throws JMSException {
|
||||
Comparable<Comparable> lv = (Comparable)left.evaluate(message);
|
||||
if (lv == null) {
|
||||
|
@ -345,13 +349,21 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
return compare(lv, rv);
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected Boolean compare(Comparable lv, Comparable rv) {
|
||||
Class<? extends Comparable> lc = lv.getClass();
|
||||
Class<? extends Comparable> rc = rv.getClass();
|
||||
// If the the objects are not of the same type,
|
||||
// try to convert up to allow the comparison.
|
||||
if (lc != rc) {
|
||||
if (lc == Byte.class) {
|
||||
try {
|
||||
if (lc == Boolean.class) {
|
||||
if (rc == String.class) {
|
||||
lv = Boolean.valueOf((String)lv).booleanValue();
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
} else if (lc == Byte.class) {
|
||||
if (rc == Short.class) {
|
||||
lv = Short.valueOf(((Number)lv).shortValue());
|
||||
} else if (rc == Integer.class) {
|
||||
|
@ -362,6 +374,8 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
lv = new Float(((Number)lv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else if (rc == String.class) {
|
||||
rv = Byte.valueOf((String)rv);
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
@ -374,6 +388,8 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
lv = new Float(((Number)lv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else if (rc == String.class) {
|
||||
rv = Short.valueOf((String)rv);
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
@ -384,6 +400,8 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
lv = new Float(((Number)lv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else if (rc == String.class) {
|
||||
rv = Integer.valueOf((String)rv);
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
@ -394,6 +412,8 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
lv = new Float(((Number)lv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else if (rc == String.class) {
|
||||
rv = Long.valueOf((String)rv);
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
@ -404,6 +424,8 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
rv = new Float(((Number)rv).floatValue());
|
||||
} else if (rc == Double.class) {
|
||||
lv = new Double(((Number)lv).doubleValue());
|
||||
} else if (rc == String.class) {
|
||||
rv = Float.valueOf((String)rv);
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
|
@ -414,12 +436,35 @@ public abstract class ComparisonExpression extends BinaryExpression implements B
|
|||
rv = new Double(((Number)rv).doubleValue());
|
||||
} else if (rc == Float.class) {
|
||||
rv = new Float(((Number)rv).doubleValue());
|
||||
} else if (rc == String.class) {
|
||||
rv = Double.valueOf((String)rv);
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
} else if (lc == String.class) {
|
||||
if (rc == Boolean.class) {
|
||||
lv = Boolean.valueOf((String)lv);
|
||||
} else if (rc == Byte.class) {
|
||||
lv = Byte.valueOf((String)lv);
|
||||
} else if (rc == Short.class) {
|
||||
lv = Short.valueOf((String)lv);
|
||||
} else if (rc == Integer.class) {
|
||||
lv = Integer.valueOf((String)lv);
|
||||
} else if (rc == Long.class) {
|
||||
lv = Long.valueOf((String)lv);
|
||||
} else if (rc == Float.class) {
|
||||
lv = Float.valueOf((String)lv);
|
||||
} else if (rc == Double.class) {
|
||||
lv = Double.valueOf((String)lv);
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
} else {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
} catch(NumberFormatException e) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
return asBoolean(lv.compareTo(rv)) ? Boolean.TRUE : Boolean.FALSE;
|
||||
}
|
||||
|
|
|
@ -574,6 +574,87 @@ public class StompTest extends CombinationTestSupport {
|
|||
stompConnection.sendFrame(frame);
|
||||
}
|
||||
|
||||
public void testSubscribeWithAutoAckAndNumericSelector() throws Exception {
|
||||
|
||||
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
frame = stompConnection.receiveFrame();
|
||||
assertTrue(frame.startsWith("CONNECTED"));
|
||||
|
||||
frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "selector: foo = 42\n" + "ack:auto\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
// Ignored
|
||||
frame = "SEND\n" + "foo:abc\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Ignored Message" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
// Matches
|
||||
frame = "SEND\n" + "foo:42\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Real Message" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
frame = stompConnection.receiveFrame();
|
||||
assertTrue(frame.startsWith("MESSAGE"));
|
||||
assertTrue("Should have received the real message but got: " + frame, frame.indexOf("Real Message") > 0);
|
||||
|
||||
frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
}
|
||||
|
||||
public void testSubscribeWithAutoAckAndBooleanSelector() throws Exception {
|
||||
|
||||
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
frame = stompConnection.receiveFrame();
|
||||
assertTrue(frame.startsWith("CONNECTED"));
|
||||
|
||||
frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "selector: foo = true\n" + "ack:auto\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
// Ignored
|
||||
frame = "SEND\n" + "foo:false\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Ignored Message" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
// Matches
|
||||
frame = "SEND\n" + "foo:true\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Real Message" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
frame = stompConnection.receiveFrame();
|
||||
assertTrue(frame.startsWith("MESSAGE"));
|
||||
assertTrue("Should have received the real message but got: " + frame, frame.indexOf("Real Message") > 0);
|
||||
|
||||
frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
}
|
||||
|
||||
public void testSubscribeWithAutoAckAnFloatSelector() throws Exception {
|
||||
|
||||
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
frame = stompConnection.receiveFrame();
|
||||
assertTrue(frame.startsWith("CONNECTED"));
|
||||
|
||||
frame = "SUBSCRIBE\n" + "destination:/queue/" + getQueueName() + "\n" + "selector: foo = 3.14159\n" + "ack:auto\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
// Ignored
|
||||
frame = "SEND\n" + "foo:6.578\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Ignored Message" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
// Matches
|
||||
frame = "SEND\n" + "foo:3.14159\n" + "destination:/queue/" + getQueueName() + "\n\n" + "Real Message" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
|
||||
frame = stompConnection.receiveFrame();
|
||||
assertTrue(frame.startsWith("MESSAGE"));
|
||||
assertTrue("Should have received the real message but got: " + frame, frame.indexOf("Real Message") > 0);
|
||||
|
||||
frame = "DISCONNECT\n" + "\n\n" + Stomp.NULL;
|
||||
stompConnection.sendFrame(frame);
|
||||
}
|
||||
|
||||
public void testSubscribeWithClientAck() throws Exception {
|
||||
|
||||
String frame = "CONNECT\n" + "login: system\n" + "passcode: manager\n\n" + Stomp.NULL;
|
||||
|
|
Loading…
Reference in New Issue