db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1327909 - in /db/torque/torque4/trunk/torque-test/src: main/schema/default-value-schema.xml test/java/org/apache/torque/generated/peer/UseDefaultValueFromDatabaseTest.java
Date Thu, 19 Apr 2012 11:57:20 GMT
Author: tfischer
Date: Thu Apr 19 11:57:20 2012
New Revision: 1327909

URL: http://svn.apache.org/viewvc?rev=1327909&view=rev
Log:
TORQUE-15 test allowing database default values for columns 

Added:
    db/torque/torque4/trunk/torque-test/src/main/schema/default-value-schema.xml
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/UseDefaultValueFromDatabaseTest.java

Added: db/torque/torque4/trunk/torque-test/src/main/schema/default-value-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/default-value-schema.xml?rev=1327909&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/default-value-schema.xml (added)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/default-value-schema.xml Thu Apr 19
11:57:20 2012
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?>
+<!--
+ 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.
+-->
+
+<database name="@DATABASE_DEFAULT@"
+    defaultIdMethod="@DATABASE_ID_METHOD@"
+    package="org.apache.torque.test.ext"
+    xmlns="http://db.apache.org/torque/4.0/templates/database"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://db.apache.org/torque/4.0/templates/database 
+        http://db.apache.org/torque/4.0/templates/database-strict.xsd">
+
+  <table name="default_values">
+    <column
+      name="id"
+      required="true"
+      primaryKey="true"
+      type="INTEGER"
+    />
+    <column
+      name="o_integer_default_from_db"
+      required="true"
+      type="INTEGER"
+      javaType="object"
+      useDatabaseDefaultValue="true"
+      default="2"
+    />
+    <column
+      name="o_integer_with_default"
+      required="true"
+      type="INTEGER"
+      javaType="object"
+      default="3"
+    />
+    <column
+      name="p_int_default_from_db"
+      required="true"
+      type="INTEGER"
+      javaType="primitive"
+      useDatabaseDefaultValue="true"
+      default="4"
+    />
+    <column
+      name="p_int_with_default"
+      required="true"
+      type="INTEGER"
+      javaType="primitive"
+      default="5"
+    />
+  </table>
+</database>

Added: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/UseDefaultValueFromDatabaseTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/UseDefaultValueFromDatabaseTest.java?rev=1327909&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/UseDefaultValueFromDatabaseTest.java
(added)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/UseDefaultValueFromDatabaseTest.java
Thu Apr 19 11:57:20 2012
@@ -0,0 +1,148 @@
+package org.apache.torque.generated.peer;
+
+import java.sql.Types;
+
+import org.apache.torque.BaseDatabaseTestCase;
+import org.apache.torque.test.DefaultValues;
+import org.apache.torque.test.DefaultValuesPeer;
+import org.apache.torque.util.ColumnValues;
+import org.apache.torque.util.JdbcTypedValue;
+
+/*
+ * 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.
+ */
+
+/**
+ * Tests whether the useDatabaseDefaultValue attribute works.
+ * It is difficult to have database default values for the different
+ * databases, so the test checks the results of the buildColumnValues
+ * method of the peers.
+ *
+ * @version $Id: DataTest.java 1213056 2011-12-11 20:31:06Z tfischer $
+ */
+public class UseDefaultValueFromDatabaseTest extends BaseDatabaseTestCase
+{
+    /**
+     * Tests whether the buildColumnValues adds column values
+     * for columns which have no database default on a new object.
+     */
+    public void testJavaDefaultValueOnNewObject() throws Exception
+    {
+        DefaultValues defaultValues = new DefaultValues();
+        ColumnValues columnValues
+                = DefaultValuesPeer.buildColumnValues(defaultValues);
+        assertEquals(
+                new JdbcTypedValue(3, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.O_INTEGER_WITH_DEFAULT));
+        assertEquals(
+                new JdbcTypedValue(5, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.P_INT_WITH_DEFAULT));
+    }
+
+    /**
+     * Tests whether the buildColumnValues does not add column values
+     * for columns which use the database default value on a new object.
+     */
+    public void testDatabaseDefaultValueOnNewObject() throws Exception
+    {
+        DefaultValues defaultValues = new DefaultValues();
+        ColumnValues columnValues
+                = DefaultValuesPeer.buildColumnValues(defaultValues);
+        assertNull(
+                columnValues.get(DefaultValuesPeer.O_INTEGER_DEFAULT_FROM_DB));
+        assertNull(
+                columnValues.get(DefaultValuesPeer.P_INT_DEFAULT_FROM_DB));
+    }
+
+    /**
+     * Tests whether the buildColumnValues adds column values
+     * for columns with modified value which have no database default
+     *  on a new object.
+     */
+    public void testJavaDefaultValueOnNewObjectChangedValue() throws Exception
+    {
+        DefaultValues defaultValues = new DefaultValues();
+        defaultValues.setOIntegerWithDefault(6);
+        defaultValues.setPIntWithDefault(7);
+        ColumnValues columnValues
+                = DefaultValuesPeer.buildColumnValues(defaultValues);
+        assertEquals(
+                new JdbcTypedValue(6, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.O_INTEGER_WITH_DEFAULT));
+        assertEquals(
+                new JdbcTypedValue(7, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.P_INT_WITH_DEFAULT));
+    }
+
+    /**
+     * Tests whether the buildColumnValues adds column values
+     * for columns with modified value
+     * which use the database default value on a new object.
+     */
+    public void testDatabaseDefaultValueOnNewObjectChangedValue()
+            throws Exception
+    {
+        DefaultValues defaultValues = new DefaultValues();
+        defaultValues.setOIntegerDefaultFromDb(6);
+        defaultValues.setPIntDefaultFromDb(7);
+        ColumnValues columnValues
+                = DefaultValuesPeer.buildColumnValues(defaultValues);
+        assertEquals(
+                new JdbcTypedValue(6, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.O_INTEGER_DEFAULT_FROM_DB));
+        assertEquals(
+                new JdbcTypedValue(7, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.P_INT_DEFAULT_FROM_DB));
+    }
+
+    /**
+     * Tests whether the buildColumnValues adds column values
+     * for columns which have no database default on a not new object.
+     */
+    public void testJavaDefaultValueOnNotNewObject() throws Exception
+    {
+        DefaultValues defaultValues = new DefaultValues();
+        defaultValues.setNew(false);
+        ColumnValues columnValues
+                = DefaultValuesPeer.buildColumnValues(defaultValues);
+        assertEquals(
+                new JdbcTypedValue(3, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.O_INTEGER_WITH_DEFAULT));
+        assertEquals(
+                new JdbcTypedValue(5, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.P_INT_WITH_DEFAULT));
+    }
+
+    /**
+     * Tests whether the buildColumnValues adds column values
+     * for columns which use the database default value on a not new object.
+     */
+    public void testDatabaseDefaultValueOnNotNewObject() throws Exception
+    {
+        DefaultValues defaultValues = new DefaultValues();
+        defaultValues.setNew(false);
+        ColumnValues columnValues
+                = DefaultValuesPeer.buildColumnValues(defaultValues);
+        assertEquals(
+                new JdbcTypedValue(2, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.O_INTEGER_DEFAULT_FROM_DB));
+        assertEquals(
+                new JdbcTypedValue(4, Types.INTEGER),
+                columnValues.get(DefaultValuesPeer.P_INT_DEFAULT_FROM_DB));
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org


Mime
View raw message