deltaspike-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rafab...@apache.org
Subject deltaspike git commit: DELTASPIKE-901 - Add tests
Date Fri, 22 May 2015 18:42:52 GMT
Repository: deltaspike
Updated Branches:
  refs/heads/master 31b674d5b -> 334e1c4b6


DELTASPIKE-901 - Add tests


Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/334e1c4b
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/334e1c4b
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/334e1c4b

Branch: refs/heads/master
Commit: 334e1c4b6062ca40ac16a10d04f71a78ef8d96f3
Parents: 31b674d
Author: Rafael Benevides <rafabene@gmail.com>
Authored: Fri May 22 14:42:35 2015 -0400
Committer: Rafael Benevides <rafabene@gmail.com>
Committed: Fri May 22 14:42:35 2015 -0400

----------------------------------------------------------------------
 .../deltaspike/data/impl/QueryResultTest.java   | 28 +++++++-
 .../data/test/domain/SimpleStringId.java        | 69 ++++++++++++++++++++
 .../data/test/domain/SimpleStringIdBuilder.java | 46 +++++++++++++
 .../data/test/service/SimpleRepository.java     |  4 ++
 4 files changed, 144 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/334e1c4b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
index e300ea0..723feca 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/QueryResultTest.java
@@ -38,9 +38,7 @@ import javax.persistence.PersistenceContext;
 
 import org.apache.deltaspike.data.api.QueryResult;
 import org.apache.deltaspike.data.test.TransactionalTestCase;
-import org.apache.deltaspike.data.test.domain.Simple;
-import org.apache.deltaspike.data.test.domain.SimpleBuilder;
-import org.apache.deltaspike.data.test.domain.Simple_;
+import org.apache.deltaspike.data.test.domain.*;
 import org.apache.deltaspike.data.test.service.SimpleRepository;
 import org.apache.deltaspike.test.category.WebProfileCategory;
 import org.jboss.arquillian.container.test.api.Deployment;
@@ -359,6 +357,30 @@ public class QueryResultTest extends TransactionalTestCase
         assertNull(result2);
     }
 
+    @Test
+    public void should_paginate_with_orderby()
+    {
+        // given
+        SimpleStringIdBuilder builder = new SimpleStringIdBuilder(entityManager);
+
+
+        final String name = "should_paginate_with_orderby";
+        final String name2 = "should_paginate_with_orderby2";
+        builder.createSimple("a", name);
+        builder.createSimple("b", name2);
+
+        // when
+        QueryResult<SimpleStringId> allOrderByNamePaginate = repo.findAllOrderByIdPaginate(0,
10);
+
+        // then
+        assertNotNull(allOrderByNamePaginate);
+
+        List<SimpleStringId> resultList = allOrderByNamePaginate.getResultList();
+        assertEquals(2, resultList.size());
+        assertEquals("a", resultList.get(0).getId());
+        assertEquals("b", resultList.get(1).getId());
+    }
+
     @Before
     public void setup()
     {

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/334e1c4b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/SimpleStringId.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/SimpleStringId.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/SimpleStringId.java
new file mode 100644
index 0000000..002c2b9
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/SimpleStringId.java
@@ -0,0 +1,69 @@
+/*
+ * 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.deltaspike.data.test.domain;
+
+import javax.persistence.*;
+import java.util.UUID;
+
+@Entity
+@NamedQueries({
+        @NamedQuery(name = SimpleStringId.FIND_ALL_ORDER_BY_ID, query = "SELECT e FROM SimpleStringId
e ORDER BY e.id")
+})
+@Table(name = "SIMPLE_TABLE_STRING")
+public class SimpleStringId extends SuperSimple
+{
+
+    public static final String FIND_ALL_ORDER_BY_ID = "SimpleStringId.findAllOrderById";
+
+    @Id
+    private String id;
+    private String name;
+
+    public SimpleStringId(String id, String name)
+    {
+        this.id = id;
+        this.name = name;
+    }
+
+    public String getId()
+    {
+        return id;
+    }
+
+    public void setId(String id)
+    {
+        this.id = id;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    @Override
+    public String toString()
+    {
+        return "Simple [id=" + id + ", name=" + name + "]";
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/334e1c4b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/SimpleStringIdBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/SimpleStringIdBuilder.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/SimpleStringIdBuilder.java
new file mode 100644
index 0000000..0ef99c1
--- /dev/null
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/domain/SimpleStringIdBuilder.java
@@ -0,0 +1,46 @@
+/*
+ * 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.deltaspike.data.test.domain;
+
+import javax.persistence.EntityManager;
+
+public class SimpleStringIdBuilder
+{
+
+    private final EntityManager entityManager;
+
+    public SimpleStringIdBuilder(EntityManager entityManager)
+    {
+        this.entityManager = entityManager;
+    }
+
+    public SimpleStringId createSimple(String id, String name)
+    {
+        SimpleStringId result = new SimpleStringId(id, name);
+        return persistSimple(result);
+    }
+
+    public SimpleStringId persistSimple(SimpleStringId result)
+    {
+        entityManager.persist(result);
+        entityManager.flush();
+        return result;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/334e1c4b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
index 2c3b4e3..39b9311 100755
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/test/service/SimpleRepository.java
@@ -35,6 +35,7 @@ import org.apache.deltaspike.data.api.QueryParam;
 import org.apache.deltaspike.data.api.QueryResult;
 import org.apache.deltaspike.data.api.Repository;
 import org.apache.deltaspike.data.test.domain.Simple;
+import org.apache.deltaspike.data.test.domain.SimpleStringId;
 
 @Repository
 public abstract class SimpleRepository extends AbstractEntityRepository<Simple, Long>
@@ -101,6 +102,9 @@ public abstract class SimpleRepository extends AbstractEntityRepository<Simple,
 
     public abstract QueryResult<Simple> findByName(String name);
 
+    @Query(named = SimpleStringId.FIND_ALL_ORDER_BY_ID)
+    public abstract QueryResult<SimpleStringId> findAllOrderByIdPaginate(@FirstResult
int start, @MaxResults int pageSize);
+
     @Override
     protected abstract EntityManager entityManager();
 


Mime
View raw message