cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amicha...@apache.org
Subject svn commit: r1078380 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/ext/search/client/ test/java/org/apache/cxf/jaxrs/ext/search/client/
Date Sat, 05 Mar 2011 22:35:49 GMT
Author: amichalec
Date: Sat Mar  5 22:35:48 2011
New Revision: 1078380

URL: http://svn.apache.org/viewvc?rev=1078380&view=rev
Log:
Client-side search condition builder with FIQL implementation (draft)

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java?rev=1078380&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilder.java
Sat Mar  5 22:35:48 2011
@@ -0,0 +1,291 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search.client;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.xml.datatype.Duration;
+
+import org.apache.cxf.jaxrs.ext.search.FiqlParser;
+
+/**
+ * Builds client-side search condition that passed to backend can be consumed by {@link FiqlParser}.
+ * <p>
+ * Examples:
+ * 
+ * <pre>
+ * FiqlSearchConditionBuilder b = new FiqlSearchConditionBuilder();
+ * b.query().is(&quot;price&quot;).equalTo(123.5).build();
+ * // gives &quot;price==123.5&quot;
+ * b.query().is(&quot;price&quot;).greaterThan(30).and().is(&quot;price&quot;).lessThan(50).build();
+ * // gives &quot;price=gt=30.0;price=lt=50.0&quot;
+ * </pre>
+ * 
+ * For very complex junctions nested "and"/"or" are allowed (breaking a bit fluency of interface)
and looks
+ * like the following example:
+ * 
+ * <pre>
+ * PartialCondition c = b.query();
+ * c.is("price").lessThan(100).and().or(
+ *      c.is("title").equalTo("The lord*"), 
+ *      c.is("author").equalTo("R.R.Tolkien").build();
+ * // gives "price=lt=100.0;(title==The lord*,author==R.R.Tolkien)"
+ * </pre>
+ */
+public class FiqlSearchConditionBuilder implements SearchConditionBuilder {
+
+    @Override
+    public String build() {
+        return "";
+    }
+
+    @Override
+    public PartialCondition query() {
+        return new Builder();
+    }
+
+    private static class Builder implements SearchConditionBuilder.Property,
+        SearchConditionBuilder.CompleteCondition, SearchConditionBuilder.PartialCondition
{
+        private String result = "";
+        private Builder parent;
+        private DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+
+        public Builder() {
+            parent = null;
+        }
+
+        public Builder(Builder parent) {
+            this.parent = parent;
+        }
+
+        @Override
+        public String build() {
+            return buildPartial(null);
+            // if (parent != null) {
+            // return parent.build() + result;
+            // } else {
+            // return result;
+            // }
+        }
+
+        // builds from parent but not further then exclude builder
+        private String buildPartial(Builder exclude) {
+            if (parent != null && !parent.equals(exclude)) {
+                return parent.buildPartial(exclude) + result;
+            } else {
+                return result;
+            }
+        }
+
+        @Override
+        public CompleteCondition after(Date date) {
+            result += FiqlParser.GT + toString(date);
+            return this;
+        }
+
+        @Override
+        public CompleteCondition before(Date date) {
+            result += FiqlParser.LT + toString(date);
+            return this;
+        }
+
+        @Override
+        public CompleteCondition equalTo(String literalOrPattern) {
+            result += FiqlParser.EQ + literalOrPattern;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition equalTo(double number) {
+            result += FiqlParser.EQ + number;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition equalTo(Date date) {
+            result += FiqlParser.EQ + toString(date);
+            return this;
+        }
+
+        @Override
+        public CompleteCondition greaterOrEqualTo(double number) {
+            result += FiqlParser.GE + number;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition greaterThan(double number) {
+            result += FiqlParser.GT + number;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition lessOrEqualTo(double number) {
+            result += FiqlParser.LE + number;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition lessThan(double number) {
+            result += FiqlParser.LT + number;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition lexicalAfter(String literal) {
+            result += FiqlParser.GT + literal;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition lexicalBefore(String literal) {
+            result += FiqlParser.LT + literal;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition lexicalNotAfter(String literal) {
+            result += FiqlParser.LE + literal;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition lexicalNotBefore(String literal) {
+            result += FiqlParser.GE + literal;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition notAfter(Date date) {
+            result += FiqlParser.LE + toString(date);
+            return this;
+        }
+
+        @Override
+        public CompleteCondition notBefore(Date date) {
+            result += FiqlParser.GE + toString(date);
+            return this;
+        }
+
+        @Override
+        public CompleteCondition notEqualTo(String literalOrPattern) {
+            result += FiqlParser.NEQ + literalOrPattern;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition notEqualTo(double number) {
+            result += FiqlParser.NEQ + number;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition notEqualTo(Date date) {
+            result += FiqlParser.NEQ + toString(date);
+            return this;
+        }
+
+        @Override
+        public CompleteCondition after(Duration distanceFromNow) {
+            result += FiqlParser.GT + distanceFromNow;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition before(Duration distanceFromNow) {
+            result += FiqlParser.LT + distanceFromNow;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition equalTo(Duration distanceFromNow) {
+            result += FiqlParser.EQ + distanceFromNow;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition notAfter(Duration distanceFromNow) {
+            result += FiqlParser.LE + distanceFromNow;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition notBefore(Duration distanceFromNow) {
+            result += FiqlParser.GE + distanceFromNow;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition notEqualTo(Duration distanceFromNow) {
+            result += FiqlParser.NEQ + distanceFromNow;
+            return this;
+        }
+
+        @Override
+        public PartialCondition and() {
+            result += FiqlParser.AND;
+            return this;
+        }
+
+        @Override
+        public PartialCondition or() {
+            result += FiqlParser.OR;
+            return this;
+        }
+
+        @Override
+        public CompleteCondition and(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn) {
+            result += "(" + ((Builder)c1).buildPartial(this) + FiqlParser.AND
+                      + ((Builder)c2).buildPartial(this);
+            for (CompleteCondition c : cn) {
+                result += FiqlParser.AND + ((Builder)c).buildPartial(this);
+            }
+            result += ")";
+            return this;
+        }
+
+        @Override
+        public CompleteCondition or(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn) {
+            result += "(" + ((Builder)c1).buildPartial(this) + FiqlParser.OR
+                      + ((Builder)c2).buildPartial(this);
+            for (CompleteCondition c : cn) {
+                result += FiqlParser.OR + ((Builder)c).buildPartial(this);
+            }
+            result += ")";
+            return this;
+        }
+
+        @Override
+        public Property is(String property) {
+            Builder b = new Builder(this);
+            b.result = property;
+            return b;
+        }
+
+        private String toString(Date date) {
+            String s = df.format(date);
+            // zone in XML is "+01:00" in Java is "+0100"; adding semicolon
+            int len = s.length();
+            return s.substring(0, len - 2) + ":" + s.substring(len - 2, len);
+        }
+    }
+
+}

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java?rev=1078380&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/client/SearchConditionBuilder.java
Sat Mar  5 22:35:48 2011
@@ -0,0 +1,133 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search.client;
+
+import java.util.Date;
+
+import javax.xml.datatype.Duration;
+
+/**
+ * Builds client-side search condition string using `fluent interface' style. It helps build
create part of
+ * URL that will be parsed by server-side counterpart e.g. FiqlSearchConditionBuilder has
FiqlParser.
+ */
+public interface SearchConditionBuilder {
+
+    /** Creates unconstrained query (no conditions) */
+    PartialCondition query();
+
+    /** Finalize condition construction and build search condition. */
+    String build();
+
+    public interface Property {
+        /** Is textual property equal to given literal or matching given pattern? */
+        CompleteCondition equalTo(String literalOrPattern);
+
+        /** Is numeric property equal to given number? */
+        CompleteCondition equalTo(double number);
+
+        /** Is date property same as given date? */
+        CompleteCondition equalTo(Date date);
+
+        /** Is date property same as date distant from now by given period of time? */
+        CompleteCondition equalTo(Duration distanceFromNow);
+
+        /** Is textual property different than given literal or not matching given pattern?
*/
+        CompleteCondition notEqualTo(String literalOrPattern);
+
+        /** Is numeric property different than given number? */
+        CompleteCondition notEqualTo(double number);
+
+        /** Is date property different than given date? */
+        CompleteCondition notEqualTo(Date date);
+
+        /** Is date property different than date distant from now by given period of time?
*/
+        CompleteCondition notEqualTo(Duration distanceFromNow);
+
+        /** Is numeric property greater than given number? */
+        CompleteCondition greaterThan(double number);
+
+        /** Is numeric property less than given number? */
+        CompleteCondition lessThan(double number);
+
+        /** Is numeric property greater or equal to given number? */
+        CompleteCondition greaterOrEqualTo(double number);
+
+        /** Is numeric property less or equal to given number? */
+        CompleteCondition lessOrEqualTo(double number);
+
+        /** Is date property after (greater than) given date? */
+        CompleteCondition after(Date date);
+
+        /** Is date property before (less than) given date? */
+        CompleteCondition before(Date date);
+
+        /** Is date property not before (greater or equal to) given date? */
+        CompleteCondition notBefore(Date date);
+
+        /** Is date property not after (less or equal to) given date? */
+        CompleteCondition notAfter(Date date);
+
+        /** Is date property after (greater than) date distant from now by given period of
time? */
+        CompleteCondition after(Duration distanceFromNow);
+
+        /** Is date property before (less than) date distant from now by given period of
time? */
+        CompleteCondition before(Duration distanceFromNow);
+
+        /** Is date property not after (less or equal to) date distant from now by given
period of time? */
+        CompleteCondition notAfter(Duration distanceFromNow);
+
+        /** Is date property not before (greater or equal to) date distant from now by given

+         * period of time? */
+        CompleteCondition notBefore(Duration distanceFromNow);
+
+        /** Is textual property lexically after (greater than) given literal? */
+        CompleteCondition lexicalAfter(String literal);
+
+        /** Is textual property lexically before (less than) given literal? */
+        CompleteCondition lexicalBefore(String literal);
+
+        /** Is textual property lexically not before (greater or equal to) given literal?
*/
+        CompleteCondition lexicalNotBefore(String literal);
+
+        /** Is textual property lexically not after (less or equal to) given literal? */
+        CompleteCondition lexicalNotAfter(String literal);
+    }
+    
+    public interface PartialCondition {
+        /** Get property of inspected entity type */
+        Property is(String property);
+
+        /** Conjunct multiple expressions */
+        CompleteCondition and(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn);
+
+        /** Disjunct multiple expressions */
+        CompleteCondition or(CompleteCondition c1, CompleteCondition c2, CompleteCondition...
cn);
+    }
+    
+    public interface CompleteCondition /*extends PartialCondition*/ {
+        /** Conjunct current expression with another */
+        PartialCondition and();
+
+        /** Disjunct current expression with another */
+        PartialCondition or();
+
+        /** Finalize condition construction and build search condition. */
+        String build();
+    }
+}

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java?rev=1078380&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/client/FiqlSearchConditionBuilderTest.java
Sat Mar  5 22:35:48 2011
@@ -0,0 +1,245 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search.client;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+
+import static junit.framework.Assert.assertEquals;
+
+import org.apache.cxf.jaxrs.ext.search.client.SearchConditionBuilder.PartialCondition;
+
+import org.junit.Test;
+
+public class FiqlSearchConditionBuilderTest {
+    private static FiqlSearchConditionBuilder b = new FiqlSearchConditionBuilder();
+
+    @Test
+    public void testEmptyBuild() {
+        assertEquals("", b.build());
+    }
+
+    @Test
+    public void testEqualToString() {
+        String ret = b.query().is("foo").equalTo("literalOrPattern*").build();
+        assertEquals("foo==literalOrPattern*", ret);
+    }
+
+    @Test
+    public void testEqualToNumber() {
+        String ret = b.query().is("foo").equalTo(123.5).build();
+        assertEquals("foo==123.5", ret);
+    }
+
+    @Test
+    public void testEqualToDate() throws ParseException {
+        Date d = SimpleDateFormat.getInstance().parse("01.03.11 12:34");
+        String ret = b.query().is("foo").equalTo(d).build();
+        assertEquals("foo==2011-03-01T12:34:00.000+01:00", ret);
+    }
+
+    @Test
+    public void testEqualToDuration() throws ParseException, DatatypeConfigurationException
{
+        Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

+        String ret = b.query().is("foo").equalTo(d).build();
+        assertEquals("foo==-P0Y0M1DT12H0M0S", ret);
+    }
+
+    @Test
+    public void testNotEqualToString() {
+        String ret = b.query().is("foo").notEqualTo("literalOrPattern*").build();
+        assertEquals("foo!=literalOrPattern*", ret);
+    }
+
+    @Test
+    public void testNotEqualToNumber() {
+        String ret = b.query().is("foo").notEqualTo(123.5).build();
+        assertEquals("foo!=123.5", ret);
+    }
+
+    @Test
+    public void testNotEqualToDate() throws ParseException {
+        Date d = SimpleDateFormat.getInstance().parse("01.03.11 12:34");
+        String ret = b.query().is("foo").notEqualTo(d).build();
+        assertEquals("foo!=2011-03-01T12:34:00.000+01:00", ret);
+    }
+
+    @Test
+    public void testNotEqualToDuration() throws ParseException, DatatypeConfigurationException
{
+        Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

+        String ret = b.query().is("foo").notEqualTo(d).build();
+        assertEquals("foo!=-P0Y0M1DT12H0M0S", ret);
+    }
+
+    @Test
+    public void testGreaterThanString() {
+        String ret = b.query().is("foo").lexicalAfter("abc").build();
+        assertEquals("foo=gt=abc", ret);
+    }
+
+    @Test
+    public void testLessThanString() {
+        String ret = b.query().is("foo").lexicalBefore("abc").build();
+        assertEquals("foo=lt=abc", ret);
+    }
+
+    @Test
+    public void testLessOrEqualToString() {
+        String ret = b.query().is("foo").lexicalNotAfter("abc").build();
+        assertEquals("foo=le=abc", ret);
+    }
+
+    @Test
+    public void testGreaterOrEqualToString() {
+        String ret = b.query().is("foo").lexicalNotBefore("abc").build();
+        assertEquals("foo=ge=abc", ret);
+    }
+    
+    @Test
+    public void testGreaterThanNumber() {
+        String ret = b.query().is("foo").greaterThan(25).build();
+        assertEquals("foo=gt=25.0", ret);
+    }
+
+    @Test
+    public void testLessThanNumber() {
+        String ret = b.query().is("foo").lessThan(25.333).build();
+        assertEquals("foo=lt=25.333", ret);
+    }
+
+    @Test
+    public void testLessOrEqualToNumber() {
+        String ret = b.query().is("foo").lessOrEqualTo(0).build();
+        assertEquals("foo=le=0.0", ret);
+    }
+
+    @Test
+    public void testGreaterOrEqualToNumber() {
+        String ret = b.query().is("foo").greaterOrEqualTo(-5).build();
+        assertEquals("foo=ge=-5.0", ret);
+    }
+
+    @Test
+    public void testGreaterThanDate() throws ParseException {
+        Date d = SimpleDateFormat.getInstance().parse("02.03.11 22:33");
+        String ret = b.query().is("foo").after(d).build();
+        assertEquals("foo=gt=2011-03-02T22:33:00.000+01:00", ret);
+    }
+
+    @Test
+    public void testLessThanDate() throws ParseException {
+        Date d = SimpleDateFormat.getInstance().parse("02.03.11 22:33");
+        String ret = b.query().is("foo").before(d).build();
+        assertEquals("foo=lt=2011-03-02T22:33:00.000+01:00", ret);
+    }
+
+    @Test
+    public void testLessOrEqualToDate() throws ParseException {
+        Date d = SimpleDateFormat.getInstance().parse("02.03.11 22:33");
+        String ret = b.query().is("foo").notAfter(d).build();
+        assertEquals("foo=le=2011-03-02T22:33:00.000+01:00", ret);
+    }
+
+    @Test
+    public void testGreaterOrEqualToDate() throws ParseException {
+        Date d = SimpleDateFormat.getInstance().parse("02.03.11 22:33");
+        String ret = b.query().is("foo").notBefore(d).build();
+        assertEquals("foo=ge=2011-03-02T22:33:00.000+01:00", ret);
+    }
+
+    @Test
+    public void testGreaterThanDuration() throws DatatypeConfigurationException {
+        Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

+        String ret = b.query().is("foo").after(d).build();
+        assertEquals("foo=gt=-P0Y0M1DT12H0M0S", ret);
+    }
+
+    @Test
+    public void testLessThanDuration() throws DatatypeConfigurationException {
+        Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

+        String ret = b.query().is("foo").before(d).build();
+        assertEquals("foo=lt=-P0Y0M1DT12H0M0S", ret);
+    }
+
+    @Test
+    public void testLessOrEqualToDuration() throws DatatypeConfigurationException {
+        Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

+        String ret = b.query().is("foo").notAfter(d).build();
+        assertEquals("foo=le=-P0Y0M1DT12H0M0S", ret);
+    }
+
+    @Test
+    public void testGreaterOrEqualToDuration() throws DatatypeConfigurationException {
+        Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);

+        String ret = b.query().is("foo").notBefore(d).build();
+        assertEquals("foo=ge=-P0Y0M1DT12H0M0S", ret);
+    }
+    
+    @Test
+    public void testOrSimple() {
+        String ret = b.query().is("foo").greaterThan(20).or().is("foo").lessThan(10).build();
+        assertEquals("foo=gt=20.0,foo=lt=10.0", ret);
+    }    
+    
+    @Test
+    public void testAndSimple() {
+        String ret = b.query().is("foo").greaterThan(20).and().is("bar").equalTo("plonk").build();
+        assertEquals("foo=gt=20.0;bar==plonk", ret);
+    }
+    
+    @Test
+    public void testOrComplex() {
+        PartialCondition c = b.query();
+        String ret = c.or(c.is("foo").equalTo("aaa"), c.is("bar").equalTo("bbb")).build();
+        assertEquals("(foo==aaa,bar==bbb)", ret);
+    }    
+
+    @Test
+    public void testAndComplex() {
+        PartialCondition c = b.query();
+        String ret = c.and(c.is("foo").equalTo("aaa"), c.is("bar").equalTo("bbb")).build();
+        assertEquals("(foo==aaa;bar==bbb)", ret);
+    }    
+
+    @Test
+    public void testComplex1() {
+        PartialCondition c = b.query();
+        String ret = c.is("foo").equalTo(123.4).or().and(
+            c.is("bar").equalTo("asadf*"), 
+            c.is("baz").lessThan(20)).build();
+        assertEquals("foo==123.4,(bar==asadf*;baz=lt=20.0)", ret);
+    }
+
+    @Test
+    public void testComplex2() {
+        PartialCondition c = b.query();
+        String ret = c.is("foo").equalTo(123.4).or().is("foo").equalTo("null").and().or(
+            c.is("bar").equalTo("asadf*"), 
+            c.is("baz").lessThan(20).and().or(
+                c.is("sub1").equalTo(0),
+                c.is("sub2").equalTo(0))).build();
+        
+        assertEquals("foo==123.4,foo==null;(bar==asadf*,baz=lt=20.0;(sub1==0.0,sub2==0.0))",
ret);
+    }
+}



Mime
View raw message