You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2014/11/27 08:12:03 UTC
[20/39] cayenne git commit: re-categorizing Test vs IT
re-categorizing Test vs IT
* some test cases were misplaced
* some no longer require "_InContext" qualifier in the name
Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/a0d54aba
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/a0d54aba
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/a0d54aba
Branch: refs/heads/CAY-1946_1
Commit: a0d54aba704c3dee919fb2980db6f7fd0666ccd1
Parents: 7aeba71
Author: aadamchik <aa...@apache.org>
Authored: Sat Nov 22 17:35:06 2014 +0300
Committer: aadamchik <aa...@apache.org>
Committed: Sat Nov 22 17:36:05 2014 +0300
----------------------------------------------------------------------
.../apache/cayenne/exp/ExpressionFactoryIT.java | 106 ++++++
.../cayenne/exp/ExpressionFactoryTest.java | 250 ++++++++++++-
.../exp/ExpressionFactory_InContextIT.java | 354 -------------------
.../org/apache/cayenne/exp/ExpressionIT.java | 128 +++++++
.../cayenne/exp/Expression_InContextIT.java | 128 -------
5 files changed, 470 insertions(+), 496 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cayenne/blob/a0d54aba/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryIT.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryIT.java
new file mode 100644
index 0000000..c03b998
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryIT.java
@@ -0,0 +1,106 @@
+/*****************************************************************
+ * 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.cayenne.exp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.CayenneProjects;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.junit.Test;
+
+@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
+public class ExpressionFactoryIT extends ServerCase {
+
+ @Inject
+ private ObjectContext context;
+
+ // CAY-416
+ @Test
+ public void testCollectionMatch() {
+ Artist artist = context.newObject(Artist.class);
+ artist.setArtistName("artist");
+ Painting p1 = context.newObject(Painting.class), p2 = context.newObject(Painting.class), p3 = context
+ .newObject(Painting.class);
+ p1.setPaintingTitle("p1");
+ p2.setPaintingTitle("p2");
+ p3.setPaintingTitle("p3");
+ artist.addToPaintingArray(p1);
+ artist.addToPaintingArray(p2);
+
+ context.commitChanges();
+
+ assertTrue(ExpressionFactory.matchExp("paintingArray", p1).match(artist));
+ assertFalse(ExpressionFactory.matchExp("paintingArray", p3).match(artist));
+ assertFalse(ExpressionFactory.noMatchExp("paintingArray", p1).match(artist));
+ assertTrue(ExpressionFactory.noMatchExp("paintingArray", p3).match(artist));
+
+ assertTrue(ExpressionFactory.matchExp("paintingArray.paintingTitle", "p1").match(artist));
+ assertFalse(ExpressionFactory.matchExp("paintingArray.paintingTitle", "p3").match(artist));
+ assertFalse(ExpressionFactory.noMatchExp("paintingArray.paintingTitle", "p1").match(artist));
+ assertTrue(ExpressionFactory.noMatchExp("paintingArray.paintingTitle", "p3").match(artist));
+
+ assertTrue(ExpressionFactory.inExp("paintingTitle", "p1").match(p1));
+ assertFalse(ExpressionFactory.notInExp("paintingTitle", "p3").match(p3));
+ }
+
+ @Test
+ public void testIn() {
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("a1");
+ Painting p1 = context.newObject(Painting.class);
+ p1.setPaintingTitle("p1");
+ Painting p2 = context.newObject(Painting.class);
+ p2.setPaintingTitle("p2");
+ a1.addToPaintingArray(p1);
+ a1.addToPaintingArray(p2);
+
+ Expression in = ExpressionFactory.inExp("paintingArray", p1);
+ assertTrue(in.match(a1));
+ }
+
+ @Test
+ public void testEscapeCharacter() {
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("A_1");
+ Artist a2 = context.newObject(Artist.class);
+ a2.setArtistName("A_2");
+ context.commitChanges();
+
+ Expression ex1 = ExpressionFactory.likeIgnoreCaseDbExp("ARTIST_NAME", "A*_1", '*');
+ SelectQuery<Artist> q1 = new SelectQuery<Artist>(Artist.class, ex1);
+ List<Artist> artists = context.select(q1);
+ assertEquals(1, artists.size());
+
+ Expression ex2 = ExpressionFactory.likeExp("artistName", "A*_2", '*');
+ SelectQuery<Artist> q2 = new SelectQuery<Artist>(Artist.class, ex2);
+ artists = context.select(q2);
+ assertEquals(1, artists.size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/a0d54aba/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
index d52548c..5c41ff1 100644
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactoryTest.java
@@ -28,8 +28,11 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
+import org.apache.cayenne.exp.parser.ASTLike;
+import org.apache.cayenne.exp.parser.ASTLikeIgnoreCase;
import org.junit.Before;
import org.junit.Test;
@@ -42,6 +45,232 @@ public class ExpressionFactoryTest {
handler = new TstTraversalHandler();
}
+ @Test(expected = ExpressionException.class)
+ public void testExpressionOfBadType() throws Exception {
+ // non existing type
+ int badType = -50;
+ ExpressionFactory.expressionOfType(badType);
+ }
+
+ @Test
+ public void testBetweenExp() throws Exception {
+ Object v1 = new Object();
+ Object v2 = new Object();
+ Expression exp = ExpressionFactory.betweenExp("abc", v1, v2);
+ assertEquals(Expression.BETWEEN, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.OBJ_PATH, path.getType());
+ }
+
+ @Test
+ public void testBetweenDbExp() throws Exception {
+ Object v1 = new Object();
+ Object v2 = new Object();
+ Expression exp = ExpressionFactory.betweenDbExp("abc", v1, v2);
+ assertEquals(Expression.BETWEEN, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.DB_PATH, path.getType());
+ }
+
+ @Test
+ public void testNotBetweenExp() throws Exception {
+ Object v1 = new Object();
+ Object v2 = new Object();
+ Expression exp = ExpressionFactory.notBetweenExp("abc", v1, v2);
+ assertEquals(Expression.NOT_BETWEEN, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.OBJ_PATH, path.getType());
+ }
+
+ @Test
+ public void testNotBetweenDbExp() throws Exception {
+ Object v1 = new Object();
+ Object v2 = new Object();
+ Expression exp = ExpressionFactory.notBetweenDbExp("abc", v1, v2);
+ assertEquals(Expression.NOT_BETWEEN, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.DB_PATH, path.getType());
+ }
+
+ @Test
+ public void testGreaterExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.greaterExp("abc", v);
+ assertEquals(Expression.GREATER_THAN, exp.getType());
+ }
+
+ @Test
+ public void testGreaterDbExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.greaterDbExp("abc", v);
+ assertEquals(Expression.GREATER_THAN, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.DB_PATH, path.getType());
+ }
+
+ @Test
+ public void testGreaterOrEqualExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.greaterOrEqualExp("abc", v);
+ assertEquals(Expression.GREATER_THAN_EQUAL_TO, exp.getType());
+ }
+
+ @Test
+ public void testGreaterOrEqualDbExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.greaterOrEqualDbExp("abc", v);
+ assertEquals(Expression.GREATER_THAN_EQUAL_TO, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.DB_PATH, path.getType());
+ }
+
+ @Test
+ public void testLessExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.lessExp("abc", v);
+ assertEquals(Expression.LESS_THAN, exp.getType());
+ }
+
+ @Test
+ public void testLessDbExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.lessDbExp("abc", v);
+ assertEquals(Expression.LESS_THAN, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.DB_PATH, path.getType());
+ }
+
+ @Test
+ public void testLessOrEqualExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.lessOrEqualExp("abc", v);
+ assertEquals(Expression.LESS_THAN_EQUAL_TO, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.OBJ_PATH, path.getType());
+ }
+
+ @Test
+ public void testLessOrEqualDbExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.lessOrEqualDbExp("abc", v);
+ assertEquals(Expression.LESS_THAN_EQUAL_TO, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.DB_PATH, path.getType());
+ }
+
+ @Test
+ public void testInExp1() throws Exception {
+ Expression exp = ExpressionFactory.inExp("abc", "a", "b");
+ assertEquals(Expression.IN, exp.getType());
+ }
+
+ @Test
+ public void testInExp2() throws Exception {
+ List<Object> v = new ArrayList<Object>();
+ v.add("a");
+ v.add("b");
+ Expression exp = ExpressionFactory.inExp("abc", v);
+ assertEquals(Expression.IN, exp.getType());
+ }
+
+ @Test
+ public void testInExp3() throws Exception {
+ List<Object> v = new ArrayList<Object>();
+ Expression exp = ExpressionFactory.inExp("abc", v);
+ assertEquals(Expression.FALSE, exp.getType());
+ }
+
+ @Test
+ public void testLikeExp() throws Exception {
+ String v = "abc";
+ Expression exp = ExpressionFactory.likeExp("abc", v);
+ assertEquals(Expression.LIKE, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.OBJ_PATH, path.getType());
+ }
+
+ @Test
+ public void testLikeDbExp() throws Exception {
+ String v = "abc";
+ Expression exp = ExpressionFactory.likeDbExp("abc", v);
+ assertEquals(Expression.LIKE, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.DB_PATH, path.getType());
+ }
+
+ @Test
+ public void testLikeExpEscape() throws Exception {
+ String v = "abc";
+ Expression exp = ExpressionFactory.likeExp("=abc", v, '=');
+ assertEquals(Expression.LIKE, exp.getType());
+
+ assertEquals('=', ((ASTLike) exp).getEscapeChar());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.OBJ_PATH, path.getType());
+ }
+
+ @Test
+ public void testLikeIgnoreCaseExp() throws Exception {
+ String v = "abc";
+ Expression exp = ExpressionFactory.likeIgnoreCaseExp("abc", v);
+ assertEquals(Expression.LIKE_IGNORE_CASE, exp.getType());
+ assertEquals(0, ((ASTLikeIgnoreCase) exp).getEscapeChar());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.OBJ_PATH, path.getType());
+ }
+
+ @Test
+ public void testLikeIgnoreCaseExpEscape() throws Exception {
+ String v = "abc";
+ Expression exp = ExpressionFactory.likeIgnoreCaseExp("=abc", v, '=');
+ assertEquals(Expression.LIKE_IGNORE_CASE, exp.getType());
+ assertEquals('=', ((ASTLikeIgnoreCase) exp).getEscapeChar());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.OBJ_PATH, path.getType());
+ }
+
+ @Test
+ public void testLikeIgnoreCaseDbExp() throws Exception {
+ String v = "abc";
+ Expression exp = ExpressionFactory.likeIgnoreCaseDbExp("abc", v);
+ assertEquals(Expression.LIKE_IGNORE_CASE, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.DB_PATH, path.getType());
+ }
+
+ @Test
+ public void testNotLikeIgnoreCaseExp() throws Exception {
+ String v = "abc";
+ Expression exp = ExpressionFactory.notLikeIgnoreCaseExp("abc", v);
+ assertEquals(Expression.NOT_LIKE_IGNORE_CASE, exp.getType());
+ }
+
+ // testing CAY-941 bug
+ @Test
+ public void testLikeExpNull() throws Exception {
+ Expression exp = ExpressionFactory.likeExp("abc", null);
+ assertEquals(Expression.LIKE, exp.getType());
+
+ Expression path = (Expression) exp.getOperand(0);
+ assertEquals(Expression.OBJ_PATH, path.getType());
+ assertNull(exp.getOperand(1));
+ }
+
@Test
public void testMatchAllExp() throws Exception {
// create expressions and check the counts,
@@ -59,16 +288,14 @@ public class ExpressionFactoryTest {
map.put("k" + i, "v" + i);
}
- Expression exp = ExpressionFactory.matchAllExp(map,
- Expression.LESS_THAN);
+ Expression exp = ExpressionFactory.matchAllExp(map, Expression.LESS_THAN);
assertNotNull(exp);
handler.traverseExpression(exp);
// assert statistics
handler.assertConsistency();
assertEquals("Failed: " + exp, 2 * n, handler.getLeafs());
- assertEquals("Failed: " + exp, n < 2 ? 2 * n : 2 * n + 1,
- handler.getNodeCount());
+ assertEquals("Failed: " + exp, n < 2 ? 2 * n : 2 * n + 1, handler.getNodeCount());
}
}
@@ -95,8 +322,7 @@ public class ExpressionFactoryTest {
// assert statistics
handler.assertConsistency();
assertEquals("Failed: " + exp, 2 * n, handler.getLeafs());
- assertEquals("Failed: " + exp, n > 1 ? 2 * n + 1 : 2 * n,
- handler.getNodeCount());
+ assertEquals("Failed: " + exp, n > 1 ? 2 * n + 1 : 2 * n, handler.getNodeCount());
}
}
@@ -125,8 +351,7 @@ public class ExpressionFactoryTest {
@Test
public void testAnd_Collection_Empty() {
- Expression e = ExpressionFactory.and(Collections
- .<Expression> emptyList());
+ Expression e = ExpressionFactory.and(Collections.<Expression> emptyList());
// hmm... is this really a valid return value?
assertNull(e);
@@ -211,16 +436,13 @@ public class ExpressionFactoryTest {
@Test
public void testExp_Enum() {
- Expression e1 = ExpressionFactory
- .exp("a = enum:org.apache.cayenne.exp.ExpEnum1.ONE");
+ Expression e1 = ExpressionFactory.exp("a = enum:org.apache.cayenne.exp.ExpEnum1.ONE");
assertEquals(ExpEnum1.ONE, e1.getOperand(1));
- Expression e2 = ExpressionFactory
- .exp("a = enum:org.apache.cayenne.exp.ExpEnum1.TWO");
+ Expression e2 = ExpressionFactory.exp("a = enum:org.apache.cayenne.exp.ExpEnum1.TWO");
assertEquals(ExpEnum1.TWO, e2.getOperand(1));
- Expression e3 = ExpressionFactory
- .exp("a = enum:org.apache.cayenne.exp.ExpEnum1.THREE");
+ Expression e3 = ExpressionFactory.exp("a = enum:org.apache.cayenne.exp.ExpEnum1.THREE");
assertEquals(ExpEnum1.THREE, e3.getOperand(1));
}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/a0d54aba/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactory_InContextIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactory_InContextIT.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactory_InContextIT.java
deleted file mode 100644
index fa39d6d..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactory_InContextIT.java
+++ /dev/null
@@ -1,354 +0,0 @@
-/*****************************************************************
- * 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.cayenne.exp;
-
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.parser.ASTLike;
-import org.apache.cayenne.exp.parser.ASTLikeIgnoreCase;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.di.server.CayenneProjects;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
-public class ExpressionFactory_InContextIT extends ServerCase {
-
- @Inject
- private ObjectContext context;
-
- @Test
- public void testExpressionOfBadType() throws Exception {
-
- // non existing type
- int badType = -50;
-
- try {
- ExpressionFactory.expressionOfType(badType);
- fail();
- } catch (ExpressionException ex) {
- // exception expected
- }
- }
-
- @Test
- public void testBetweenExp() throws Exception {
- Object v1 = new Object();
- Object v2 = new Object();
- Expression exp = ExpressionFactory.betweenExp("abc", v1, v2);
- assertEquals(Expression.BETWEEN, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.OBJ_PATH, path.getType());
- }
-
- @Test
- public void testBetweenDbExp() throws Exception {
- Object v1 = new Object();
- Object v2 = new Object();
- Expression exp = ExpressionFactory.betweenDbExp("abc", v1, v2);
- assertEquals(Expression.BETWEEN, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.DB_PATH, path.getType());
- }
-
- @Test
- public void testNotBetweenExp() throws Exception {
- Object v1 = new Object();
- Object v2 = new Object();
- Expression exp = ExpressionFactory.notBetweenExp("abc", v1, v2);
- assertEquals(Expression.NOT_BETWEEN, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.OBJ_PATH, path.getType());
- }
-
- @Test
- public void testNotBetweenDbExp() throws Exception {
- Object v1 = new Object();
- Object v2 = new Object();
- Expression exp = ExpressionFactory.notBetweenDbExp("abc", v1, v2);
- assertEquals(Expression.NOT_BETWEEN, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.DB_PATH, path.getType());
- }
-
- @Test
- public void testGreaterExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.greaterExp("abc", v);
- assertEquals(Expression.GREATER_THAN, exp.getType());
- }
-
- @Test
- public void testGreaterDbExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.greaterDbExp("abc", v);
- assertEquals(Expression.GREATER_THAN, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.DB_PATH, path.getType());
- }
-
- @Test
- public void testGreaterOrEqualExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.greaterOrEqualExp("abc", v);
- assertEquals(Expression.GREATER_THAN_EQUAL_TO, exp.getType());
- }
-
- @Test
- public void testGreaterOrEqualDbExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.greaterOrEqualDbExp("abc", v);
- assertEquals(Expression.GREATER_THAN_EQUAL_TO, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.DB_PATH, path.getType());
- }
-
- @Test
- public void testLessExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.lessExp("abc", v);
- assertEquals(Expression.LESS_THAN, exp.getType());
- }
-
- @Test
- public void testLessDbExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.lessDbExp("abc", v);
- assertEquals(Expression.LESS_THAN, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.DB_PATH, path.getType());
- }
-
- @Test
- public void testLessOrEqualExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.lessOrEqualExp("abc", v);
- assertEquals(Expression.LESS_THAN_EQUAL_TO, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.OBJ_PATH, path.getType());
- }
-
- @Test
- public void testLessOrEqualDbExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.lessOrEqualDbExp("abc", v);
- assertEquals(Expression.LESS_THAN_EQUAL_TO, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.DB_PATH, path.getType());
- }
-
- @Test
- public void testInExp1() throws Exception {
- Expression exp = ExpressionFactory.inExp("abc", "a", "b");
- assertEquals(Expression.IN, exp.getType());
- }
-
- @Test
- public void testInExp2() throws Exception {
- List<Object> v = new ArrayList<Object>();
- v.add("a");
- v.add("b");
- Expression exp = ExpressionFactory.inExp("abc", v);
- assertEquals(Expression.IN, exp.getType());
- }
-
- @Test
- public void testInExp3() throws Exception {
- List<Object> v = new ArrayList<Object>();
- Expression exp = ExpressionFactory.inExp("abc", v);
- assertEquals(Expression.FALSE, exp.getType());
- }
-
- @Test
- public void testLikeExp() throws Exception {
- String v = "abc";
- Expression exp = ExpressionFactory.likeExp("abc", v);
- assertEquals(Expression.LIKE, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.OBJ_PATH, path.getType());
- }
-
- @Test
- public void testLikeDbExp() throws Exception {
- String v = "abc";
- Expression exp = ExpressionFactory.likeDbExp("abc", v);
- assertEquals(Expression.LIKE, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.DB_PATH, path.getType());
- }
-
- @Test
- public void testLikeExpEscape() throws Exception {
- String v = "abc";
- Expression exp = ExpressionFactory.likeExp("=abc", v, '=');
- assertEquals(Expression.LIKE, exp.getType());
-
- assertEquals('=', ((ASTLike) exp).getEscapeChar());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.OBJ_PATH, path.getType());
- }
-
- @Test
- public void testLikeIgnoreCaseExp() throws Exception {
- String v = "abc";
- Expression exp = ExpressionFactory.likeIgnoreCaseExp("abc", v);
- assertEquals(Expression.LIKE_IGNORE_CASE, exp.getType());
- assertEquals(0, ((ASTLikeIgnoreCase) exp).getEscapeChar());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.OBJ_PATH, path.getType());
- }
-
- @Test
- public void testLikeIgnoreCaseExpEscape() throws Exception {
- String v = "abc";
- Expression exp = ExpressionFactory.likeIgnoreCaseExp("=abc", v, '=');
- assertEquals(Expression.LIKE_IGNORE_CASE, exp.getType());
- assertEquals('=', ((ASTLikeIgnoreCase) exp).getEscapeChar());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.OBJ_PATH, path.getType());
- }
-
- @Test
- public void testLikeIgnoreCaseDbExp() throws Exception {
- String v = "abc";
- Expression exp = ExpressionFactory.likeIgnoreCaseDbExp("abc", v);
- assertEquals(Expression.LIKE_IGNORE_CASE, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.DB_PATH, path.getType());
- }
-
- @Test
- public void testNotLikeIgnoreCaseExp() throws Exception {
- String v = "abc";
- Expression exp = ExpressionFactory.notLikeIgnoreCaseExp("abc", v);
- assertEquals(Expression.NOT_LIKE_IGNORE_CASE, exp.getType());
- }
-
- // testing CAY-941 bug
- @Test
- public void testLikeExpNull() throws Exception {
- Expression exp = ExpressionFactory.likeExp("abc", null);
- assertEquals(Expression.LIKE, exp.getType());
-
- Expression path = (Expression) exp.getOperand(0);
- assertEquals(Expression.OBJ_PATH, path.getType());
- assertNull(exp.getOperand(1));
- }
-
- // CAY-416
- @Test
- public void testCollectionMatch() {
- Artist artist = context.newObject(Artist.class);
- artist.setArtistName("artist");
- Painting p1 = context.newObject(Painting.class), p2 = context
- .newObject(Painting.class), p3 = context
- .newObject(Painting.class);
- p1.setPaintingTitle("p1");
- p2.setPaintingTitle("p2");
- p3.setPaintingTitle("p3");
- artist.addToPaintingArray(p1);
- artist.addToPaintingArray(p2);
-
- context.commitChanges();
-
- assertTrue(ExpressionFactory.matchExp("paintingArray", p1)
- .match(artist));
- assertFalse(ExpressionFactory.matchExp("paintingArray", p3).match(
- artist));
- assertFalse(ExpressionFactory.noMatchExp("paintingArray", p1).match(
- artist));
- assertTrue(ExpressionFactory.noMatchExp("paintingArray", p3).match(
- artist));
-
- assertTrue(ExpressionFactory.matchExp("paintingArray.paintingTitle",
- "p1").match(artist));
- assertFalse(ExpressionFactory.matchExp("paintingArray.paintingTitle",
- "p3").match(artist));
- assertFalse(ExpressionFactory.noMatchExp("paintingArray.paintingTitle",
- "p1").match(artist));
- assertTrue(ExpressionFactory.noMatchExp("paintingArray.paintingTitle",
- "p3").match(artist));
-
- assertTrue(ExpressionFactory.inExp("paintingTitle", "p1").match(p1));
- assertFalse(ExpressionFactory.notInExp("paintingTitle", "p3").match(p3));
- }
-
- @Test
- public void testIn() {
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("a1");
- Painting p1 = context.newObject(Painting.class);
- p1.setPaintingTitle("p1");
- Painting p2 = context.newObject(Painting.class);
- p2.setPaintingTitle("p2");
- a1.addToPaintingArray(p1);
- a1.addToPaintingArray(p2);
-
- Expression in = ExpressionFactory.inExp("paintingArray", p1);
- assertTrue(in.match(a1));
- }
-
- @Test
- public void testEscapeCharacter() {
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("A_1");
- Artist a2 = context.newObject(Artist.class);
- a2.setArtistName("A_2");
- context.commitChanges();
-
- Expression ex1 = ExpressionFactory.likeIgnoreCaseDbExp("ARTIST_NAME",
- "A*_1", '*');
- SelectQuery<Artist> q1 = new SelectQuery<Artist>(Artist.class, ex1);
- List<Artist> artists = context.select(q1);
- assertEquals(1, artists.size());
-
- Expression ex2 = ExpressionFactory.likeExp("artistName", "A*_2", '*');
- SelectQuery<Artist> q2 = new SelectQuery<Artist>(Artist.class, ex2);
- artists = context.select(q2);
- assertEquals(1, artists.size());
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/a0d54aba/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionIT.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionIT.java
new file mode 100644
index 0000000..b2d8749
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionIT.java
@@ -0,0 +1,128 @@
+/*****************************************************************
+ * 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.cayenne.exp;
+
+import org.apache.cayenne.ObjectContext;
+import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.CayenneProjects;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
+public class ExpressionIT extends ServerCase {
+
+ @Inject
+ private ObjectContext context;
+
+ @Inject
+ private ServerRuntime runtime;
+
+ @Test
+ public void testMatch() {
+
+ assertTrue(context instanceof DataContext);
+
+ DataContext context2 = (DataContext) runtime.newContext();
+
+ Artist a1 = context.newObject(Artist.class);
+ a1.setArtistName("Equals");
+ Painting p1 = context.newObject(Painting.class);
+ p1.setToArtist(a1);
+ p1.setPaintingTitle("painting1");
+
+ context.commitChanges();
+
+ SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
+ Expression e = Painting.TO_ARTIST.eq(a1);
+ query.setQualifier(e);
+
+ assertNotSame(context2, context);
+
+ List<Painting> objects = context2.select(query);
+ assertEquals(1, objects.size());
+
+ // 2 same objects in different contexts
+ assertTrue(e.match(objects.get(0)));
+
+ // we change one object - so the objects are different now
+ // (PersistenceState different)
+ a1.setArtistName("newName");
+
+ SelectQuery<Painting> q2 = new SelectQuery<Painting>(Painting.class);
+ Expression ex2 = Painting.TO_ARTIST.eq(a1);
+ q2.setQualifier(ex2);
+
+ assertTrue(ex2.match(objects.get(0)));
+
+ Artist a2 = context.newObject(Artist.class);
+ a2.setArtistName("Equals");
+
+ context.commitChanges();
+
+ SelectQuery<Painting> q = new SelectQuery<Painting>(Painting.class);
+ Expression ex = Painting.TO_ARTIST.eq(a2);
+ q.setQualifier(ex);
+
+ // 2 different objects in different contexts
+ assertFalse(ex.match(objects.get(0)));
+ }
+
+ @Test
+ public void testFirst() {
+ List<Painting> paintingList = new ArrayList<Painting>();
+ Painting p1 = context.newObject(Painting.class);
+ p1.setPaintingTitle("x1");
+ paintingList.add(p1);
+
+ Painting p2 = context.newObject(Painting.class);
+ p2.setPaintingTitle("x2");
+ paintingList.add(p2);
+
+ Painting p3 = context.newObject(Painting.class);
+ p3.setPaintingTitle("x3");
+ paintingList.add(p3);
+
+ Expression e1 = ExpressionFactory.likeExp("paintingTitle", "x%");
+ assertSame(p1, e1.first(paintingList));
+
+ Expression e3 = ExpressionFactory.matchExp("paintingTitle", "x3");
+ assertSame(p3, e3.first(paintingList));
+
+ Expression e4 = ExpressionFactory.matchExp("paintingTitle", "x4");
+ assertNull(e4.first(paintingList));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/a0d54aba/cayenne-server/src/test/java/org/apache/cayenne/exp/Expression_InContextIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/Expression_InContextIT.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/Expression_InContextIT.java
deleted file mode 100644
index fc7e0bf..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/Expression_InContextIT.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*****************************************************************
- * 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.cayenne.exp;
-
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.di.server.CayenneProjects;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-
-@UseServerRuntime(CayenneProjects.TESTMAP_PROJECT)
-public class Expression_InContextIT extends ServerCase {
-
- @Inject
- private ObjectContext context;
-
- @Inject
- private ServerRuntime runtime;
-
- @Test
- public void testMatch() {
-
- assertTrue(context instanceof DataContext);
-
- DataContext context2 = (DataContext) runtime.newContext();
-
- Artist a1 = context.newObject(Artist.class);
- a1.setArtistName("Equals");
- Painting p1 = context.newObject(Painting.class);
- p1.setToArtist(a1);
- p1.setPaintingTitle("painting1");
-
- context.commitChanges();
-
- SelectQuery<Painting> query = new SelectQuery<Painting>(Painting.class);
- Expression e = Painting.TO_ARTIST.eq(a1);
- query.setQualifier(e);
-
- assertNotSame(context2, context);
-
- List<Painting> objects = context2.select(query);
- assertEquals(1, objects.size());
-
- // 2 same objects in different contexts
- assertTrue(e.match(objects.get(0)));
-
- // we change one object - so the objects are different now
- // (PersistenceState different)
- a1.setArtistName("newName");
-
- SelectQuery<Painting> q2 = new SelectQuery<Painting>(Painting.class);
- Expression ex2 = Painting.TO_ARTIST.eq(a1);
- q2.setQualifier(ex2);
-
- assertTrue(ex2.match(objects.get(0)));
-
- Artist a2 = context.newObject(Artist.class);
- a2.setArtistName("Equals");
-
- context.commitChanges();
-
- SelectQuery<Painting> q = new SelectQuery<Painting>(Painting.class);
- Expression ex = Painting.TO_ARTIST.eq(a2);
- q.setQualifier(ex);
-
- // 2 different objects in different contexts
- assertFalse(ex.match(objects.get(0)));
- }
-
- @Test
- public void testFirst() {
- List<Painting> paintingList = new ArrayList<Painting>();
- Painting p1 = context.newObject(Painting.class);
- p1.setPaintingTitle("x1");
- paintingList.add(p1);
-
- Painting p2 = context.newObject(Painting.class);
- p2.setPaintingTitle("x2");
- paintingList.add(p2);
-
- Painting p3 = context.newObject(Painting.class);
- p3.setPaintingTitle("x3");
- paintingList.add(p3);
-
- Expression e1 = ExpressionFactory.likeExp("paintingTitle", "x%");
- assertSame(p1, e1.first(paintingList));
-
- Expression e3 = ExpressionFactory.matchExp("paintingTitle", "x3");
- assertSame(p3, e3.first(paintingList));
-
- Expression e4 = ExpressionFactory.matchExp("paintingTitle", "x4");
- assertNull(e4.first(paintingList));
- }
-
-}