You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by am...@apache.org on 2011/03/09 02:05:22 UTC

svn commit: r1079631 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/

Author: amichalec
Date: Wed Mar  9 01:05:22 2011
New Revision: 1079631

URL: http://svn.apache.org/viewvc?rev=1079631&view=rev
Log:
Reverting changes of false problem alert

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchConditionTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java?rev=1079631&r1=1079630&r2=1079631&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java Wed Mar  9 01:05:22 2011
@@ -21,8 +21,8 @@ package org.apache.cxf.jaxrs.ext.search;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.HashSet;
-import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -32,6 +32,7 @@ import java.util.Set;
  * {@link #isMet(Object)} description.
  * 
  * @param <T> type of search condition.
+ * 
  */
 public class SimpleSearchCondition<T> implements SearchCondition<T> {
 
@@ -46,9 +47,9 @@ public class SimpleSearchCondition<T> im
     }
     private ConditionType joiningType = ConditionType.AND;
     private T condition;
-
+    
     private List<SearchCondition<T>> scts;
-
+    
     /**
      * Creates search condition with same operator (equality, inequality) applied in all comparison; see
      * {@link #isMet(Object)} for details of comparison.
@@ -68,7 +69,7 @@ public class SimpleSearchCondition<T> im
         }
         this.condition = condition;
         scts = createConditions(null, cType);
-
+                
     }
 
     /**
@@ -86,7 +87,7 @@ public class SimpleSearchCondition<T> im
         if (condition == null) {
             throw new IllegalArgumentException("condition is null");
         }
-        if (isPrimitive(condition)) {
+        if (isBuiltIn(condition)) {
             throw new IllegalArgumentException("mapped operators strategy is "
                                                + "not supported for primitive type "
                                                + condition.getClass().getName());
@@ -125,17 +126,15 @@ public class SimpleSearchCondition<T> im
         }
     }
 
-    private List<SearchCondition<T>> createConditions(Map<String, ConditionType> getters2operators,
+    private List<SearchCondition<T>> createConditions(Map<String, ConditionType> getters2operators, 
                                                       ConditionType sharedType) {
-        if (isPrimitive(condition)) {
-            return Collections.singletonList((SearchCondition<T>)new PrimitiveSearchCondition<T>(null,
-                                                                                                 condition,
-                                                                                                 sharedType,
-                                                                                                 condition));
+        if (isBuiltIn(condition)) {
+            return Collections.singletonList(
+                (SearchCondition<T>)new PrimitiveSearchCondition<T>(null, condition, sharedType, condition));
         } else {
             List<SearchCondition<T>> list = new ArrayList<SearchCondition<T>>();
             Map<String, Object> get2val = getGettersAndValues();
-
+            
             for (String getter : get2val.keySet()) {
                 ConditionType ct = getters2operators == null ? sharedType : getters2operators.get(getter);
                 if (ct == null) {
@@ -146,7 +145,7 @@ public class SimpleSearchCondition<T> im
                     continue;
                 }
                 list.add(new PrimitiveSearchCondition<T>(getter, rval, ct, condition));
-
+                
             }
             if (list.isEmpty()) {
                 throw new IllegalStateException("This search condition is empty and can not be used");
@@ -154,7 +153,7 @@ public class SimpleSearchCondition<T> im
             return list;
         }
     }
-
+    
     /**
      * Compares given object against template condition object.
      * <p>
@@ -166,8 +165,7 @@ public class SimpleSearchCondition<T> im
      * For other types the comparison of given object against template object is done using its
      * <b>getters</b>; Value returned by {@linkplain #isMet(Object)} operation is <b>conjunction ('and'
      * operator)</b> of comparisons of each getter accessible in object of type T. Getters of template object
-     * that return null or throw exception are not used in comparison. If type T contains getters that return
-     * primitive not-nullable types (as int, float etc) exception will be thrown. Finally, if all getters
+     * that return null or throw exception are not used in comparison. Finally, if all getters
      * return nulls (are excluded) it is interpreted as no filter (match every pojo).
      * <p>
      * If {@link #SimpleSearchCondition(ConditionType, Object) constructor with shared operator} was used,
@@ -193,7 +191,7 @@ public class SimpleSearchCondition<T> im
      * 
      * class Entity {
      *   public String getName() {...
-     *   public Integer getLevel() {...
+     *   public int getLevel() {...
      *   public String getMessage() {...
      * }
      * 
@@ -238,25 +236,14 @@ public class SimpleSearchCondition<T> im
      * @return template (condition) object getters mapped to their non-null values
      */
     private Map<String, Object> getGettersAndValues() {
-        Map<String, Object> getters2values = new LinkedHashMap<String, Object>();
+        
+        Map<String, Object> getters2values = new HashMap<String, Object>();
         Beanspector<T> beanspector = new Beanspector<T>(condition);
         for (String getter : beanspector.getGettersNames()) {
-            try {
-                if (beanspector.getAccessorType(getter).isPrimitive()) {
-                    String beanType = beanspector.getBean().getClass().getCanonicalName();
-                    throw new IllegalArgumentException("Type '" + beanType + "' has property '" + getter
-                                                       + "' of primitive type and "
-                                                       + "cannot be used as a condition");
-                }
-            } catch (IllegalArgumentException e) {
-                throw e;
-            } catch (Exception e) {
-                throw new IllegalArgumentException(e);
-            }
             Object value = getValue(beanspector, getter, condition);
             getters2values.put(getter, value);
         }
-        // we do not need compare class objects
+        //we do not need compare class objects
         getters2values.keySet().remove("class");
         return getters2values;
     }
@@ -269,10 +256,11 @@ public class SimpleSearchCondition<T> im
         }
     }
 
-    private boolean isPrimitive(T pojo) {
+    private boolean isBuiltIn(T pojo) {
         return pojo.getClass().getName().startsWith("java.lang");
     }
 
+
     public List<T> findAll(Collection<T> pojos) {
         List<T> result = new ArrayList<T>();
         for (T pojo : pojos) {
@@ -286,7 +274,7 @@ public class SimpleSearchCondition<T> im
     public String toSQL(String table, String... columns) {
         return SearchUtils.toSQL(this, table, columns);
     }
-
+    
     public PrimitiveStatement getStatement() {
         if (scts.size() == 1) {
             return scts.get(0).getStatement();
@@ -298,5 +286,6 @@ public class SimpleSearchCondition<T> im
     public void accept(SearchConditionVisitor<T> visitor) {
         visitor.visit(this);
     }
-
+    
+    
 }

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=1079631&r1=1079630&r2=1079631&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 Wed Mar  9 01:05:22 2011
@@ -30,7 +30,6 @@ 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);
 
@@ -78,12 +77,12 @@ public class FiqlParserTest extends Asse
     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)");
@@ -166,21 +165,22 @@ public class FiqlParserTest extends Asse
     public void testParseComplex1() throws FiqlParseException {
         SearchCondition<Condition> filter = parser.parse("name==ami*;level=gt=10");
         assertEquals(ConditionType.AND, filter.getConditionType());
-        
+
         List<SearchCondition<Condition>> conditions = filter.getSearchConditions();
         assertEquals(2, conditions.size());
         PrimitiveStatement st1 = conditions.get(0).getStatement();
-        assertEquals(ConditionType.EQUALS, st1.getCondition());
-        
         PrimitiveStatement st2 = conditions.get(1).getStatement();
-        assertEquals(ConditionType.GREATER_THAN, st2.getCondition());
-        
+        assertTrue((ConditionType.EQUALS.equals(st1.getCondition()) 
+            && ConditionType.GREATER_THAN.equals(st2.getCondition())) 
+            || (ConditionType.EQUALS.equals(st2.getCondition()) 
+                && ConditionType.GREATER_THAN.equals(st1.getCondition())));
+
         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)));
     }
-    
+
     @SuppressWarnings("deprecation")
     @Test
     public void testSQL1() throws FiqlParseException {
@@ -194,16 +194,17 @@ public class FiqlParserTest extends Asse
     public void testParseComplex2() throws FiqlParseException {
         SearchCondition<Condition> filter = parser.parse("name==ami*,level=gt=10");
         assertEquals(ConditionType.OR, filter.getConditionType());
-        
+
         List<SearchCondition<Condition>> conditions = filter.getSearchConditions();
         assertEquals(2, conditions.size());
-        
+
         PrimitiveStatement st1 = conditions.get(0).getStatement();
-        assertEquals(ConditionType.EQUALS, st1.getCondition());
-        
         PrimitiveStatement st2 = conditions.get(1).getStatement();
-        assertEquals(ConditionType.GREATER_THAN, st2.getCondition());
-        
+        assertTrue((ConditionType.EQUALS.equals(st1.getCondition()) 
+            && ConditionType.GREATER_THAN.equals(st2.getCondition())) 
+            || (ConditionType.EQUALS.equals(st2.getCondition()) 
+                && ConditionType.GREATER_THAN.equals(st1.getCondition())));
+
         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)));
@@ -217,7 +218,7 @@ public class FiqlParserTest extends Asse
         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)");
@@ -233,22 +234,22 @@ public class FiqlParserTest extends Asse
         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)
+                    + "OR (level > '10'))").equals(sql)
                    || ("SELECT * FROM table WHERE (name LIKE 'foo%') AND "
-                   + "((level > '10') OR (name NOT LIKE '%bar'))").equals(sql));
+                       + "((level > '10') OR (name NOT LIKE '%bar'))").equals(sql));
     }
-    
+
     @SuppressWarnings("deprecation")
     @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)
+                    + " 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));
+                       + " AND ((name = 'test') OR (level = '18'))").equals(sql));
     }
-    
+
     @SuppressWarnings("deprecation")
     @Test
     public void testSQL5() throws FiqlParseException {
@@ -256,7 +257,7 @@ public class FiqlParserTest extends Asse
         String sql = filter.toSQL("table");
         assertTrue("SELECT * FROM table WHERE name = 'test'".equals(sql));
     }
-    
+
     @Test
     public void testParseComplex4() throws FiqlParseException {
         SearchCondition<Condition> filter = parser.parse("name==foo*;name!=*bar,level=gt=10");
@@ -265,7 +266,7 @@ public class FiqlParserTest extends Asse
         assertTrue(filter.isMet(new Condition("foobar", 20, null)));
         assertFalse(filter.isMet(new Condition("fooxxxbar", 0, null)));
     }
-    
+
     @Ignore
     static class Condition {
         private String name;
@@ -289,11 +290,11 @@ public class FiqlParserTest extends Asse
             this.name = name;
         }
 
-        public Integer getLevel() {
+        public int getLevel() {
             return level;
         }
 
-        public void setLevel(Integer level) {
+        public void setLevel(int level) {
             this.level = level;
         }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java?rev=1079631&r1=1079630&r2=1079631&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java Wed Mar  9 01:05:22 2011
@@ -21,11 +21,11 @@ package org.apache.cxf.jaxrs.ext.search;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class SearchContextImplTest extends Assert {
@@ -67,48 +67,4 @@ public class SearchContextImplTest exten
         assertEquals(1, found.size());
         assertEquals(new Book("CXF Rocks", 125L), found.get(0));
     }
-    
-    @Ignore
-    public static class Book {
-        private String name;
-        private long id;
-        
-        public Book() {
-        }
-        
-        public Book(String name, long id) {
-            this.name = name;
-            this.id = id;
-        }
-        
-        public void setName(String n) {
-            name = n;
-        }
-
-        public String getName() {
-            return name;
-        }
-        
-        public void setId(Long i) {
-            id = i;
-        }
-        public Long getId() {
-            return id;
-        }
-        
-        public int hashCode() { 
-            return name.hashCode() * 37 + new Long(id).hashCode();
-        }
-        
-        public boolean equals(Object o) {
-            if (!(o instanceof Book)) {
-                return false;
-            }
-            Book other = (Book)o;
-            
-            return other.name.equals(name) && other.id == id;
-            
-        }
-    }
-
 }

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=1079631&r1=1079630&r2=1079631&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 Wed Mar  9 01:05:22 2011
@@ -333,11 +333,6 @@ public class SimpleSearchConditionTest {
         assertFalse(ssc.isMet("foobarbaz"));
     }
     
-    @Test(expected = IllegalArgumentException.class)
-    public void testPrimitivePropertyOfCondition() {
-        new SimpleSearchCondition<PrimitiveProp>(ConditionType.EQUALS, new PrimitiveProp(123));
-    }
-
     static class SingleAttr {
         private String foo;
 
@@ -372,23 +367,5 @@ public class SimpleSearchConditionTest {
         public String getBar() {
             return bar;
         }
-    }
-    
-    static class PrimitiveProp {
-        private Integer foo;
-
-        public PrimitiveProp(Integer foo) {
-            super();
-            this.foo = foo;
-        }
-        
-        //primitives getter will be detected
-        public int getFoo() {
-            return foo;
-        }
-
-        public void setFoo(int foo) {
-            this.foo = foo;
-        }        
-    }
+    }    
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1079631&r1=1079630&r2=1079631&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Wed Mar  9 01:05:22 2011
@@ -679,26 +679,23 @@ public class JAXRSClientServerBookTest e
                                "application/xml", 200);
     }
     
-// Enable these tests when SimpleSearchCondition flaw (
-// regarding primitive type of properties of type T) is sloved     
+    @Test
+    public void testSearchBook123() throws Exception {
+        getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/search"
+                               + "?_s=name==CXF*;id=ge=123;id=lt=124",
+                               "resources/expected_get_book123.txt",
+                               "application/xml", 200);
+    }
     
-//    @Test
-//    public void testSearchBook123() throws Exception {
-//        getAndCompareAsStrings("http://localhost:" + PORT + "/bookstore/books/search"
-//                               + "?_s=name==CXF*;id=ge=123;id=lt=124",
-//                               "resources/expected_get_book123.txt",
-//                               "application/xml", 200);
-//    }
-//    
-//    @Test
-//    public void testSearchBook123WithWebClient() throws Exception {
-//        String address = "http://localhost:" + PORT + "/bookstore/books/search";
-//                          
-//        WebClient client = WebClient.create(address);
-//        Book b = client.query("_s", "name==CXF*;id=ge=123;id=lt=124").get(Book.class);
-//        assertEquals(b.getId(), 123L);
-//        
-//    }
+    @Test
+    public void testSearchBook123WithWebClient() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/search";
+                          
+        WebClient client = WebClient.create(address);
+        Book b = client.query("_s", "name==CXF*;id=ge=123;id=lt=124").get(Book.class);
+        assertEquals(b.getId(), 123L);
+        
+    }
     
     @Test
     public void testGetBook123CGLIB() throws Exception {