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/02 08:09:58 UTC
[10/48] Installing Maven Failsafe Plugin
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/Oracle8AdapterIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/Oracle8AdapterIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/Oracle8AdapterIT.java
new file mode 100644
index 0000000..ff02f16
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/Oracle8AdapterIT.java
@@ -0,0 +1,59 @@
+/*****************************************************************
+ * 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.dba.oracle;
+
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.net.URL;
+import java.sql.Types;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class Oracle8AdapterIT extends ServerCase {
+
+ @Inject
+ private AdhocObjectFactory objectFactory;
+
+ public void testTimestampMapping() throws Exception {
+
+ Oracle8Adapter adapter = objectFactory.newInstance(
+ Oracle8Adapter.class,
+ Oracle8Adapter.class.getName());
+
+ String[] types = adapter.externalTypesForJdbcType(Types.TIMESTAMP);
+ assertNotNull(types);
+ assertEquals(1, types.length);
+ assertEquals("DATE", types[0]);
+ }
+
+ public void testFindAdapterResource() throws Exception {
+
+ Oracle8Adapter adapter = objectFactory.newInstance(
+ Oracle8Adapter.class,
+ Oracle8Adapter.class.getName());
+
+ URL typesURL = adapter.findResource("/types.xml");
+ assertNotNull(typesURL);
+ assertTrue("Unexpected url:" + typesURL, typesURL.toExternalForm().endsWith(
+ "types-oracle8.xml"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/Oracle8AdapterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/Oracle8AdapterTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/Oracle8AdapterTest.java
deleted file mode 100644
index 5848bc3..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/Oracle8AdapterTest.java
+++ /dev/null
@@ -1,59 +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.dba.oracle;
-
-import java.net.URL;
-import java.sql.Types;
-
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class Oracle8AdapterTest extends ServerCase {
-
- @Inject
- private AdhocObjectFactory objectFactory;
-
- public void testTimestampMapping() throws Exception {
-
- Oracle8Adapter adapter = objectFactory.newInstance(
- Oracle8Adapter.class,
- Oracle8Adapter.class.getName());
-
- String[] types = adapter.externalTypesForJdbcType(Types.TIMESTAMP);
- assertNotNull(types);
- assertEquals(1, types.length);
- assertEquals("DATE", types[0]);
- }
-
- public void testFindAdapterResource() throws Exception {
-
- Oracle8Adapter adapter = objectFactory.newInstance(
- Oracle8Adapter.class,
- Oracle8Adapter.class.getName());
-
- URL typesURL = adapter.findResource("/types.xml");
- assertNotNull(typesURL);
- assertTrue("Unexpected url:" + typesURL, typesURL.toExternalForm().endsWith(
- "types-oracle8.xml"));
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterIT.java
new file mode 100644
index 0000000..c471daa
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterIT.java
@@ -0,0 +1,62 @@
+/*****************************************************************
+ * 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.dba.oracle;
+
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.query.InsertBatchQuery;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class OracleAdapterIT extends ServerCase {
+
+ @Inject
+ private ServerRuntime runtime;
+
+ @Inject
+ private AdhocObjectFactory objectFactory;
+
+ public void testUpdatesLOBColumns() throws Exception {
+ DataMap map = runtime.getDataDomain().getDataMap("tstmap");
+ assertTrue(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map
+ .getDbEntity("BLOB_TEST"), 1)));
+ assertTrue(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map
+ .getDbEntity("CLOB_TEST"), 1)));
+ assertFalse(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map
+ .getDbEntity("ARTIST"), 1)));
+ }
+
+ public void testTimestampMapping() throws Exception {
+
+ OracleAdapter adapter = objectFactory.newInstance(
+ OracleAdapter.class,
+ OracleAdapter.class.getName());
+
+ String[] types = adapter.externalTypesForJdbcType(Types.TIMESTAMP);
+ assertNotNull(types);
+ assertEquals(1, types.length);
+ assertEquals("TIMESTAMP", types[0]);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterTest.java
deleted file mode 100644
index d501a77..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OracleAdapterTest.java
+++ /dev/null
@@ -1,62 +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.dba.oracle;
-
-import java.sql.Types;
-
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DataMap;
-import org.apache.cayenne.query.InsertBatchQuery;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class OracleAdapterTest extends ServerCase {
-
- @Inject
- private ServerRuntime runtime;
-
- @Inject
- private AdhocObjectFactory objectFactory;
-
- public void testUpdatesLOBColumns() throws Exception {
- DataMap map = runtime.getDataDomain().getDataMap("tstmap");
- assertTrue(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map
- .getDbEntity("BLOB_TEST"), 1)));
- assertTrue(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map
- .getDbEntity("CLOB_TEST"), 1)));
- assertFalse(OracleAdapter.updatesLOBColumns(new InsertBatchQuery(map
- .getDbEntity("ARTIST"), 1)));
- }
-
- public void testTimestampMapping() throws Exception {
-
- OracleAdapter adapter = objectFactory.newInstance(
- OracleAdapter.class,
- OracleAdapter.class.getName());
-
- String[] types = adapter.externalTypesForJdbcType(Types.TIMESTAMP);
- assertNotNull(types);
- assertEquals(1, types.length);
- assertEquals("TIMESTAMP", types[0]);
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OraclePkGeneratorIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OraclePkGeneratorIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OraclePkGeneratorIT.java
new file mode 100644
index 0000000..9000f76
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OraclePkGeneratorIT.java
@@ -0,0 +1,68 @@
+/*****************************************************************
+ * 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.dba.oracle;
+
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.log.JdbcEventLogger;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbKeyGenerator;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class OraclePkGeneratorIT extends ServerCase {
+
+ @Inject
+ protected JdbcEventLogger logger;
+
+ @Inject
+ protected AdhocObjectFactory objectFactory;
+
+ private OraclePkGenerator pkGenerator;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ OracleAdapter adapter = objectFactory.newInstance(OracleAdapter.class, OracleAdapter.class.getName());
+ pkGenerator = new OraclePkGenerator(adapter);
+ }
+
+ public void testSequenceNameDefault() throws Exception {
+ DbEntity entity = new DbEntity("TEST_ENTITY");
+ assertEquals("pk_test_entity", pkGenerator.sequenceName(entity));
+ }
+
+ public void testSequenceNameCustom1() throws Exception {
+ DbEntity entity = new DbEntity("TEST_ENTITY");
+ DbKeyGenerator customGenerator = new DbKeyGenerator();
+ customGenerator.setGeneratorType(DbKeyGenerator.ORACLE_TYPE);
+ customGenerator.setGeneratorName("CUSTOM_GENERATOR");
+ entity.setPrimaryKeyGenerator(customGenerator);
+ assertEquals("custom_generator", pkGenerator.sequenceName(entity));
+ }
+
+ public void testSequenceNameCustom2() throws Exception {
+ DbEntity entity = new DbEntity("TEST_ENTITY");
+ DbKeyGenerator customGenerator = new DbKeyGenerator();
+ customGenerator.setGeneratorType(DbKeyGenerator.NAMED_SEQUENCE_TABLE_TYPE);
+ customGenerator.setGeneratorName("CUSTOM_GENERATOR");
+ assertEquals("pk_test_entity", pkGenerator.sequenceName(entity));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OraclePkGeneratorTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OraclePkGeneratorTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OraclePkGeneratorTest.java
deleted file mode 100644
index 6115c9a..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/oracle/OraclePkGeneratorTest.java
+++ /dev/null
@@ -1,68 +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.dba.oracle;
-
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.log.JdbcEventLogger;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.DbKeyGenerator;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class OraclePkGeneratorTest extends ServerCase {
-
- @Inject
- protected JdbcEventLogger logger;
-
- @Inject
- protected AdhocObjectFactory objectFactory;
-
- private OraclePkGenerator pkGenerator;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- OracleAdapter adapter = objectFactory.newInstance(OracleAdapter.class, OracleAdapter.class.getName());
- pkGenerator = new OraclePkGenerator(adapter);
- }
-
- public void testSequenceNameDefault() throws Exception {
- DbEntity entity = new DbEntity("TEST_ENTITY");
- assertEquals("pk_test_entity", pkGenerator.sequenceName(entity));
- }
-
- public void testSequenceNameCustom1() throws Exception {
- DbEntity entity = new DbEntity("TEST_ENTITY");
- DbKeyGenerator customGenerator = new DbKeyGenerator();
- customGenerator.setGeneratorType(DbKeyGenerator.ORACLE_TYPE);
- customGenerator.setGeneratorName("CUSTOM_GENERATOR");
- entity.setPrimaryKeyGenerator(customGenerator);
- assertEquals("custom_generator", pkGenerator.sequenceName(entity));
- }
-
- public void testSequenceNameCustom2() throws Exception {
- DbEntity entity = new DbEntity("TEST_ENTITY");
- DbKeyGenerator customGenerator = new DbKeyGenerator();
- customGenerator.setGeneratorType(DbKeyGenerator.NAMED_SEQUENCE_TABLE_TYPE);
- customGenerator.setGeneratorName("CUSTOM_GENERATOR");
- assertEquals("pk_test_entity", pkGenerator.sequenceName(entity));
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/postgres/PostgresAdapterIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/postgres/PostgresAdapterIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/postgres/PostgresAdapterIT.java
new file mode 100644
index 0000000..ea00534
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/postgres/PostgresAdapterIT.java
@@ -0,0 +1,56 @@
+/*****************************************************************
+ * 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.dba.postgres;
+
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class PostgresAdapterIT extends ServerCase {
+
+ @Inject
+ private AdhocObjectFactory objectFactory;
+
+ public void testCreateTableWithFloatAttributeWithScale () {
+ PostgresAdapter adapter = objectFactory.newInstance(
+ PostgresAdapter.class,
+ PostgresAdapter.class.getName());
+ DbEntity e = new DbEntity("Test");
+ DbAttribute dblPrec = new DbAttribute("dbl1");
+ dblPrec.setType(Types.FLOAT);
+ dblPrec.setMaxLength(22);
+ dblPrec.setScale(12);
+ e.addAttribute(dblPrec);
+
+ String sql = adapter.createTable(e);
+
+ // CAY-1363.
+ // Postgress don't support notations float(a, b)
+ assertTrue(sql.indexOf("float(22)") > 0);
+ assertEquals(-1, sql.indexOf("float(22, 12)"));
+ assertEquals("CREATE TABLE Test (dbl1 float(22) NULL)", sql);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/postgres/PostgresAdapterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/postgres/PostgresAdapterTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/postgres/PostgresAdapterTest.java
deleted file mode 100644
index 2bd20bc..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/postgres/PostgresAdapterTest.java
+++ /dev/null
@@ -1,56 +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.dba.postgres;
-
-import java.sql.Types;
-
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class PostgresAdapterTest extends ServerCase {
-
- @Inject
- private AdhocObjectFactory objectFactory;
-
- public void testCreateTableWithFloatAttributeWithScale () {
- PostgresAdapter adapter = objectFactory.newInstance(
- PostgresAdapter.class,
- PostgresAdapter.class.getName());
- DbEntity e = new DbEntity("Test");
- DbAttribute dblPrec = new DbAttribute("dbl1");
- dblPrec.setType(Types.FLOAT);
- dblPrec.setMaxLength(22);
- dblPrec.setScale(12);
- e.addAttribute(dblPrec);
-
- String sql = adapter.createTable(e);
-
- // CAY-1363.
- // Postgress don't support notations float(a, b)
- assertTrue(sql.indexOf("float(22)") > 0);
- assertEquals(-1, sql.indexOf("float(22, 12)"));
- assertEquals("CREATE TABLE Test (dbl1 float(22) NULL)", sql);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterIT.java
new file mode 100644
index 0000000..7fbbb51
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterIT.java
@@ -0,0 +1,55 @@
+/*****************************************************************
+ * 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.dba.sqlserver;
+
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SQLServerAdapterIT extends ServerCase {
+
+ @Inject
+ private AdhocObjectFactory objectFactory;
+
+ public void testCreateTableWithFloatAttributeWithScale () {
+ SQLServerAdapter adapter = objectFactory.newInstance(
+ SQLServerAdapter.class,
+ SQLServerAdapter.class.getName());
+ DbEntity e = new DbEntity("Test");
+ DbAttribute dblPrec = new DbAttribute("dbl1");
+ dblPrec.setType(Types.FLOAT);
+ dblPrec.setMaxLength(22);
+ dblPrec.setScale(12);
+ e.addAttribute(dblPrec);
+
+ String sql = adapter.createTable(e);
+
+ // CAY-1363.
+ // Postgress don't support notations float(a, b)
+ assertTrue(sql.indexOf("float(22)") > 0);
+ assertEquals(-1, sql.indexOf("float(22, 12)"));
+ assertEquals("CREATE TABLE Test (dbl1 float(22) NULL)", sql);
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java
deleted file mode 100644
index 5d0c9e2..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerAdapterTest.java
+++ /dev/null
@@ -1,55 +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.dba.sqlserver;
-
-import java.sql.Types;
-
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.DbAttribute;
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class SQLServerAdapterTest extends ServerCase {
-
- @Inject
- private AdhocObjectFactory objectFactory;
-
- public void testCreateTableWithFloatAttributeWithScale () {
- SQLServerAdapter adapter = objectFactory.newInstance(
- SQLServerAdapter.class,
- SQLServerAdapter.class.getName());
- DbEntity e = new DbEntity("Test");
- DbAttribute dblPrec = new DbAttribute("dbl1");
- dblPrec.setType(Types.FLOAT);
- dblPrec.setMaxLength(22);
- dblPrec.setScale(12);
- e.addAttribute(dblPrec);
-
- String sql = adapter.createTable(e);
-
- // CAY-1363.
- // Postgress don't support notations float(a, b)
- assertTrue(sql.indexOf("float(22)") > 0);
- assertEquals(-1, sql.indexOf("float(22, 12)"));
- assertEquals("CREATE TABLE Test (dbl1 float(22) NULL)", sql);
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerSnifferIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerSnifferIT.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerSnifferIT.java
new file mode 100644
index 0000000..7fa3a0a
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerSnifferIT.java
@@ -0,0 +1,72 @@
+/*****************************************************************
+ * 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.dba.sqlserver;
+
+import org.apache.cayenne.dba.DbAdapter;
+import org.apache.cayenne.di.AdhocObjectFactory;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.unit.SQLServerUnitDbAdapter;
+import org.apache.cayenne.unit.UnitDbAdapter;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.ServerCaseDataSourceFactory;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class SQLServerSnifferIT extends ServerCase {
+
+ @Inject
+ private ServerCaseDataSourceFactory dataSourceFactory;
+
+ @Inject
+ private UnitDbAdapter accessStackAdapter;
+
+ @Inject
+ private AdhocObjectFactory objectFactory;
+
+ public void testCreateAdapter() throws Exception {
+
+ SQLServerSniffer sniffer = new SQLServerSniffer(objectFactory);
+
+ DbAdapter adapter = null;
+ Connection c = dataSourceFactory.getSharedDataSource().getConnection();
+
+ try {
+ adapter = sniffer.createAdapter(c.getMetaData());
+ }
+ finally {
+ try {
+ c.close();
+ }
+ catch (SQLException e) {
+
+ }
+ }
+
+ if (accessStackAdapter instanceof SQLServerUnitDbAdapter) {
+ assertNotNull(adapter);
+ }
+ else {
+ assertNull(adapter);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerSnifferTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerSnifferTest.java b/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerSnifferTest.java
deleted file mode 100644
index c95682c..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/dba/sqlserver/SQLServerSnifferTest.java
+++ /dev/null
@@ -1,72 +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.dba.sqlserver;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import org.apache.cayenne.dba.DbAdapter;
-import org.apache.cayenne.di.AdhocObjectFactory;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.unit.UnitDbAdapter;
-import org.apache.cayenne.unit.SQLServerUnitDbAdapter;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.ServerCaseDataSourceFactory;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class SQLServerSnifferTest extends ServerCase {
-
- @Inject
- private ServerCaseDataSourceFactory dataSourceFactory;
-
- @Inject
- private UnitDbAdapter accessStackAdapter;
-
- @Inject
- private AdhocObjectFactory objectFactory;
-
- public void testCreateAdapter() throws Exception {
-
- SQLServerSniffer sniffer = new SQLServerSniffer(objectFactory);
-
- DbAdapter adapter = null;
- Connection c = dataSourceFactory.getSharedDataSource().getConnection();
-
- try {
- adapter = sniffer.createAdapter(c.getMetaData());
- }
- finally {
- try {
- c.close();
- }
- catch (SQLException e) {
-
- }
- }
-
- if (accessStackAdapter instanceof SQLServerUnitDbAdapter) {
- assertNotNull(adapter);
- }
- else {
- assertNull(adapter);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionIT.java b/cayenne-server/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionIT.java
new file mode 100644
index 0000000..e86d4bc
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionIT.java
@@ -0,0 +1,111 @@
+/*****************************************************************
+ * 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.ejbql;
+
+import org.apache.cayenne.configuration.server.ServerRuntime;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.map.EntityResolver;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class EJBQLCompiledExpressionIT extends ServerCase {
+
+ @Inject
+ protected ServerRuntime runtime;
+
+ public void testGetSource() {
+ String source = "select a from Artist a";
+ EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+ EJBQLParser parser = EJBQLParserFactory.getParser();
+
+ EJBQLCompiledExpression select = parser.compile(source, resolver);
+ assertEquals(source, select.getSource());
+ }
+
+ public void testGetExpression() {
+ String source = "select a from Artist a";
+ EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+ EJBQLParser parser = EJBQLParserFactory.getParser();
+
+ EJBQLCompiledExpression select = parser.compile(source, resolver);
+ assertNotNull(select.getExpression());
+ }
+
+ public void testGetEntityDescriptor() {
+ EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+ EJBQLParser parser = EJBQLParserFactory.getParser();
+
+ EJBQLCompiledExpression select = parser.compile(
+ "select a from Artist a",
+ resolver);
+
+ assertNotNull(select.getEntityDescriptor("a"));
+ assertSame(resolver.getClassDescriptor("Artist"), select.getEntityDescriptor("a"));
+
+ EJBQLCompiledExpression select1 = parser.compile(
+ "select p from Painting p WHERE p.toArtist.artistName = 'a'",
+ resolver);
+ assertNotNull(select1.getEntityDescriptor("p"));
+ assertSame(resolver.getClassDescriptor("Painting"), select1
+ .getEntityDescriptor("p"));
+
+ assertNotNull(select1.getEntityDescriptor("p.toArtist"));
+ assertSame(resolver.getClassDescriptor("Artist"), select1
+ .getEntityDescriptor("p.toArtist"));
+ }
+
+ public void testGetRootDescriptor() {
+ EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+ EJBQLParser parser = EJBQLParserFactory.getParser();
+
+ EJBQLCompiledExpression select = parser.compile(
+ "select a from Artist a",
+ resolver);
+
+ assertSame("Root is not detected: " + select.getExpression(), resolver
+ .getClassDescriptor("Artist"), select.getRootDescriptor());
+ }
+
+ public void testGetEntityDescriptorCaseSensitivity() {
+ EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
+ EJBQLParser parser = EJBQLParserFactory.getParser();
+
+ EJBQLCompiledExpression select1 = parser.compile(
+ "select a from Artist a",
+ resolver);
+
+ assertNotNull(select1.getEntityDescriptor("a"));
+ assertNotNull(select1.getEntityDescriptor("A"));
+
+ EJBQLCompiledExpression select2 = parser.compile(
+ "select A from Artist A",
+ resolver);
+
+ assertNotNull(select2.getEntityDescriptor("a"));
+ assertNotNull(select2.getEntityDescriptor("A"));
+
+ EJBQLCompiledExpression select3 = parser.compile(
+ "select a from Artist A",
+ resolver);
+
+ assertNotNull(select3.getEntityDescriptor("a"));
+ assertNotNull(select3.getEntityDescriptor("A"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionTest.java b/cayenne-server/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionTest.java
deleted file mode 100644
index 5e16edb..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/ejbql/EJBQLCompiledExpressionTest.java
+++ /dev/null
@@ -1,111 +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.ejbql;
-
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class EJBQLCompiledExpressionTest extends ServerCase {
-
- @Inject
- protected ServerRuntime runtime;
-
- public void testGetSource() {
- String source = "select a from Artist a";
- EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
- EJBQLParser parser = EJBQLParserFactory.getParser();
-
- EJBQLCompiledExpression select = parser.compile(source, resolver);
- assertEquals(source, select.getSource());
- }
-
- public void testGetExpression() {
- String source = "select a from Artist a";
- EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
- EJBQLParser parser = EJBQLParserFactory.getParser();
-
- EJBQLCompiledExpression select = parser.compile(source, resolver);
- assertNotNull(select.getExpression());
- }
-
- public void testGetEntityDescriptor() {
- EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
- EJBQLParser parser = EJBQLParserFactory.getParser();
-
- EJBQLCompiledExpression select = parser.compile(
- "select a from Artist a",
- resolver);
-
- assertNotNull(select.getEntityDescriptor("a"));
- assertSame(resolver.getClassDescriptor("Artist"), select.getEntityDescriptor("a"));
-
- EJBQLCompiledExpression select1 = parser.compile(
- "select p from Painting p WHERE p.toArtist.artistName = 'a'",
- resolver);
- assertNotNull(select1.getEntityDescriptor("p"));
- assertSame(resolver.getClassDescriptor("Painting"), select1
- .getEntityDescriptor("p"));
-
- assertNotNull(select1.getEntityDescriptor("p.toArtist"));
- assertSame(resolver.getClassDescriptor("Artist"), select1
- .getEntityDescriptor("p.toArtist"));
- }
-
- public void testGetRootDescriptor() {
- EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
- EJBQLParser parser = EJBQLParserFactory.getParser();
-
- EJBQLCompiledExpression select = parser.compile(
- "select a from Artist a",
- resolver);
-
- assertSame("Root is not detected: " + select.getExpression(), resolver
- .getClassDescriptor("Artist"), select.getRootDescriptor());
- }
-
- public void testGetEntityDescriptorCaseSensitivity() {
- EntityResolver resolver = runtime.getDataDomain().getEntityResolver();
- EJBQLParser parser = EJBQLParserFactory.getParser();
-
- EJBQLCompiledExpression select1 = parser.compile(
- "select a from Artist a",
- resolver);
-
- assertNotNull(select1.getEntityDescriptor("a"));
- assertNotNull(select1.getEntityDescriptor("A"));
-
- EJBQLCompiledExpression select2 = parser.compile(
- "select A from Artist A",
- resolver);
-
- assertNotNull(select2.getEntityDescriptor("a"));
- assertNotNull(select2.getEntityDescriptor("A"));
-
- EJBQLCompiledExpression select3 = parser.compile(
- "select a from Artist A",
- resolver);
-
- assertNotNull(select3.getEntityDescriptor("a"));
- assertNotNull(select3.getEntityDescriptor("A"));
- }
-}
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/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
new file mode 100644
index 0000000..b8aab38
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactory_InContextIT.java
@@ -0,0 +1,319 @@
+/*****************************************************************
+ * 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.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ExpressionFactory_InContextIT extends ServerCase {
+
+ @Inject
+ private ObjectContext context;
+
+ public void testExpressionOfBadType() throws Exception {
+
+ // non existing type
+ int badType = -50;
+
+ try {
+ ExpressionFactory.expressionOfType(badType);
+ fail();
+ } catch (ExpressionException ex) {
+ // exception expected
+ }
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ public void testGreaterExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.greaterExp("abc", v);
+ assertEquals(Expression.GREATER_THAN, exp.getType());
+ }
+
+ 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());
+ }
+
+ public void testGreaterOrEqualExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.greaterOrEqualExp("abc", v);
+ assertEquals(Expression.GREATER_THAN_EQUAL_TO, exp.getType());
+ }
+
+ 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());
+ }
+
+ public void testLessExp() throws Exception {
+ Object v = new Object();
+ Expression exp = ExpressionFactory.lessExp("abc", v);
+ assertEquals(Expression.LESS_THAN, exp.getType());
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ public void testInExp1() throws Exception {
+ Expression exp = ExpressionFactory.inExp("abc", "a", "b");
+ assertEquals(Expression.IN, exp.getType());
+ }
+
+ 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());
+ }
+
+ public void testInExp3() throws Exception {
+ List<Object> v = new ArrayList<Object>();
+ Expression exp = ExpressionFactory.inExp("abc", v);
+ assertEquals(Expression.FALSE, exp.getType());
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ 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());
+ }
+
+ 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
+ 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
+ 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));
+ }
+
+ 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));
+ }
+
+ 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/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactory_InContextTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactory_InContextTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactory_InContextTest.java
deleted file mode 100644
index cd0e08c..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/ExpressionFactory_InContextTest.java
+++ /dev/null
@@ -1,319 +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 java.util.ArrayList;
-import java.util.List;
-
-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.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class ExpressionFactory_InContextTest extends ServerCase {
-
- @Inject
- private ObjectContext context;
-
- public void testExpressionOfBadType() throws Exception {
-
- // non existing type
- int badType = -50;
-
- try {
- ExpressionFactory.expressionOfType(badType);
- fail();
- } catch (ExpressionException ex) {
- // exception expected
- }
- }
-
- 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());
- }
-
- 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());
- }
-
- 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());
- }
-
- 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());
- }
-
- public void testGreaterExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.greaterExp("abc", v);
- assertEquals(Expression.GREATER_THAN, exp.getType());
- }
-
- 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());
- }
-
- public void testGreaterOrEqualExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.greaterOrEqualExp("abc", v);
- assertEquals(Expression.GREATER_THAN_EQUAL_TO, exp.getType());
- }
-
- 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());
- }
-
- public void testLessExp() throws Exception {
- Object v = new Object();
- Expression exp = ExpressionFactory.lessExp("abc", v);
- assertEquals(Expression.LESS_THAN, exp.getType());
- }
-
- 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());
- }
-
- 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());
- }
-
- 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());
- }
-
- public void testInExp1() throws Exception {
- Expression exp = ExpressionFactory.inExp("abc", "a", "b");
- assertEquals(Expression.IN, exp.getType());
- }
-
- 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());
- }
-
- public void testInExp3() throws Exception {
- List<Object> v = new ArrayList<Object>();
- Expression exp = ExpressionFactory.inExp("abc", v);
- assertEquals(Expression.FALSE, exp.getType());
- }
-
- 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());
- }
-
- 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());
- }
-
- 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());
- }
-
- 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());
- }
-
- 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());
- }
-
- 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());
- }
-
- 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
- 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
- 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));
- }
-
- 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));
- }
-
- 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/e42c376c/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
new file mode 100644
index 0000000..d75aceb
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/exp/Expression_InContextIT.java
@@ -0,0 +1,132 @@
+/*****************************************************************
+ * 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.test.jdbc.DBHelper;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class Expression_InContextIT extends ServerCase {
+
+ @Inject
+ private DBHelper dbHelper;
+
+ @Inject
+ private ObjectContext context;
+
+ @Inject
+ private ServerRuntime runtime;
+
+ @Override
+ protected void setUpAfterInjection() throws Exception {
+ dbHelper.deleteAll("PAINTING_INFO");
+ dbHelper.deleteAll("PAINTING");
+ dbHelper.deleteAll("ARTIST_EXHIBIT");
+ dbHelper.deleteAll("ARTIST_GROUP");
+ dbHelper.deleteAll("ARTIST");
+ dbHelper.deleteAll("EXHIBIT");
+ dbHelper.deleteAll("GALLERY");
+ }
+
+ 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)));
+ }
+
+ 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/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/exp/Expression_InContextTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/exp/Expression_InContextTest.java b/cayenne-server/src/test/java/org/apache/cayenne/exp/Expression_InContextTest.java
deleted file mode 100644
index af4f2d7..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/exp/Expression_InContextTest.java
+++ /dev/null
@@ -1,132 +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 java.util.ArrayList;
-import java.util.List;
-
-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.test.jdbc.DBHelper;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class Expression_InContextTest extends ServerCase {
-
- @Inject
- private DBHelper dbHelper;
-
- @Inject
- private ObjectContext context;
-
- @Inject
- private ServerRuntime runtime;
-
- @Override
- protected void setUpAfterInjection() throws Exception {
- dbHelper.deleteAll("PAINTING_INFO");
- dbHelper.deleteAll("PAINTING");
- dbHelper.deleteAll("ARTIST_EXHIBIT");
- dbHelper.deleteAll("ARTIST_GROUP");
- dbHelper.deleteAll("ARTIST");
- dbHelper.deleteAll("EXHIBIT");
- dbHelper.deleteAll("GALLERY");
- }
-
- 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)));
- }
-
- 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));
- }
-
-}