summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2016-04-06 12:28:32 -0400
committerJames Moger <james.moger@gitblit.com>2016-04-06 12:28:32 -0400
commitae3d3a1620cf75f0b5f1f74c108d977681d00f57 (patch)
tree3b54b1582cfb543ebd5fe81f94a928250de32f33 /src/test
parente8333d5fcd205b40cffb972f9130c310368be64a (diff)
downloadiciql-ae3d3a1620cf75f0b5f1f74c108d977681d00f57.tar.gz
iciql-ae3d3a1620cf75f0b5f1f74c108d977681d00f57.zip
Add methods to return group by field counts
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/iciql/test/ModelsTest.java44
-rw-r--r--src/test/java/com/iciql/test/PrimitivesTest.java19
-rw-r--r--src/test/java/com/iciql/test/models/PrimitivesModel.java4
3 files changed, 67 insertions, 0 deletions
diff --git a/src/test/java/com/iciql/test/ModelsTest.java b/src/test/java/com/iciql/test/ModelsTest.java
index 742ed53..96a6e4a 100644
--- a/src/test/java/com/iciql/test/ModelsTest.java
+++ b/src/test/java/com/iciql/test/ModelsTest.java
@@ -19,6 +19,7 @@ package com.iciql.test;
import com.iciql.Db;
import com.iciql.DbInspector;
+import com.iciql.ValueCount;
import com.iciql.ValidationRemark;
import com.iciql.test.models.Product;
import com.iciql.test.models.ProductAnnotationOnly;
@@ -174,4 +175,47 @@ public class ModelsTest {
assertEquals(10, ids.size());
assertEquals("[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]", ids.toString());
}
+
+ @Test
+ public void testGroupByCount() {
+ Product products = new Product();
+
+ List<ValueCount<String>> categories = db.from(products)
+ .selectCount(products.category);
+ assertEquals(5, categories.size());
+ assertEquals("[Meat/Poultry=1, Produce=1, Seafood=1, Beverages=2, Condiments=5]", categories.toString());
+ }
+
+ @Test
+ public void testGroupByCountDesc() {
+ Product products = new Product();
+
+ List<ValueCount<String>> categories = db.from(products)
+ .selectCountDesc(products.category);
+ assertEquals(5, categories.size());
+ assertEquals("[Condiments=5, Beverages=2, Seafood=1, Produce=1, Meat/Poultry=1]", categories.toString());
+ }
+
+ @Test
+ public void testFilteredGroupByCount() {
+ Product products = new Product();
+
+ List<ValueCount<String>> categories = db.from(products)
+ .where(products.category).isNot("Seafood")
+ .selectCount(products.category);
+ assertEquals(4, categories.size());
+ assertEquals("[Meat/Poultry=1, Produce=1, Beverages=2, Condiments=5]", categories.toString());
+ }
+
+ @Test
+ public void testFilteredGroupByCountDesc() {
+ Product products = new Product();
+
+ List<ValueCount<String>> categories = db.from(products)
+ .where(products.category).isNot("Seafood")
+ .selectCountDesc(products.category);
+ assertEquals(4, categories.size());
+ assertEquals("[Condiments=5, Beverages=2, Produce=1, Meat/Poultry=1]", categories.toString());
+ }
+
}
diff --git a/src/test/java/com/iciql/test/PrimitivesTest.java b/src/test/java/com/iciql/test/PrimitivesTest.java
index 49595a2..db36be0 100644
--- a/src/test/java/com/iciql/test/PrimitivesTest.java
+++ b/src/test/java/com/iciql/test/PrimitivesTest.java
@@ -18,6 +18,7 @@ package com.iciql.test;
import com.iciql.Db;
import com.iciql.IciqlException;
+import com.iciql.ValueCount;
import com.iciql.test.models.MultipleBoolsModel;
import com.iciql.test.models.PrimitivesModel;
import org.junit.Test;
@@ -114,4 +115,22 @@ public class PrimitivesTest {
assertEquals(models.size(), list.size());
assertEquals("[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]", list.toString());
}
+
+ @Test
+ public void testPrimitiveGroupByCount() {
+ Db db = IciqlSuite.openNewDb();
+
+ // insert random models in reverse order
+ List<PrimitivesModel> models = PrimitivesModel.getList();
+ Collections.reverse(models);
+ // insert them in reverse order
+ db.insertAll(models);
+
+ PrimitivesModel primitives = new PrimitivesModel();
+ List<ValueCount<Integer>> types = db.from(primitives)
+ .selectCount(primitives.typeCode);
+ assertEquals(2, types.size());
+ assertEquals("[0=5, 1=5]", types.toString());
+ }
+
}
diff --git a/src/test/java/com/iciql/test/models/PrimitivesModel.java b/src/test/java/com/iciql/test/models/PrimitivesModel.java
index 078b565..aebf9f6 100644
--- a/src/test/java/com/iciql/test/models/PrimitivesModel.java
+++ b/src/test/java/com/iciql/test/models/PrimitivesModel.java
@@ -50,6 +50,9 @@ public class PrimitivesModel {
@IQColumn
public float myFloat;
+ @IQColumn
+ public int typeCode;
+
public PrimitivesModel() {
Random rand = new Random();
myLong = rand.nextLong();
@@ -78,6 +81,7 @@ public class PrimitivesModel {
for (int i = 1; i <= 10; i++) {
PrimitivesModel p = new PrimitivesModel();
p.myLong = i;
+ p.typeCode = i % 2;
list.add(p);
}
return list;