You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2011/01/10 23:07:13 UTC
svn commit: r1057393 [2/5] - in /cxf/trunk:
common/common/src/main/java/org/apache/cxf/common/logging/
common/common/src/test/java/org/apache/cxf/staxutils/resources/
distribution/src/main/release/samples/aegis/testSrc/org/apache/cxf/sample/test/
distr...
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java Mon Jan 10 22:07:10 2011
@@ -1,290 +1,290 @@
-/**
- * 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;
-
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-
-import javax.xml.datatype.DatatypeFactory;
-
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-
-public class FiqlParserTest extends Assert {
- private FiqlParser<Condition> parser = new FiqlParser<Condition>(Condition.class);
-
- @Test(expected = FiqlParseException.class)
- public void testCompareWrongComparator() throws FiqlParseException {
- parser.parse("name>booba");
- }
-
- @Test(expected = FiqlParseException.class)
- public void testCompareMissingName() throws FiqlParseException {
- parser.parse("==30");
- }
-
- @Test(expected = FiqlParseException.class)
- public void testCompareMissingValue() throws FiqlParseException {
- parser.parse("name=gt=");
- }
-
- @Test
- public void testCompareValueTextSpaces() throws FiqlParseException {
- parser.parse("name=gt=some text");
- }
-
- @Test(expected = FiqlParseException.class)
- public void testCompareNameTextSpaces() throws FiqlParseException {
- parser.parse("some name=gt=text");
- }
-
- @Test(expected = FiqlParseException.class)
- public void testDanglingOperator() throws FiqlParseException {
- parser.parse("name==a;(level==10;),");
- }
-
- @Test
- public void testMultilevelExpression() throws FiqlParseException {
- parser.parse("name==a;(level==10,(name!=b;name!=c;(level=gt=10)))");
- }
-
- @Test
- public void testMultilevelExpression2() throws FiqlParseException {
- parser.parse("((name==a;level==10),name!=b;name!=c);level=gt=10");
- }
-
- @Test
- public void testRedundantBrackets() throws FiqlParseException {
- parser.parse("name==a;((((level==10))))");
- }
-
- @Test
- public void testAndOfOrs() throws FiqlParseException {
- parser.parse("(name==a,name==b);(level=gt=0,level=lt=10)");
- }
-
- @Test
- public void testOrOfAnds() throws FiqlParseException {
- parser.parse("(name==a;name==b),(level=gt=0;level=lt=10)");
- }
-
- @Test(expected = FiqlParseException.class)
- public void testUnmatchedBracket() throws FiqlParseException {
- parser.parse("name==a;(name!=b;(level==10,(name!=b))");
- }
-
- @Test(expected = FiqlParseException.class)
- public void testUnmatchedBracket2() throws FiqlParseException {
- parser.parse("name==bbb;))()level==111");
- }
-
- @Test(expected = FiqlParseException.class)
- public void testMissingComparison() throws FiqlParseException {
- parser.parse("name==bbb;,level==111");
- }
-
- @Test(expected = FiqlParseException.class)
- public void testSetterMissing() throws FiqlParseException {
- parser.parse("noSuchSetter==xxx");
- }
-
- @Test(expected = FiqlParseException.class)
- public void testSetterWrongType() throws FiqlParseException {
- parser.parse("exception==text");
- }
-
- @Test
- public void testSetterNumericText() throws FiqlParseException {
- parser.parse("name==10");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testMismatchedAccessorTypes() throws FiqlParseException {
- new FiqlParser<MismatchedTypes>(MismatchedTypes.class);
- }
-
- @Test
- public void testParseName() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("name==king");
- assertTrue(filter.isMet(new Condition("king", 10, new Date())));
- assertTrue(filter.isMet(new Condition("king", 0, null)));
- assertFalse(filter.isMet(new Condition("diamond", 10, new Date())));
- assertFalse(filter.isMet(new Condition("diamond", 0, null)));
- }
-
- @Test
- public void testParseLevel() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("level=gt=10");
- assertTrue(filter.isMet(new Condition("whatever", 15, new Date())));
- assertTrue(filter.isMet(new Condition(null, 15, null)));
- assertFalse(filter.isMet(new Condition("blah", 5, new Date())));
- assertFalse(filter.isMet(new Condition("foobar", 0, null)));
- }
-
- @Test
- public void testParseDate() throws FiqlParseException, ParseException {
- SearchCondition<Condition> filter = parser.parse("time=le=2010-03-11T18:00:00.000+00:00");
- DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
- assertTrue(filter.isMet(new Condition("whatever", 15, df.parse("2010-03-11T18:00:00.000+0000"))));
- assertTrue(filter.isMet(new Condition(null, null, df.parse("2010-03-10T22:22:00.000+0000"))));
- assertFalse(filter.isMet(new Condition("blah", null, df.parse("2010-03-12T00:00:00.000+0000"))));
- assertFalse(filter.isMet(new Condition(null, 123, df.parse("2010-03-12T00:00:00.000+0000"))));
- }
-
- @Test
- public void testParseDateDuration() throws Exception {
- SearchCondition<Condition> filter = parser.parse("time=gt=-PT1M");
- Date now = new Date();
- Date tenMinutesAgo = new Date();
- DatatypeFactory.newInstance().newDuration("-PT10M").addTo(tenMinutesAgo);
- assertTrue(filter.isMet(new Condition(null, null, now)));
- assertFalse(filter.isMet(new Condition(null, null, tenMinutesAgo)));
- }
-
- @Test
- public void testParseComplex1() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
- assertTrue(filter.isMet(new Condition("amichalec", 12, new Date())));
- assertTrue(filter.isMet(new Condition("ami", 12, new Date())));
- assertFalse(filter.isMet(new Condition("ami", 8, null)));
- assertFalse(filter.isMet(new Condition("am", 20, null)));
- }
-
- @Test
- public void testSQL1() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
- String sql = filter.toSQL("table");
- assertTrue("SELECT * FROM table WHERE name LIKE 'ami%' AND level > '10'".equals(sql)
- || "SELECT * FROM table WHERE level > '10' AND name LIKE 'ami%'".equals(sql));
- }
-
- @Test
- public void testParseComplex2() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10");
- assertTrue(filter.isMet(new Condition("ami", 0, new Date())));
- assertTrue(filter.isMet(new Condition("foo", 20, null)));
- assertFalse(filter.isMet(new Condition("foo", 0, null)));
- }
-
- @Test
- public void testSQL2() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10");
- String sql = filter.toSQL("table");
- assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') OR (level > '10')".equals(sql)
- || "SELECT * FROM table WHERE (level > '10') OR (name LIKE 'ami%')".equals(sql));
- }
-
- @Test
- public void testParseComplex3() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("name==foo*;(name!=*bar,level=gt=10)");
- assertTrue(filter.isMet(new Condition("fooooo", 0, null)));
- assertTrue(filter.isMet(new Condition("fooooobar", 20, null)));
- assertFalse(filter.isMet(new Condition("fooobar", 0, null)));
- assertFalse(filter.isMet(new Condition("bar", 20, null)));
- }
-
- @Test
- public void testSQL3() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("name==foo*;(name!=*bar,level=gt=10)");
- String sql = filter.toSQL("table");
- assertTrue(("SELECT * FROM table WHERE (name LIKE 'foo%') AND ((name NOT LIKE '%bar') "
- + "OR (level > '10'))").equals(sql)
- || ("SELECT * FROM table WHERE (name LIKE 'foo%') AND "
- + "((level > '10') OR (name NOT LIKE '%bar'))").equals(sql));
- }
-
- @Test
- public void testSQL4() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("(name==test,level==18);(name==test1,level!=19)");
- String sql = filter.toSQL("table");
- assertTrue(("SELECT * FROM table WHERE ((name = 'test') OR (level = '18'))"
- + " AND ((name = 'test1') OR (level <> '19'))").equals(sql)
- || ("SELECT * FROM table WHERE ((name = 'test1') OR (level <> '19'))"
- + " AND ((name = 'test') OR (level = '18'))").equals(sql));
- }
-
- @Test
- public void testParseComplex4() throws FiqlParseException {
- SearchCondition<Condition> filter = parser.parse("name==foo*;name!=*bar,level=gt=10");
- assertTrue(filter.isMet(new Condition("zonk", 20, null)));
- assertTrue(filter.isMet(new Condition("foobaz", 0, null)));
- assertTrue(filter.isMet(new Condition("foobar", 20, null)));
- assertFalse(filter.isMet(new Condition("fooxxxbar", 0, null)));
- }
-
- @Ignore
- static class Condition {
- private String name;
- private Integer level;
- private Date time;
-
- public Condition() {
- }
-
- public Condition(String name, Integer level, Date time) {
- this.name = name;
- this.level = level;
- this.time = time;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public int getLevel() {
- return level;
- }
-
- public void setLevel(int level) {
- this.level = level;
- }
-
- public Date getTime() {
- return time;
- }
-
- public void setTime(Date time) {
- this.time = time;
- }
-
- public void setException(Exception ex) {
- // do nothing
- }
-
- }
-
- // TODO refactor to Beanspector unit tests
- @Ignore
- static class MismatchedTypes {
- public Date getFoo() {
- return null;
- }
-
- public void setFoo(String val) {
- }
- }
-}
+/**
+ * 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;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import javax.xml.datatype.DatatypeFactory;
+
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+
+
+public class FiqlParserTest extends Assert {
+ private FiqlParser<Condition> parser = new FiqlParser<Condition>(Condition.class);
+
+ @Test(expected = FiqlParseException.class)
+ public void testCompareWrongComparator() throws FiqlParseException {
+ parser.parse("name>booba");
+ }
+
+ @Test(expected = FiqlParseException.class)
+ public void testCompareMissingName() throws FiqlParseException {
+ parser.parse("==30");
+ }
+
+ @Test(expected = FiqlParseException.class)
+ public void testCompareMissingValue() throws FiqlParseException {
+ parser.parse("name=gt=");
+ }
+
+ @Test
+ public void testCompareValueTextSpaces() throws FiqlParseException {
+ parser.parse("name=gt=some text");
+ }
+
+ @Test(expected = FiqlParseException.class)
+ public void testCompareNameTextSpaces() throws FiqlParseException {
+ parser.parse("some name=gt=text");
+ }
+
+ @Test(expected = FiqlParseException.class)
+ public void testDanglingOperator() throws FiqlParseException {
+ parser.parse("name==a;(level==10;),");
+ }
+
+ @Test
+ public void testMultilevelExpression() throws FiqlParseException {
+ parser.parse("name==a;(level==10,(name!=b;name!=c;(level=gt=10)))");
+ }
+
+ @Test
+ public void testMultilevelExpression2() throws FiqlParseException {
+ parser.parse("((name==a;level==10),name!=b;name!=c);level=gt=10");
+ }
+
+ @Test
+ public void testRedundantBrackets() throws FiqlParseException {
+ parser.parse("name==a;((((level==10))))");
+ }
+
+ @Test
+ public void testAndOfOrs() throws FiqlParseException {
+ parser.parse("(name==a,name==b);(level=gt=0,level=lt=10)");
+ }
+
+ @Test
+ public void testOrOfAnds() throws FiqlParseException {
+ parser.parse("(name==a;name==b),(level=gt=0;level=lt=10)");
+ }
+
+ @Test(expected = FiqlParseException.class)
+ public void testUnmatchedBracket() throws FiqlParseException {
+ parser.parse("name==a;(name!=b;(level==10,(name!=b))");
+ }
+
+ @Test(expected = FiqlParseException.class)
+ public void testUnmatchedBracket2() throws FiqlParseException {
+ parser.parse("name==bbb;))()level==111");
+ }
+
+ @Test(expected = FiqlParseException.class)
+ public void testMissingComparison() throws FiqlParseException {
+ parser.parse("name==bbb;,level==111");
+ }
+
+ @Test(expected = FiqlParseException.class)
+ public void testSetterMissing() throws FiqlParseException {
+ parser.parse("noSuchSetter==xxx");
+ }
+
+ @Test(expected = FiqlParseException.class)
+ public void testSetterWrongType() throws FiqlParseException {
+ parser.parse("exception==text");
+ }
+
+ @Test
+ public void testSetterNumericText() throws FiqlParseException {
+ parser.parse("name==10");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testMismatchedAccessorTypes() throws FiqlParseException {
+ new FiqlParser<MismatchedTypes>(MismatchedTypes.class);
+ }
+
+ @Test
+ public void testParseName() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("name==king");
+ assertTrue(filter.isMet(new Condition("king", 10, new Date())));
+ assertTrue(filter.isMet(new Condition("king", 0, null)));
+ assertFalse(filter.isMet(new Condition("diamond", 10, new Date())));
+ assertFalse(filter.isMet(new Condition("diamond", 0, null)));
+ }
+
+ @Test
+ public void testParseLevel() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("level=gt=10");
+ assertTrue(filter.isMet(new Condition("whatever", 15, new Date())));
+ assertTrue(filter.isMet(new Condition(null, 15, null)));
+ assertFalse(filter.isMet(new Condition("blah", 5, new Date())));
+ assertFalse(filter.isMet(new Condition("foobar", 0, null)));
+ }
+
+ @Test
+ public void testParseDate() throws FiqlParseException, ParseException {
+ SearchCondition<Condition> filter = parser.parse("time=le=2010-03-11T18:00:00.000+00:00");
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+ assertTrue(filter.isMet(new Condition("whatever", 15, df.parse("2010-03-11T18:00:00.000+0000"))));
+ assertTrue(filter.isMet(new Condition(null, null, df.parse("2010-03-10T22:22:00.000+0000"))));
+ assertFalse(filter.isMet(new Condition("blah", null, df.parse("2010-03-12T00:00:00.000+0000"))));
+ assertFalse(filter.isMet(new Condition(null, 123, df.parse("2010-03-12T00:00:00.000+0000"))));
+ }
+
+ @Test
+ public void testParseDateDuration() throws Exception {
+ SearchCondition<Condition> filter = parser.parse("time=gt=-PT1M");
+ Date now = new Date();
+ Date tenMinutesAgo = new Date();
+ DatatypeFactory.newInstance().newDuration("-PT10M").addTo(tenMinutesAgo);
+ assertTrue(filter.isMet(new Condition(null, null, now)));
+ assertFalse(filter.isMet(new Condition(null, null, tenMinutesAgo)));
+ }
+
+ @Test
+ public void testParseComplex1() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
+ assertTrue(filter.isMet(new Condition("amichalec", 12, new Date())));
+ assertTrue(filter.isMet(new Condition("ami", 12, new Date())));
+ assertFalse(filter.isMet(new Condition("ami", 8, null)));
+ assertFalse(filter.isMet(new Condition("am", 20, null)));
+ }
+
+ @Test
+ public void testSQL1() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
+ String sql = filter.toSQL("table");
+ assertTrue("SELECT * FROM table WHERE name LIKE 'ami%' AND level > '10'".equals(sql)
+ || "SELECT * FROM table WHERE level > '10' AND name LIKE 'ami%'".equals(sql));
+ }
+
+ @Test
+ public void testParseComplex2() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10");
+ assertTrue(filter.isMet(new Condition("ami", 0, new Date())));
+ assertTrue(filter.isMet(new Condition("foo", 20, null)));
+ assertFalse(filter.isMet(new Condition("foo", 0, null)));
+ }
+
+ @Test
+ public void testSQL2() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10");
+ String sql = filter.toSQL("table");
+ assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') OR (level > '10')".equals(sql)
+ || "SELECT * FROM table WHERE (level > '10') OR (name LIKE 'ami%')".equals(sql));
+ }
+
+ @Test
+ public void testParseComplex3() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("name==foo*;(name!=*bar,level=gt=10)");
+ assertTrue(filter.isMet(new Condition("fooooo", 0, null)));
+ assertTrue(filter.isMet(new Condition("fooooobar", 20, null)));
+ assertFalse(filter.isMet(new Condition("fooobar", 0, null)));
+ assertFalse(filter.isMet(new Condition("bar", 20, null)));
+ }
+
+ @Test
+ public void testSQL3() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("name==foo*;(name!=*bar,level=gt=10)");
+ String sql = filter.toSQL("table");
+ assertTrue(("SELECT * FROM table WHERE (name LIKE 'foo%') AND ((name NOT LIKE '%bar') "
+ + "OR (level > '10'))").equals(sql)
+ || ("SELECT * FROM table WHERE (name LIKE 'foo%') AND "
+ + "((level > '10') OR (name NOT LIKE '%bar'))").equals(sql));
+ }
+
+ @Test
+ public void testSQL4() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("(name==test,level==18);(name==test1,level!=19)");
+ String sql = filter.toSQL("table");
+ assertTrue(("SELECT * FROM table WHERE ((name = 'test') OR (level = '18'))"
+ + " AND ((name = 'test1') OR (level <> '19'))").equals(sql)
+ || ("SELECT * FROM table WHERE ((name = 'test1') OR (level <> '19'))"
+ + " AND ((name = 'test') OR (level = '18'))").equals(sql));
+ }
+
+ @Test
+ public void testParseComplex4() throws FiqlParseException {
+ SearchCondition<Condition> filter = parser.parse("name==foo*;name!=*bar,level=gt=10");
+ assertTrue(filter.isMet(new Condition("zonk", 20, null)));
+ assertTrue(filter.isMet(new Condition("foobaz", 0, null)));
+ assertTrue(filter.isMet(new Condition("foobar", 20, null)));
+ assertFalse(filter.isMet(new Condition("fooxxxbar", 0, null)));
+ }
+
+ @Ignore
+ static class Condition {
+ private String name;
+ private Integer level;
+ private Date time;
+
+ public Condition() {
+ }
+
+ public Condition(String name, Integer level, Date time) {
+ this.name = name;
+ this.level = level;
+ this.time = time;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getLevel() {
+ return level;
+ }
+
+ public void setLevel(int level) {
+ this.level = level;
+ }
+
+ public Date getTime() {
+ return time;
+ }
+
+ public void setTime(Date time) {
+ this.time = time;
+ }
+
+ public void setException(Exception ex) {
+ // do nothing
+ }
+
+ }
+
+ // TODO refactor to Beanspector unit tests
+ @Ignore
+ static class MismatchedTypes {
+ public Date getFoo() {
+ return null;
+ }
+
+ public void setFoo(String val) {
+ }
+ }
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchConditionTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchConditionTest.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchConditionTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchConditionTest.java Mon Jan 10 22:07:10 2011
@@ -1,371 +1,371 @@
-/**
- * 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;
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-public class SimpleSearchConditionTest {
-
- private static SearchCondition<SingleAttr> cEq;
- private static SearchCondition<SingleAttr> cGt;
- private static SearchCondition<SingleAttr> cGeq;
- private static SearchCondition<SingleAttr> cLt;
- private static SearchCondition<SingleAttr> cLeq;
-
- private static SingleAttr attr = new SingleAttr("bbb");
- private static SingleAttr attrGreater = new SingleAttr("ccc");
- private static SingleAttr attrLesser = new SingleAttr("aaa");
-
- // TODO 1. comparison with multiple values
- // TODO 2. comparison when getter returns null/throws exception
- private static DoubleAttr attr2Vals = new DoubleAttr("bbb", "ccc");
- private static DoubleAttr attr2ValsGreater = new DoubleAttr("ccc", "ddd");
- private static DoubleAttr attr2ValsLesser = new DoubleAttr("aaa", "bbb");
-
- private static DoubleAttr attr1Val = new DoubleAttr("bbb", null);
- private static DoubleAttr attr1ValGreater = new DoubleAttr("ccc", "ingored");
- private static DoubleAttr attr1ValLesser = new DoubleAttr("aaa", "ingored");
-
- private static SearchCondition<DoubleAttr> dc1Eq;
- private static SearchCondition<DoubleAttr> dc1Gt;
- private static SearchCondition<DoubleAttr> dc1Geq;
- private static SearchCondition<DoubleAttr> dc1Lt;
- private static SearchCondition<DoubleAttr> dc1Leq;
-
- private static SearchCondition<DoubleAttr> dc2Eq;
- private static SearchCondition<DoubleAttr> dc2Gt;
- private static SearchCondition<DoubleAttr> dc2Geq;
- private static SearchCondition<DoubleAttr> dc2Lt;
- private static SearchCondition<DoubleAttr> dc2Leq;
-
- private static List<ConditionType> supported = Arrays.asList(ConditionType.EQUALS,
- ConditionType.NOT_EQUALS,
- ConditionType.GREATER_OR_EQUALS,
- ConditionType.GREATER_THAN,
- ConditionType.LESS_OR_EQUALS,
- ConditionType.LESS_THAN);
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- cEq = new SimpleSearchCondition<SingleAttr>(ConditionType.EQUALS, attr);
- cGt = new SimpleSearchCondition<SingleAttr>(ConditionType.GREATER_THAN, attr);
- cGeq = new SimpleSearchCondition<SingleAttr>(ConditionType.GREATER_OR_EQUALS, attr);
- cLt = new SimpleSearchCondition<SingleAttr>(ConditionType.LESS_THAN, attr);
- cLeq = new SimpleSearchCondition<SingleAttr>(ConditionType.LESS_OR_EQUALS, attr);
-
- dc1Eq = new SimpleSearchCondition<DoubleAttr>(ConditionType.EQUALS, attr1Val);
- dc1Gt = new SimpleSearchCondition<DoubleAttr>(ConditionType.GREATER_THAN, attr1Val);
- dc1Geq = new SimpleSearchCondition<DoubleAttr>(ConditionType.GREATER_OR_EQUALS, attr1Val);
- dc1Lt = new SimpleSearchCondition<DoubleAttr>(ConditionType.LESS_THAN, attr1Val);
- dc1Leq = new SimpleSearchCondition<DoubleAttr>(ConditionType.LESS_OR_EQUALS, attr1Val);
-
- dc2Eq = new SimpleSearchCondition<DoubleAttr>(ConditionType.EQUALS, attr2Vals);
- dc2Gt = new SimpleSearchCondition<DoubleAttr>(ConditionType.GREATER_THAN, attr2Vals);
- dc2Geq = new SimpleSearchCondition<DoubleAttr>(ConditionType.GREATER_OR_EQUALS, attr2Vals);
- dc2Lt = new SimpleSearchCondition<DoubleAttr>(ConditionType.LESS_THAN, attr2Vals);
- dc2Leq = new SimpleSearchCondition<DoubleAttr>(ConditionType.LESS_OR_EQUALS, attr2Vals);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testCtorNull1() {
- new SimpleSearchCondition<SingleAttr>((ConditionType)null, attr);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testCtorNull2() {
- new SimpleSearchCondition<SingleAttr>(ConditionType.LESS_THAN, null);
- }
-
- @Test
- public void testCtorCondSupported() {
- for (ConditionType ct : ConditionType.values()) {
- try {
- new SimpleSearchCondition<SingleAttr>(ct, attr);
- if (!supported.contains(ct)) {
- fail(String.format("Not supported type %s should throw exception", ct.name()));
- }
- } catch (IllegalArgumentException e) {
- if (supported.contains(ct)) {
- fail(String.format("Supported type %s should not throw exception", ct.name()));
- }
- }
- }
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testCtorMapNull() {
- new SimpleSearchCondition<SingleAttr>((Map<String, ConditionType>)null, attr);
- }
-
- @Test
- public void testCtorMapCondSupported() {
- for (ConditionType ct : ConditionType.values()) {
- try {
- Map<String, ConditionType> map = new HashMap<String, ConditionType>();
- map.put("foo", ct);
- new SimpleSearchCondition<SingleAttr>(map, attr);
- if (!supported.contains(ct)) {
- fail(String.format("Not supported type %s should throw exception", ct.name()));
- }
- } catch (IllegalArgumentException e) {
- if (supported.contains(ct)) {
- fail(String.format("Supported type %s should not throw exception", ct.name()));
- }
- }
- }
- }
-
- @Test
- public void testGetCondition() {
- assertEquals(cLeq.getCondition(), attr);
- }
-
- @Test
- public void testGetConditionType() {
- assertEquals(cEq.getConditionType(), ConditionType.EQUALS);
- assertEquals(cLt.getConditionType(), ConditionType.LESS_THAN);
- }
-
- @Test
- public void testGetConditions() {
- assertEquals(cGt.getSearchConditions(), null);
- }
-
- @Test
- public void testIsMetEq() {
- assertTrue(cEq.isMet(attr));
- assertFalse(cEq.isMet(attrGreater));
- }
-
- @Test
- public void testIsMetGt() {
- assertTrue(cGt.isMet(attrGreater));
- assertFalse(cGt.isMet(attr));
- assertFalse(cGt.isMet(attrLesser));
- }
-
- @Test
- public void testIsMetGeq() {
- assertTrue(cGeq.isMet(attrGreater));
- assertTrue(cGeq.isMet(attr));
- assertFalse(cGeq.isMet(attrLesser));
- }
-
- @Test
- public void testIsMetLt() {
- assertFalse(cLt.isMet(attrGreater));
- assertFalse(cLt.isMet(attr));
- assertTrue(cLt.isMet(attrLesser));
- }
-
- @Test
- public void testIsMetLeq() {
- assertFalse(cLeq.isMet(attrGreater));
- assertTrue(cLeq.isMet(attr));
- assertTrue(cLeq.isMet(attrLesser));
- }
-
- @Test
- public void testIsMetEqPrimitive() {
- assertTrue(new SimpleSearchCondition<String>(ConditionType.EQUALS, "foo").isMet("foo"));
- }
-
- @Test
- public void testIsMetGtPrimitive() {
- assertTrue(new SimpleSearchCondition<Float>(ConditionType.GREATER_THAN, 1.5f).isMet(2.5f));
- }
-
- @Test
- public void testIsMetLtPrimitive() {
- assertTrue(new SimpleSearchCondition<Integer>(ConditionType.LESS_THAN, 10).isMet(5));
- }
-
- @Test
- public void testFindAll() {
- List<SingleAttr> inputs = Arrays.asList(attr, attrGreater, attrLesser);
- List<SingleAttr> found = Arrays.asList(attr, attrGreater);
- assertEquals(found, cGeq.findAll(inputs));
- }
-
- @Test
- public void testIsMetEqDouble1Val() {
- assertFalse(dc1Eq.isMet(attr1ValGreater));
- assertTrue(dc1Eq.isMet(attr1Val));
- assertFalse(dc1Eq.isMet(attr1ValLesser));
- }
-
- @Test
- public void testIsMetGtDouble1Val() {
- assertTrue(dc1Gt.isMet(attr1ValGreater));
- assertFalse(dc1Gt.isMet(attr1Val));
- assertFalse(dc1Gt.isMet(attr1ValLesser));
- }
-
- @Test
- public void testIsMetGeqDouble1Val() {
- assertTrue(dc1Geq.isMet(attr1ValGreater));
- assertTrue(dc1Geq.isMet(attr1Val));
- assertFalse(dc1Geq.isMet(attr1ValLesser));
- }
-
- @Test
- public void testIsMetLtDouble1Val() {
- assertFalse(dc1Lt.isMet(attr1ValGreater));
- assertFalse(dc1Lt.isMet(attr1Val));
- assertTrue(dc1Lt.isMet(attr1ValLesser));
- }
-
- @Test
- public void testIsMetLeqDouble1Val() {
- assertFalse(dc1Leq.isMet(attr1ValGreater));
- assertTrue(dc1Leq.isMet(attr1Val));
- assertTrue(dc1Leq.isMet(attr1ValLesser));
- }
-
- @Test
- public void testIsMetEqDouble2Vals() {
- assertFalse(dc2Eq.isMet(attr2ValsGreater));
- assertTrue(dc2Eq.isMet(attr2Vals));
- assertFalse(dc2Eq.isMet(attr2ValsLesser));
- }
-
- @Test
- public void testIsMetGtDouble2Vals() {
- assertTrue(dc2Gt.isMet(attr2ValsGreater));
- assertFalse(dc2Gt.isMet(attr2Vals));
- assertFalse(dc2Gt.isMet(attr2ValsLesser));
- }
-
- @Test
- public void testIsMetGeqDouble2Vals() {
- assertTrue(dc2Geq.isMet(attr2ValsGreater));
- assertTrue(dc2Geq.isMet(attr2Vals));
- assertFalse(dc2Geq.isMet(attr2ValsLesser));
- }
-
- @Test
- public void testIsMetLtDouble2Vals() {
- assertFalse(dc2Lt.isMet(attr2ValsGreater));
- assertFalse(dc2Lt.isMet(attr2Vals));
- assertTrue(dc2Lt.isMet(attr2ValsLesser));
- }
-
- @Test
- public void testIsMetLeqDouble2Vals() {
- assertFalse(dc2Leq.isMet(attr2ValsGreater));
- assertTrue(dc2Leq.isMet(attr2Vals));
- assertTrue(dc2Leq.isMet(attr2ValsLesser));
- }
-
- @Test
- public void testIsMetMappedOperators() {
- Map<String, ConditionType> map = new HashMap<String, ConditionType>();
- map.put("foo", ConditionType.LESS_THAN);
- map.put("bar", ConditionType.GREATER_THAN);
-
- // expression "template.getFoo() < pojo.getFoo() & template.getBar() > pojo.getBar()"
- assertTrue(new SimpleSearchCondition<DoubleAttr>(map, new DoubleAttr("bbb", "ccc"))
- .isMet(new DoubleAttr("aaa", "ddd")));
-
- // expression "template.getBar() > pojo.getBar()"
- assertTrue(new SimpleSearchCondition<DoubleAttr>(map, new DoubleAttr(null, "ccc"))
- .isMet(new DoubleAttr("!not-interpreted!", "ddd")));
- }
-
- @Test
- public void testIsMetWildcardEnds() {
- SimpleSearchCondition<String> ssc = new SimpleSearchCondition<String>(ConditionType.EQUALS, "bar*");
- assertTrue(ssc.isMet("bar"));
- assertTrue(ssc.isMet("barbaz"));
- assertFalse(ssc.isMet("foobar"));
- }
-
- @Test
- public void testIsMetWildcardStarts() {
- SimpleSearchCondition<String> ssc = new SimpleSearchCondition<String>(ConditionType.EQUALS, "*bar");
- assertTrue(ssc.isMet("bar"));
- assertFalse(ssc.isMet("barbaz"));
- assertTrue(ssc.isMet("foobar"));
- }
-
- @Test
- public void testIsMetWildcardStartsEnds() {
- SimpleSearchCondition<String> ssc = new SimpleSearchCondition<String>(ConditionType.EQUALS, "*bar*");
- assertTrue(ssc.isMet("bar"));
- assertTrue(ssc.isMet("barbaz"));
- assertTrue(ssc.isMet("foobar"));
- }
-
- @Test
- public void testIsMetWildcardMultiAsterisk() {
- SimpleSearchCondition<String> ssc = new SimpleSearchCondition<String>(ConditionType.EQUALS, "*ba*r*");
- assertFalse(ssc.isMet("bar"));
- assertTrue(ssc.isMet("ba*r"));
- assertTrue(ssc.isMet("fooba*r"));
- assertTrue(ssc.isMet("fooba*rbaz"));
- assertFalse(ssc.isMet("foobarbaz"));
- }
-
- static class SingleAttr {
- private String foo;
-
- public SingleAttr(String foo) {
- this.foo = foo;
- }
-
- public String getFoo() {
- return foo;
- }
-
- // this should not be used by "isMet" (is not public)
- @SuppressWarnings("unused")
- private String getBar() {
- return "it's private!";
- }
- }
-
- static class DoubleAttr {
- private String foo;
- private String bar;
-
- public DoubleAttr(String foo, String bar) {
- this.foo = foo;
- this.bar = bar;
- }
-
- public String getFoo() {
- return foo;
- }
-
- public String getBar() {
- return bar;
- }
- }
-}
+/**
+ * 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;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class SimpleSearchConditionTest {
+
+ private static SearchCondition<SingleAttr> cEq;
+ private static SearchCondition<SingleAttr> cGt;
+ private static SearchCondition<SingleAttr> cGeq;
+ private static SearchCondition<SingleAttr> cLt;
+ private static SearchCondition<SingleAttr> cLeq;
+
+ private static SingleAttr attr = new SingleAttr("bbb");
+ private static SingleAttr attrGreater = new SingleAttr("ccc");
+ private static SingleAttr attrLesser = new SingleAttr("aaa");
+
+ // TODO 1. comparison with multiple values
+ // TODO 2. comparison when getter returns null/throws exception
+ private static DoubleAttr attr2Vals = new DoubleAttr("bbb", "ccc");
+ private static DoubleAttr attr2ValsGreater = new DoubleAttr("ccc", "ddd");
+ private static DoubleAttr attr2ValsLesser = new DoubleAttr("aaa", "bbb");
+
+ private static DoubleAttr attr1Val = new DoubleAttr("bbb", null);
+ private static DoubleAttr attr1ValGreater = new DoubleAttr("ccc", "ingored");
+ private static DoubleAttr attr1ValLesser = new DoubleAttr("aaa", "ingored");
+
+ private static SearchCondition<DoubleAttr> dc1Eq;
+ private static SearchCondition<DoubleAttr> dc1Gt;
+ private static SearchCondition<DoubleAttr> dc1Geq;
+ private static SearchCondition<DoubleAttr> dc1Lt;
+ private static SearchCondition<DoubleAttr> dc1Leq;
+
+ private static SearchCondition<DoubleAttr> dc2Eq;
+ private static SearchCondition<DoubleAttr> dc2Gt;
+ private static SearchCondition<DoubleAttr> dc2Geq;
+ private static SearchCondition<DoubleAttr> dc2Lt;
+ private static SearchCondition<DoubleAttr> dc2Leq;
+
+ private static List<ConditionType> supported = Arrays.asList(ConditionType.EQUALS,
+ ConditionType.NOT_EQUALS,
+ ConditionType.GREATER_OR_EQUALS,
+ ConditionType.GREATER_THAN,
+ ConditionType.LESS_OR_EQUALS,
+ ConditionType.LESS_THAN);
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ cEq = new SimpleSearchCondition<SingleAttr>(ConditionType.EQUALS, attr);
+ cGt = new SimpleSearchCondition<SingleAttr>(ConditionType.GREATER_THAN, attr);
+ cGeq = new SimpleSearchCondition<SingleAttr>(ConditionType.GREATER_OR_EQUALS, attr);
+ cLt = new SimpleSearchCondition<SingleAttr>(ConditionType.LESS_THAN, attr);
+ cLeq = new SimpleSearchCondition<SingleAttr>(ConditionType.LESS_OR_EQUALS, attr);
+
+ dc1Eq = new SimpleSearchCondition<DoubleAttr>(ConditionType.EQUALS, attr1Val);
+ dc1Gt = new SimpleSearchCondition<DoubleAttr>(ConditionType.GREATER_THAN, attr1Val);
+ dc1Geq = new SimpleSearchCondition<DoubleAttr>(ConditionType.GREATER_OR_EQUALS, attr1Val);
+ dc1Lt = new SimpleSearchCondition<DoubleAttr>(ConditionType.LESS_THAN, attr1Val);
+ dc1Leq = new SimpleSearchCondition<DoubleAttr>(ConditionType.LESS_OR_EQUALS, attr1Val);
+
+ dc2Eq = new SimpleSearchCondition<DoubleAttr>(ConditionType.EQUALS, attr2Vals);
+ dc2Gt = new SimpleSearchCondition<DoubleAttr>(ConditionType.GREATER_THAN, attr2Vals);
+ dc2Geq = new SimpleSearchCondition<DoubleAttr>(ConditionType.GREATER_OR_EQUALS, attr2Vals);
+ dc2Lt = new SimpleSearchCondition<DoubleAttr>(ConditionType.LESS_THAN, attr2Vals);
+ dc2Leq = new SimpleSearchCondition<DoubleAttr>(ConditionType.LESS_OR_EQUALS, attr2Vals);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCtorNull1() {
+ new SimpleSearchCondition<SingleAttr>((ConditionType)null, attr);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCtorNull2() {
+ new SimpleSearchCondition<SingleAttr>(ConditionType.LESS_THAN, null);
+ }
+
+ @Test
+ public void testCtorCondSupported() {
+ for (ConditionType ct : ConditionType.values()) {
+ try {
+ new SimpleSearchCondition<SingleAttr>(ct, attr);
+ if (!supported.contains(ct)) {
+ fail(String.format("Not supported type %s should throw exception", ct.name()));
+ }
+ } catch (IllegalArgumentException e) {
+ if (supported.contains(ct)) {
+ fail(String.format("Supported type %s should not throw exception", ct.name()));
+ }
+ }
+ }
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testCtorMapNull() {
+ new SimpleSearchCondition<SingleAttr>((Map<String, ConditionType>)null, attr);
+ }
+
+ @Test
+ public void testCtorMapCondSupported() {
+ for (ConditionType ct : ConditionType.values()) {
+ try {
+ Map<String, ConditionType> map = new HashMap<String, ConditionType>();
+ map.put("foo", ct);
+ new SimpleSearchCondition<SingleAttr>(map, attr);
+ if (!supported.contains(ct)) {
+ fail(String.format("Not supported type %s should throw exception", ct.name()));
+ }
+ } catch (IllegalArgumentException e) {
+ if (supported.contains(ct)) {
+ fail(String.format("Supported type %s should not throw exception", ct.name()));
+ }
+ }
+ }
+ }
+
+ @Test
+ public void testGetCondition() {
+ assertEquals(cLeq.getCondition(), attr);
+ }
+
+ @Test
+ public void testGetConditionType() {
+ assertEquals(cEq.getConditionType(), ConditionType.EQUALS);
+ assertEquals(cLt.getConditionType(), ConditionType.LESS_THAN);
+ }
+
+ @Test
+ public void testGetConditions() {
+ assertEquals(cGt.getSearchConditions(), null);
+ }
+
+ @Test
+ public void testIsMetEq() {
+ assertTrue(cEq.isMet(attr));
+ assertFalse(cEq.isMet(attrGreater));
+ }
+
+ @Test
+ public void testIsMetGt() {
+ assertTrue(cGt.isMet(attrGreater));
+ assertFalse(cGt.isMet(attr));
+ assertFalse(cGt.isMet(attrLesser));
+ }
+
+ @Test
+ public void testIsMetGeq() {
+ assertTrue(cGeq.isMet(attrGreater));
+ assertTrue(cGeq.isMet(attr));
+ assertFalse(cGeq.isMet(attrLesser));
+ }
+
+ @Test
+ public void testIsMetLt() {
+ assertFalse(cLt.isMet(attrGreater));
+ assertFalse(cLt.isMet(attr));
+ assertTrue(cLt.isMet(attrLesser));
+ }
+
+ @Test
+ public void testIsMetLeq() {
+ assertFalse(cLeq.isMet(attrGreater));
+ assertTrue(cLeq.isMet(attr));
+ assertTrue(cLeq.isMet(attrLesser));
+ }
+
+ @Test
+ public void testIsMetEqPrimitive() {
+ assertTrue(new SimpleSearchCondition<String>(ConditionType.EQUALS, "foo").isMet("foo"));
+ }
+
+ @Test
+ public void testIsMetGtPrimitive() {
+ assertTrue(new SimpleSearchCondition<Float>(ConditionType.GREATER_THAN, 1.5f).isMet(2.5f));
+ }
+
+ @Test
+ public void testIsMetLtPrimitive() {
+ assertTrue(new SimpleSearchCondition<Integer>(ConditionType.LESS_THAN, 10).isMet(5));
+ }
+
+ @Test
+ public void testFindAll() {
+ List<SingleAttr> inputs = Arrays.asList(attr, attrGreater, attrLesser);
+ List<SingleAttr> found = Arrays.asList(attr, attrGreater);
+ assertEquals(found, cGeq.findAll(inputs));
+ }
+
+ @Test
+ public void testIsMetEqDouble1Val() {
+ assertFalse(dc1Eq.isMet(attr1ValGreater));
+ assertTrue(dc1Eq.isMet(attr1Val));
+ assertFalse(dc1Eq.isMet(attr1ValLesser));
+ }
+
+ @Test
+ public void testIsMetGtDouble1Val() {
+ assertTrue(dc1Gt.isMet(attr1ValGreater));
+ assertFalse(dc1Gt.isMet(attr1Val));
+ assertFalse(dc1Gt.isMet(attr1ValLesser));
+ }
+
+ @Test
+ public void testIsMetGeqDouble1Val() {
+ assertTrue(dc1Geq.isMet(attr1ValGreater));
+ assertTrue(dc1Geq.isMet(attr1Val));
+ assertFalse(dc1Geq.isMet(attr1ValLesser));
+ }
+
+ @Test
+ public void testIsMetLtDouble1Val() {
+ assertFalse(dc1Lt.isMet(attr1ValGreater));
+ assertFalse(dc1Lt.isMet(attr1Val));
+ assertTrue(dc1Lt.isMet(attr1ValLesser));
+ }
+
+ @Test
+ public void testIsMetLeqDouble1Val() {
+ assertFalse(dc1Leq.isMet(attr1ValGreater));
+ assertTrue(dc1Leq.isMet(attr1Val));
+ assertTrue(dc1Leq.isMet(attr1ValLesser));
+ }
+
+ @Test
+ public void testIsMetEqDouble2Vals() {
+ assertFalse(dc2Eq.isMet(attr2ValsGreater));
+ assertTrue(dc2Eq.isMet(attr2Vals));
+ assertFalse(dc2Eq.isMet(attr2ValsLesser));
+ }
+
+ @Test
+ public void testIsMetGtDouble2Vals() {
+ assertTrue(dc2Gt.isMet(attr2ValsGreater));
+ assertFalse(dc2Gt.isMet(attr2Vals));
+ assertFalse(dc2Gt.isMet(attr2ValsLesser));
+ }
+
+ @Test
+ public void testIsMetGeqDouble2Vals() {
+ assertTrue(dc2Geq.isMet(attr2ValsGreater));
+ assertTrue(dc2Geq.isMet(attr2Vals));
+ assertFalse(dc2Geq.isMet(attr2ValsLesser));
+ }
+
+ @Test
+ public void testIsMetLtDouble2Vals() {
+ assertFalse(dc2Lt.isMet(attr2ValsGreater));
+ assertFalse(dc2Lt.isMet(attr2Vals));
+ assertTrue(dc2Lt.isMet(attr2ValsLesser));
+ }
+
+ @Test
+ public void testIsMetLeqDouble2Vals() {
+ assertFalse(dc2Leq.isMet(attr2ValsGreater));
+ assertTrue(dc2Leq.isMet(attr2Vals));
+ assertTrue(dc2Leq.isMet(attr2ValsLesser));
+ }
+
+ @Test
+ public void testIsMetMappedOperators() {
+ Map<String, ConditionType> map = new HashMap<String, ConditionType>();
+ map.put("foo", ConditionType.LESS_THAN);
+ map.put("bar", ConditionType.GREATER_THAN);
+
+ // expression "template.getFoo() < pojo.getFoo() & template.getBar() > pojo.getBar()"
+ assertTrue(new SimpleSearchCondition<DoubleAttr>(map, new DoubleAttr("bbb", "ccc"))
+ .isMet(new DoubleAttr("aaa", "ddd")));
+
+ // expression "template.getBar() > pojo.getBar()"
+ assertTrue(new SimpleSearchCondition<DoubleAttr>(map, new DoubleAttr(null, "ccc"))
+ .isMet(new DoubleAttr("!not-interpreted!", "ddd")));
+ }
+
+ @Test
+ public void testIsMetWildcardEnds() {
+ SimpleSearchCondition<String> ssc = new SimpleSearchCondition<String>(ConditionType.EQUALS, "bar*");
+ assertTrue(ssc.isMet("bar"));
+ assertTrue(ssc.isMet("barbaz"));
+ assertFalse(ssc.isMet("foobar"));
+ }
+
+ @Test
+ public void testIsMetWildcardStarts() {
+ SimpleSearchCondition<String> ssc = new SimpleSearchCondition<String>(ConditionType.EQUALS, "*bar");
+ assertTrue(ssc.isMet("bar"));
+ assertFalse(ssc.isMet("barbaz"));
+ assertTrue(ssc.isMet("foobar"));
+ }
+
+ @Test
+ public void testIsMetWildcardStartsEnds() {
+ SimpleSearchCondition<String> ssc = new SimpleSearchCondition<String>(ConditionType.EQUALS, "*bar*");
+ assertTrue(ssc.isMet("bar"));
+ assertTrue(ssc.isMet("barbaz"));
+ assertTrue(ssc.isMet("foobar"));
+ }
+
+ @Test
+ public void testIsMetWildcardMultiAsterisk() {
+ SimpleSearchCondition<String> ssc = new SimpleSearchCondition<String>(ConditionType.EQUALS, "*ba*r*");
+ assertFalse(ssc.isMet("bar"));
+ assertTrue(ssc.isMet("ba*r"));
+ assertTrue(ssc.isMet("fooba*r"));
+ assertTrue(ssc.isMet("fooba*rbaz"));
+ assertFalse(ssc.isMet("foobarbaz"));
+ }
+
+ static class SingleAttr {
+ private String foo;
+
+ public SingleAttr(String foo) {
+ this.foo = foo;
+ }
+
+ public String getFoo() {
+ return foo;
+ }
+
+ // this should not be used by "isMet" (is not public)
+ @SuppressWarnings("unused")
+ private String getBar() {
+ return "it's private!";
+ }
+ }
+
+ static class DoubleAttr {
+ private String foo;
+ private String bar;
+
+ public DoubleAttr(String foo, String bar) {
+ this.foo = foo;
+ this.bar = bar;
+ }
+
+ public String getFoo() {
+ return foo;
+ }
+
+ public String getBar() {
+ return bar;
+ }
+ }
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchConditionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchConditionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceAegisElementProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceJava5TypeCreator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/NoNamespaceTypeCreator.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/bus-dispatch.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/dispatch/bus-dispatch.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Propchange: cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/HelloServiceInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/HelloServiceInterceptor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/HelloServiceProxyFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/simple/src/test/java/org/apache/cxf/service/factory/HelloServiceProxyFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/transports/common/pom.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: cxf/trunk/rt/transports/common/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ChunkedUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ChunkedUtil.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ChunkedUtil.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ChunkedUtil.java Mon Jan 10 22:07:10 2011
@@ -1,98 +1,98 @@
-/**
- * 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.transport.http;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PushbackInputStream;
-import java.net.HttpURLConnection;
-
-import org.apache.cxf.helpers.HttpHeaderHelper;
-
-final class ChunkedUtil {
- private ChunkedUtil() {
- }
-
- /**
- * Get an input stream containing the partial response if one is present.
- *
- * @param connection the connection in question
- * @param responseCode the response code
- * @return an input stream if a partial response is pending on the connection
- */
- public static InputStream getPartialResponse(
- HttpURLConnection connection,
- int responseCode
- ) throws IOException {
- InputStream in = null;
- if (responseCode == HttpURLConnection.HTTP_ACCEPTED
- || responseCode == HttpURLConnection.HTTP_OK) {
- if (connection.getContentLength() > 0) {
- in = connection.getInputStream();
- } else if (hasChunkedResponse(connection)
- || hasEofTerminatedResponse(connection)) {
- // ensure chunked or EOF-terminated response is non-empty
- in = getNonEmptyContent(connection);
- }
- }
- return in;
- }
-
- /**
- * @param connection the given HttpURLConnection
- * @return true iff the connection has a chunked response pending
- */
- private static boolean hasChunkedResponse(HttpURLConnection connection) {
- return HttpHeaderHelper.CHUNKED.equalsIgnoreCase(
- connection.getHeaderField(HttpHeaderHelper.TRANSFER_ENCODING));
- }
-
- /**
- * @param connection the given HttpURLConnection
- * @return true iff the connection has a chunked response pending
- */
- private static boolean hasEofTerminatedResponse(
- HttpURLConnection connection
- ) {
- return HttpHeaderHelper.CLOSE.equalsIgnoreCase(
- connection.getHeaderField(HttpHeaderHelper.CONNECTION));
- }
-
- /**
- * @param connection the given HttpURLConnection
- * @return an input stream containing the response content if non-empty
- */
- private static InputStream getNonEmptyContent(
- HttpURLConnection connection
- ) {
- InputStream in = null;
- try {
- PushbackInputStream pin =
- new PushbackInputStream(connection.getInputStream());
- int c = pin.read();
- if (c != -1) {
- pin.unread((byte)c);
- in = pin;
- }
- } catch (IOException ioe) {
- // ignore
- }
- return in;
- }
-}
+/**
+ * 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.transport.http;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PushbackInputStream;
+import java.net.HttpURLConnection;
+
+import org.apache.cxf.helpers.HttpHeaderHelper;
+
+final class ChunkedUtil {
+ private ChunkedUtil() {
+ }
+
+ /**
+ * Get an input stream containing the partial response if one is present.
+ *
+ * @param connection the connection in question
+ * @param responseCode the response code
+ * @return an input stream if a partial response is pending on the connection
+ */
+ public static InputStream getPartialResponse(
+ HttpURLConnection connection,
+ int responseCode
+ ) throws IOException {
+ InputStream in = null;
+ if (responseCode == HttpURLConnection.HTTP_ACCEPTED
+ || responseCode == HttpURLConnection.HTTP_OK) {
+ if (connection.getContentLength() > 0) {
+ in = connection.getInputStream();
+ } else if (hasChunkedResponse(connection)
+ || hasEofTerminatedResponse(connection)) {
+ // ensure chunked or EOF-terminated response is non-empty
+ in = getNonEmptyContent(connection);
+ }
+ }
+ return in;
+ }
+
+ /**
+ * @param connection the given HttpURLConnection
+ * @return true iff the connection has a chunked response pending
+ */
+ private static boolean hasChunkedResponse(HttpURLConnection connection) {
+ return HttpHeaderHelper.CHUNKED.equalsIgnoreCase(
+ connection.getHeaderField(HttpHeaderHelper.TRANSFER_ENCODING));
+ }
+
+ /**
+ * @param connection the given HttpURLConnection
+ * @return true iff the connection has a chunked response pending
+ */
+ private static boolean hasEofTerminatedResponse(
+ HttpURLConnection connection
+ ) {
+ return HttpHeaderHelper.CLOSE.equalsIgnoreCase(
+ connection.getHeaderField(HttpHeaderHelper.CONNECTION));
+ }
+
+ /**
+ * @param connection the given HttpURLConnection
+ * @return an input stream containing the response content if non-empty
+ */
+ private static InputStream getNonEmptyContent(
+ HttpURLConnection connection
+ ) {
+ InputStream in = null;
+ try {
+ PushbackInputStream pin =
+ new PushbackInputStream(connection.getInputStream());
+ int c = pin.read();
+ if (c != -1) {
+ pin.unread((byte)c);
+ in = pin;
+ }
+ } catch (IOException ioe) {
+ // ignore
+ }
+ return in;
+ }
+}
Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ChunkedUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ChunkedUtil.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java Mon Jan 10 22:07:10 2011
@@ -1,108 +1,108 @@
-/**
- * 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.transport.http;
-
-import java.net.HttpURLConnection;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.cxf.message.Message;
-
-public class Cookies {
- /**
- * Variables for holding session state if sessions are supposed to be maintained
- */
- private final Map<String, Cookie> sessionCookies = new ConcurrentHashMap<String, Cookie>();
- private boolean maintainSession;
-
- public Map<String, Cookie> getSessionCookies() {
- return sessionCookies;
- }
-
- public void readFromConnection(HttpURLConnection connection) {
- if (maintainSession) {
- for (Map.Entry<String, List<String>> h : connection.getHeaderFields().entrySet()) {
- if ("Set-Cookie".equalsIgnoreCase(h.getKey())) {
- handleSetCookie(h.getValue());
- }
- }
- }
- }
-
- public void writeToMessageHeaders(Message message) {
- //Do we need to maintain a session?
- maintainSession = Boolean.TRUE.equals((Boolean)message.get(Message.MAINTAIN_SESSION));
-
- //If we have any cookies and we are maintaining sessions, then use them
- if (maintainSession && sessionCookies.size() > 0) {
- new Headers(message).writeSessionCookies(sessionCookies);
- }
- }
-
- /**
- * Given a list of current cookies and a new Set-Cookie: request, construct
- * a new set of current cookies and return it.
- * @param current Set of previously set cookies
- * @param header Text of a Set-Cookie: header
- * @return New set of cookies
- */
- private void handleSetCookie(List<String> headers) {
- if (headers == null || headers.size() == 0) {
- return;
- }
-
- for (String header : headers) {
- String[] cookies = header.split(",");
- for (String cookie : cookies) {
- String[] parts = cookie.split(";");
-
- String[] kv = parts[0].split("=", 2);
- if (kv.length != 2) {
- continue;
- }
- String name = kv[0].trim();
- String value = kv[1].trim();
- Cookie newCookie = new Cookie(name, value);
-
- for (int i = 1; i < parts.length; i++) {
- kv = parts[i].split("=", 2);
- name = kv[0].trim();
- value = (kv.length > 1) ? kv[1].trim() : null;
- if (name.equalsIgnoreCase(Cookie.DISCARD_ATTRIBUTE)) {
- newCookie.setMaxAge(0);
- } else if (name.equalsIgnoreCase(Cookie.MAX_AGE_ATTRIBUTE) && value != null) {
- try {
- newCookie.setMaxAge(Integer.parseInt(value));
- } catch (NumberFormatException e) {
- // do nothing here
- }
- } else if (name.equalsIgnoreCase(Cookie.PATH_ATTRIBUTE) && value != null) {
- newCookie.setPath(value);
- }
- }
- if (newCookie.getMaxAge() != 0) {
- sessionCookies.put(newCookie.getName(), newCookie);
- } else {
- sessionCookies.remove(newCookie.getName());
- }
- }
- }
- }
-}
+/**
+ * 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.transport.http;
+
+import java.net.HttpURLConnection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.cxf.message.Message;
+
+public class Cookies {
+ /**
+ * Variables for holding session state if sessions are supposed to be maintained
+ */
+ private final Map<String, Cookie> sessionCookies = new ConcurrentHashMap<String, Cookie>();
+ private boolean maintainSession;
+
+ public Map<String, Cookie> getSessionCookies() {
+ return sessionCookies;
+ }
+
+ public void readFromConnection(HttpURLConnection connection) {
+ if (maintainSession) {
+ for (Map.Entry<String, List<String>> h : connection.getHeaderFields().entrySet()) {
+ if ("Set-Cookie".equalsIgnoreCase(h.getKey())) {
+ handleSetCookie(h.getValue());
+ }
+ }
+ }
+ }
+
+ public void writeToMessageHeaders(Message message) {
+ //Do we need to maintain a session?
+ maintainSession = Boolean.TRUE.equals((Boolean)message.get(Message.MAINTAIN_SESSION));
+
+ //If we have any cookies and we are maintaining sessions, then use them
+ if (maintainSession && sessionCookies.size() > 0) {
+ new Headers(message).writeSessionCookies(sessionCookies);
+ }
+ }
+
+ /**
+ * Given a list of current cookies and a new Set-Cookie: request, construct
+ * a new set of current cookies and return it.
+ * @param current Set of previously set cookies
+ * @param header Text of a Set-Cookie: header
+ * @return New set of cookies
+ */
+ private void handleSetCookie(List<String> headers) {
+ if (headers == null || headers.size() == 0) {
+ return;
+ }
+
+ for (String header : headers) {
+ String[] cookies = header.split(",");
+ for (String cookie : cookies) {
+ String[] parts = cookie.split(";");
+
+ String[] kv = parts[0].split("=", 2);
+ if (kv.length != 2) {
+ continue;
+ }
+ String name = kv[0].trim();
+ String value = kv[1].trim();
+ Cookie newCookie = new Cookie(name, value);
+
+ for (int i = 1; i < parts.length; i++) {
+ kv = parts[i].split("=", 2);
+ name = kv[0].trim();
+ value = (kv.length > 1) ? kv[1].trim() : null;
+ if (name.equalsIgnoreCase(Cookie.DISCARD_ATTRIBUTE)) {
+ newCookie.setMaxAge(0);
+ } else if (name.equalsIgnoreCase(Cookie.MAX_AGE_ATTRIBUTE) && value != null) {
+ try {
+ newCookie.setMaxAge(Integer.parseInt(value));
+ } catch (NumberFormatException e) {
+ // do nothing here
+ }
+ } else if (name.equalsIgnoreCase(Cookie.PATH_ATTRIBUTE) && value != null) {
+ newCookie.setPath(value);
+ }
+ }
+ if (newCookie.getMaxAge() != 0) {
+ sessionCookies.put(newCookie.getName(), newCookie);
+ } else {
+ sessionCookies.remove(newCookie.getName());
+ }
+ }
+ }
+ }
+}
Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Cookies.java
------------------------------------------------------------------------------
svn:keywords = Rev Date