cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1406119 - in /cxf/branches/2.6.x-fixes: ./ rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/ rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/
Date Tue, 06 Nov 2012 13:02:12 GMT
Author: sergeyb
Date: Tue Nov  6 13:02:12 2012
New Revision: 1406119

URL: http://svn.apache.org/viewvc?rev=1406119&view=rev
Log:
Merged revisions 1397611 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1397611 | sergeyb | 2012-10-12 16:16:36 +0100 (Fri, 12 Oct 2012) | 1 line
  
  Adding few more FIQL to JPA converter tests
........

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1397611

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java?rev=1406119&r1=1406118&r2=1406119&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitor.java
Tue Nov  6 13:02:12 2012
@@ -117,8 +117,11 @@ public class JPATypedQueryVisitor<T> ext
             break;
         case EQUALS:
             if (clazz.equals(String.class)) {
-                pred = builder.like(path.as(String.class), "%"
-                                    + (String) value + "%");
+                String theValue = (String)value;
+                if (theValue.contains("*")) {
+                    theValue = ((String)value).replaceAll("\\*", "");
+                }
+                pred = builder.like(path.as(String.class), "%" + theValue + "%");
             } else {
                 pred = builder.equal(path.as(clazz), clazz.cast(value));
             }

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java?rev=1406119&r1=1406118&r2=1406119&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/Book.java
Tue Nov  6 13:02:12 2012
@@ -25,7 +25,9 @@ import javax.persistence.Id;
 public class Book {
     @Id
     private int id;
-
+    private String name;
+    
+    
     public int getId() {
         return id;
     }
@@ -33,4 +35,12 @@ public class Book {
     public void setId(int id) {
         this.id = id;
     }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
 }

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java?rev=1406119&r1=1406118&r2=1406119&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPATypedQueryVisitorTest.java
Tue Nov  6 13:02:12 2012
@@ -59,14 +59,17 @@ public class JPATypedQueryVisitorTest ex
             em.getTransaction().begin();
             Book b1 = new Book();
             b1.setId(9);
+            b1.setName("num9");
             em.persist(b1);
             assertTrue(em.contains(b1));
             Book b2 = new Book();
             b2.setId(10);
+            b2.setName("num10");
             em.persist(b2);
             assertTrue(em.contains(b2));
             Book b3 = new Book();
             b3.setId(11);
+            b3.setName("num11");
             em.persist(b3);
             assertTrue(em.contains(b3));
             
@@ -97,14 +100,83 @@ public class JPATypedQueryVisitorTest ex
     }
     
     @Test
-    public void testSimpleQuery() throws Exception {
-        SearchCondition<Book> filter = new FiqlParser<Book>(Book.class).parse("id=lt=10,id=gt=10");
-        JPATypedQueryVisitor<Book> jpa = new JPATypedQueryVisitor<Book>(em, Book.class);
-        filter.accept(jpa);
-        TypedQuery<Book> query = jpa.getQuery();
-        List<Book> books = query.getResultList();
+    public void testOrQuery() throws Exception {
+        List<Book> books = queryBooks("id=lt=10,id=gt=10");
         assertEquals(2, books.size());
         assertTrue(9 == books.get(0).getId() && 11 == books.get(1).getId()
             || 11 == books.get(0).getId() && 9 == books.get(1).getId());
     }
+    
+    @Test
+    public void testOrQueryNoMatch() throws Exception {
+        List<Book> books = queryBooks("id==7,id==5");
+        assertEquals(0, books.size());
+    }
+    
+    @Test
+    public void testAndQuery() throws Exception {
+        List<Book> books = queryBooks("id==10;name==num10");
+        assertEquals(1, books.size());
+        assertTrue(10 == books.get(0).getId() && "num10".equals(books.get(0).getName()));
+    }
+    
+    @Test
+    public void testAndQueryNoMatch() throws Exception {
+        List<Book> books = queryBooks("id==10;name==num9");
+        assertEquals(0, books.size());
+    }
+    
+    @Test
+    public void testEqualsQuery() throws Exception {
+        List<Book> books = queryBooks("id==10");
+        assertEquals(1, books.size());
+        assertTrue(10 == books.get(0).getId());
+    }
+    
+    @Test
+    public void testEqualsWildcard() throws Exception {
+        List<Book> books = queryBooks("name==num1*");
+        assertEquals(2, books.size());
+        assertTrue(10 == books.get(0).getId() && 11 == books.get(1).getId()
+            || 11 == books.get(0).getId() && 10 == books.get(1).getId());
+    }
+    
+    @Test
+    public void testGreaterQuery() throws Exception {
+        List<Book> books = queryBooks("id=gt=10");
+        assertEquals(1, books.size());
+        assertTrue(11 == books.get(0).getId());
+    }
+    
+    @Test
+    public void testGreaterEqualQuery() throws Exception {
+        List<Book> books = queryBooks("id=ge=10");
+        assertEquals(2, books.size());
+        assertTrue(10 == books.get(0).getId() && 11 == books.get(1).getId()
+            || 11 == books.get(0).getId() && 10 == books.get(1).getId());
+    }
+    
+    @Test
+    public void testLessEqualQuery() throws Exception {
+        List<Book> books = queryBooks("id=le=10");
+        assertEquals(2, books.size());
+        assertTrue(9 == books.get(0).getId() && 10 == books.get(1).getId()
+            || 9 == books.get(0).getId() && 10 == books.get(1).getId());
+    }
+    
+    @Test
+    public void testNotEqualsQuery() throws Exception {
+        List<Book> books = queryBooks("id!=10");
+        assertEquals(2, books.size());
+        assertTrue(9 == books.get(0).getId() && 11 == books.get(1).getId()
+            || 11 == books.get(0).getId() && 9 == books.get(1).getId());
+    }
+    
+    private List<Book> queryBooks(String expression) throws Exception {
+        SearchCondition<Book> filter = new FiqlParser<Book>(Book.class).parse(expression);
+        JPATypedQueryVisitor<Book> jpa = new JPATypedQueryVisitor<Book>(em, Book.class);
+        filter.accept(jpa);
+        TypedQuery<Book> query = jpa.getQuery();
+        return query.getResultList();
+    }
 }



Mime
View raw message