aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/com/iciql/test/IciqlSuite.java12
-rw-r--r--tests/com/iciql/test/ViewsTest.java114
-rw-r--r--tests/com/iciql/test/models/ProductView.java47
-rw-r--r--tests/com/iciql/test/models/ProductViewFromQuery.java42
-rw-r--r--tests/com/iciql/test/models/ProductViewInherited.java44
-rw-r--r--tests/com/iciql/test/models/ProductViewInheritedComplex.java28
6 files changed, 286 insertions, 1 deletions
diff --git a/tests/com/iciql/test/IciqlSuite.java b/tests/com/iciql/test/IciqlSuite.java
index 000b1c8..68156f8 100644
--- a/tests/com/iciql/test/IciqlSuite.java
+++ b/tests/com/iciql/test/IciqlSuite.java
@@ -60,6 +60,10 @@ import com.iciql.test.models.Product;
import com.iciql.test.models.ProductAnnotationOnly;
import com.iciql.test.models.ProductInheritedAnnotation;
import com.iciql.test.models.ProductMixedAnnotation;
+import com.iciql.test.models.ProductView;
+import com.iciql.test.models.ProductViewFromQuery;
+import com.iciql.test.models.ProductViewInherited;
+import com.iciql.test.models.ProductViewInheritedComplex;
import com.iciql.test.models.SupportedTypes;
import com.iciql.util.IciqlLogger;
import com.iciql.util.IciqlLogger.IciqlListener;
@@ -85,7 +89,7 @@ import com.iciql.util.Utils;
@SuiteClasses({ AliasMapTest.class, AnnotationsTest.class, BooleanModelTest.class, ClobTest.class,
ConcurrencyTest.class, EnumsTest.class, ModelsTest.class, PrimitivesTest.class,
RuntimeQueryTest.class, SamplesTest.class, UpdateTest.class, UpgradesTest.class, JoinTest.class,
- UUIDTest.class })
+ UUIDTest.class, ViewsTest.class })
public class IciqlSuite {
private static final TestDb[] TEST_DBS = {
@@ -155,6 +159,12 @@ public class IciqlSuite {
}
db = Db.open(dataSource);
+ // drop views
+ db.dropView(ProductView.class);
+ db.dropView(ProductViewInherited.class);
+ db.dropView(ProductViewFromQuery.class);
+ db.dropView(ProductViewInheritedComplex.class);
+
// drop tables
db.dropTable(BooleanModel.class);
db.dropTable(ComplexObject.class);
diff --git a/tests/com/iciql/test/ViewsTest.java b/tests/com/iciql/test/ViewsTest.java
new file mode 100644
index 0000000..be2e085
--- /dev/null
+++ b/tests/com/iciql/test/ViewsTest.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2012 James Moger.
+ *
+ * Licensed 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 com.iciql.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.iciql.Db;
+import com.iciql.test.models.ProductAnnotationOnly;
+import com.iciql.test.models.ProductView;
+import com.iciql.test.models.ProductViewFromQuery;
+import com.iciql.test.models.ProductViewInherited;
+import com.iciql.test.models.ProductViewInheritedComplex;
+import com.mysql.jdbc.StringUtils;
+
+/**
+ * Test annotation processing.
+ */
+public class ViewsTest {
+
+ /**
+ * This object represents a database (actually a connection to the
+ * database).
+ */
+
+ private Db db;
+
+ @Before
+ public void setUp() {
+ db = IciqlSuite.openNewDb();
+ db.insertAll(ProductAnnotationOnly.getList());
+ }
+
+ @After
+ public void tearDown() {
+ db.close();
+ }
+
+ @Test
+ public void testProductView() {
+ ProductView view = new ProductView();
+ List<ProductView> products = db.from(view).select();
+ assertEquals(5, products.size());
+ for (int i = 0; i < products.size(); i++) {
+ assertEquals(3 + i, products.get(i).productId.intValue());
+ }
+ }
+
+ @Test
+ public void testProductViewInherited() {
+ ProductViewInherited view = new ProductViewInherited();
+ List<ProductViewInherited> products = db.from(view).select();
+ assertEquals(5, products.size());
+ for (int i = 0; i < products.size(); i++) {
+ assertEquals(3 + i, products.get(i).productId.intValue());
+ }
+ }
+
+ @Test
+ public void testComplexInheritance() {
+ ProductViewInheritedComplex view = new ProductViewInheritedComplex();
+ List<ProductViewInheritedComplex> products = db.from(view).select();
+ assertEquals(5, products.size());
+ for (int i = 0; i < products.size(); i++) {
+ assertEquals(3 + i, products.get(i).productId.intValue());
+ assertTrue(!StringUtils.isNullOrEmpty(products.get(i).productName));
+ }
+ }
+
+ @Test
+ public void testCreateViewFromQuery() {
+ // create view from query
+ ProductAnnotationOnly product = new ProductAnnotationOnly();
+ db.from(product).where(product.productId).exceeds(2L).and(product.productId).atMost(7L).createView(ProductViewFromQuery.class);
+
+ // select from the created view
+ ProductViewFromQuery view = new ProductViewFromQuery();
+ List<ProductViewFromQuery> products = db.from(view).select();
+ assertEquals(5, products.size());
+ for (int i = 0; i < products.size(); i++) {
+ assertEquals(3 + i, products.get(i).productId.intValue());
+ }
+
+ // replace the view
+ db.from(product).where(product.productId).exceeds(3L).and(product.productId).atMost(8L).replaceView(ProductViewFromQuery.class);
+
+ // select from the replaced view
+ products = db.from(view).select();
+ assertEquals(5, products.size());
+ for (int i = 0; i < products.size(); i++) {
+ assertEquals(4 + i, products.get(i).productId.intValue());
+ }
+ }
+}
diff --git a/tests/com/iciql/test/models/ProductView.java b/tests/com/iciql/test/models/ProductView.java
new file mode 100644
index 0000000..2efe9eb
--- /dev/null
+++ b/tests/com/iciql/test/models/ProductView.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012 James Moger.
+ *
+ * Licensed 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 com.iciql.test.models;
+
+import com.iciql.Iciql.IQColumn;
+import com.iciql.Iciql.IQConstraint;
+import com.iciql.Iciql.IQView;
+
+/**
+ * A view containing product data.
+ */
+
+@IQView(name = "AnnotatedProductView", tableName = "AnnotatedProduct")
+public class ProductView {
+
+ public String unmappedField;
+
+ @IQColumn(name = "id", autoIncrement = true)
+ @IQConstraint("this <= 7 AND this > 2")
+ public Long productId;
+
+ @IQColumn(name = "name")
+ public String productName;
+
+ public ProductView() {
+ // public constructor
+ }
+
+ public String toString() {
+ return productName + " (" + productId + ")";
+ }
+
+}
diff --git a/tests/com/iciql/test/models/ProductViewFromQuery.java b/tests/com/iciql/test/models/ProductViewFromQuery.java
new file mode 100644
index 0000000..2f2f194
--- /dev/null
+++ b/tests/com/iciql/test/models/ProductViewFromQuery.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012 James Moger.
+ *
+ * Licensed 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 com.iciql.test.models;
+
+import com.iciql.Iciql.IQColumn;
+import com.iciql.Iciql.IQView;
+
+/**
+ * A view containing product data.
+ */
+
+@IQView(name = "AnnotatedProductViewInherited", inheritColumns = true)
+public class ProductViewFromQuery extends ProductAnnotationOnly {
+
+ public String unmappedField;
+
+ @IQColumn(name = "id")
+ public Long productId;
+
+ public ProductViewFromQuery() {
+ // public constructor
+ }
+
+ public String toString() {
+ return productName + " (" + productId + ")";
+ }
+
+}
diff --git a/tests/com/iciql/test/models/ProductViewInherited.java b/tests/com/iciql/test/models/ProductViewInherited.java
new file mode 100644
index 0000000..e9c274b
--- /dev/null
+++ b/tests/com/iciql/test/models/ProductViewInherited.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2012 James Moger.
+ *
+ * Licensed 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 com.iciql.test.models;
+
+import com.iciql.Iciql.IQColumn;
+import com.iciql.Iciql.IQConstraint;
+import com.iciql.Iciql.IQView;
+
+/**
+ * A view containing product data.
+ */
+
+@IQView(name = "AnnotatedProductViewInherited", inheritColumns = true)
+public class ProductViewInherited extends ProductAnnotationOnly {
+
+ public String unmappedField;
+
+ @IQColumn(name = "id", autoIncrement = true)
+ @IQConstraint("this <= 7 AND this > 2")
+ public Long productId;
+
+ public ProductViewInherited() {
+ // public constructor
+ }
+
+ public String toString() {
+ return productName + " (" + productId + ")";
+ }
+
+}
diff --git a/tests/com/iciql/test/models/ProductViewInheritedComplex.java b/tests/com/iciql/test/models/ProductViewInheritedComplex.java
new file mode 100644
index 0000000..55e7ba8
--- /dev/null
+++ b/tests/com/iciql/test/models/ProductViewInheritedComplex.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2012 James Moger.
+ *
+ * Licensed 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 com.iciql.test.models;
+
+import com.iciql.Iciql.IQView;
+
+/**
+ * A view containing product data.
+ */
+
+@IQView(inheritColumns = true)
+public class ProductViewInheritedComplex extends ProductViewInherited {
+
+}