001: /*
002: * Copyright (C) The MX4J Contributors.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the MX4J License version 1.0.
006: * See the terms of the MX4J License in the documentation provided with this software.
007: */
008:
009: package test.javax.management;
010:
011: import javax.management.BadBinaryOpValueExpException;
012: import javax.management.Query;
013: import javax.management.QueryExp;
014: import javax.management.StringValueExp;
015: import javax.management.ValueExp;
016:
017: import junit.framework.TestCase;
018:
019: /**
020: * @version $Revision: 1.4 $
021: */
022: public class BinaryRelQueryExpTest extends TestCase {
023: /**
024: * Constructor requested by the JUnit framework
025: */
026: public BinaryRelQueryExpTest(String name) {
027: super (name);
028: }
029:
030: public void testExceptions() throws Exception {
031: QueryExp operation = Query.eq(null, null);
032: assertTrue(operation.apply(null));
033:
034: ValueExp value1 = Query.value(new Integer(3));
035: operation = Query.eq(value1, null);
036: assertTrue(!operation.apply(null));
037:
038: operation = Query.eq(null, value1);
039: assertTrue(!operation.apply(null));
040:
041: ValueExp value2 = Query.value(new Long(3));
042: ValueExp result = Query.plus(value1, value2);
043: operation = Query.eq(Query.value(6), result);
044: assertTrue(operation.apply(null));
045:
046: // Comparing apple and oranges
047: ValueExp bvalue1 = Query.value(true);
048: operation = Query.eq(bvalue1, value2);
049: assertTrue(!operation.apply(null));
050:
051: // Adding 2 booleans
052: ValueExp bvalue2 = Query.value(true);
053: result = Query.plus(bvalue1, bvalue2);
054: operation = Query.eq(Query.value(false), result);
055: try {
056: operation.apply(null);
057: } catch (BadBinaryOpValueExpException ignored) {
058: }
059:
060: StringValueExp svalue1 = new StringValueExp("a");
061: StringValueExp svalue2 = new StringValueExp("b");
062: operation = Query.eq(svalue1, null);
063: assertTrue(!operation.apply(null));
064: operation = Query.eq(svalue1, svalue2);
065: assertTrue(!operation.apply(null));
066: }
067:
068: public void testNumericals() throws Exception {
069: ValueExp value1 = Query.value(new Integer(3));
070: ValueExp value2 = Query.value(new Long(3));
071: QueryExp operation = Query.eq(value1, value2);
072: assertTrue(operation.apply(null));
073:
074: value1 = Query.value(new Integer(5));
075: value2 = Query.value(new Long(4));
076: operation = Query.gt(value1, value2);
077: assertTrue(operation.apply(null));
078:
079: value1 = Query.value(new Integer(3));
080: value2 = Query.value(new Long(4));
081: operation = Query.lt(value1, value2);
082: assertTrue(operation.apply(null));
083:
084: value1 = Query.value(new Double(3));
085: value2 = Query.value(new Long(3));
086: operation = Query.eq(value1, value2);
087: assertTrue(operation.apply(null));
088:
089: value1 = Query.value(new Float(5));
090: value2 = Query.value(new Double(4));
091: operation = Query.gt(value1, value2);
092: assertTrue(operation.apply(null));
093:
094: value1 = Query.value(new Double(3));
095: value2 = Query.value(new Double(4));
096: operation = Query.lt(value1, value2);
097: assertTrue(operation.apply(null));
098: }
099:
100: public void testBooleans() throws Exception {
101: ValueExp value1 = Query.value(true);
102: ValueExp value2 = Query.value(false);
103: QueryExp operation = Query.eq(value1, value2);
104: assertTrue(!operation.apply(null));
105:
106: operation = Query.or(Query.eq(value1, value1), Query.eq(value1,
107: value2));
108: assertTrue(operation.apply(null));
109:
110: operation = Query.or(Query.eq(value1, value2), Query.eq(value2,
111: value2));
112: assertTrue(operation.apply(null));
113:
114: operation = Query.and(Query.eq(value1, value2), Query.eq(
115: value2, value2));
116: assertTrue(!operation.apply(null));
117:
118: operation = Query.and(Query.eq(value1, value1), Query.eq(
119: value1, value2));
120: assertTrue(!operation.apply(null));
121: }
122:
123: public void testStrings() throws Exception {
124: StringValueExp value1 = new StringValueExp("a");
125: StringValueExp value2 = new StringValueExp("a");
126: QueryExp operation = Query.eq(value1, value2);
127: assertTrue(operation.apply(null));
128: operation = Query.geq(value1, value2);
129: assertTrue(operation.apply(null));
130: operation = Query.gt(value1, value2);
131: assertTrue(!operation.apply(null));
132: operation = Query.leq(value1, value2);
133: assertTrue(operation.apply(null));
134: operation = Query.lt(value1, value2);
135: assertTrue(!operation.apply(null));
136:
137: value1 = new StringValueExp("a");
138: value2 = new StringValueExp("b");
139:
140: operation = Query.geq(value1, value2);
141: assertTrue(!operation.apply(null));
142: operation = Query.geq(value2, value1);
143: assertTrue(operation.apply(null));
144: operation = Query.gt(value1, value2);
145: assertTrue(!operation.apply(null));
146: operation = Query.gt(value2, value1);
147: assertTrue(operation.apply(null));
148: operation = Query.leq(value1, value2);
149: assertTrue(operation.apply(null));
150: operation = Query.leq(value2, value1);
151: assertTrue(!operation.apply(null));
152: operation = Query.lt(value1, value2);
153: assertTrue(operation.apply(null));
154: operation = Query.lt(value2, value1);
155: assertTrue(!operation.apply(null));
156: }
157: }
|