You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by gk...@apache.org on 2019/10/25 15:20:54 UTC

svn commit: r1868941 - in /db/torque/torque4/trunk/torque-test: README.md pom.xml src/main/schema/id-table-schema.xml src/test/java/org/apache/torque/DataTest.java src/test/java/org/apache/torque/generated/peer/DefaultValuesFromJavaTest.java

Author: gk
Date: Fri Oct 25 15:20:53 2019
New Revision: 1868941

URL: http://svn.apache.org/viewvc?rev=1868941&view=rev
Log:
- fix some issues in torque-test for hsqldb, mysql 
- add info about debugging, and readme.md in torque-test.

Added:
    db/torque/torque4/trunk/torque-test/README.md
Modified:
    db/torque/torque4/trunk/torque-test/pom.xml
    db/torque/torque4/trunk/torque-test/src/main/schema/id-table-schema.xml
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
    db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DefaultValuesFromJavaTest.java

Added: db/torque/torque4/trunk/torque-test/README.md
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/README.md?rev=1868941&view=auto
==============================================================================
--- db/torque/torque4/trunk/torque-test/README.md (added)
+++ db/torque/torque4/trunk/torque-test/README.md Fri Oct 25 15:20:53 2019
@@ -0,0 +1,61 @@
+# Test Module - Test against Databases
+
+## Generaal 
+- Start mvn test -P<data-type>
+
+* e.g. for database Hsqldb use "mvn test -Phsqldb". 
+
+* Find profile names in pom.xml
+
+Find more details about database anddb user settings in the profile. 
+
+## Workflow
+
+- check src/main/schema for the source schemas and the results in target/generated-* folders.
+
+- find schema xsd in torque-templates module src/main/resources/torque/xsd
+
+
+### Hsqldb
+
+- in memory, no user access restriction as configured required
+
+### MySql
+
+- user and database must exist, before running test, see profile mysql
+
+### Postgresql
+
+...
+
+### Mssql
+...
+
+### Oracle
+
+...
+### Derby
+
+...
+
+## IDE integration (Eclipse) Settings
+
+### IDE integration (Eclipse)
+
+- add src/main/generated-java and target/generated-sources to build path.
+
+### Maven Database Test with Remote Standard Socket Attachment
+
+Example 
+
+// attach example opens port 8000 per default
+// forkMode already deprecated, but change as convenient.
+
+mvnDebug test -Dtest=DataTest#testLikeClauseEscaping -Pmysql -DforkMode=never
+
+* -DforkMode=never on command line has no effect, may be a bug. Changing in pom however does what it should do (as of maven 3.6.0)
+
+## TODO
+- Use Java Testcontainers (Docker) to simulate for mysql, postgresql
+
+

Modified: db/torque/torque4/trunk/torque-test/pom.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/pom.xml?rev=1868941&r1=1868940&r2=1868941&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/pom.xml (original)
+++ db/torque/torque4/trunk/torque-test/pom.xml Fri Oct 25 15:20:53 2019
@@ -82,6 +82,11 @@
       <version>5.0.28</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-dbcp2</artifactId>
+      <scope>test</scope>
+    </dependency>
 
     <!-- avalon -->
     <dependency>
@@ -489,7 +494,7 @@
           <excludes>
             <exclude>**/BaseRuntimeTestCase.java</exclude>
           </excludes>
-          <forkMode>pertest</forkMode>
+          <forkMode>pertest</forkMode><!-- normally pertest, if remote debugging with mvnDebug port 8000, setting in console -DforkMode=none seems to have no effect, set here -->
           <systemProperties>
             <property>
               <name>torque.configuration.file</name>

Modified: db/torque/torque4/trunk/torque-test/src/main/schema/id-table-schema.xml
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/main/schema/id-table-schema.xml?rev=1868941&r1=1868940&r2=1868941&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/main/schema/id-table-schema.xml (original)
+++ db/torque/torque4/trunk/torque-test/src/main/schema/id-table-schema.xml Fri Oct 25 15:20:53 2019
@@ -33,8 +33,8 @@
 <database name="@DATABASE_DEFAULT@"
     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/torque-4.0/documentation/orm-reference/database-4-0-strict.xsd">
+    xsi:schemaLocation="http://db.apache.org/torque/4.1/templates/database 
+        http://db.apache.org/torque/torque-4.1/documentation/orm-reference/database-4-1-strict.xsd">
 
   <table name="ID_TABLE" idMethod="idbroker">
     <column name="ID_TABLE_ID" required="true" primaryKey="true" type="INTEGER"/>
@@ -43,7 +43,7 @@
     <column name="QUANTITY" type="INTEGER"/>
 
     <unique>
-      <unique-column name="TABLE_NAME"/>
+      <unique-column name="TABLE_NAME" size="191"/>
     </unique>
 
   </table>

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1868941&r1=1868940&r2=1868941&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java Fri Oct 25 15:20:53 2019
@@ -1235,15 +1235,25 @@ public class DataTest extends BaseDataba
 
         likeResults.put("a\\%c", "a%c");
         likeResults.put("a\\%%", "a%c");
-        likeResults.put("%\\%c", "a%c");
+        likeResults.put("%\\%c", "a%c"); // escaped second %
 
-        likeResults.put("a\\\\c", "a\\c");
+        likeResults.put("a\\\\c", "a\\c"); // escaped \ three times
         likeResults.put("a\\\\%", "a\\c");
-        likeResults.put("%\\\\c", "a\\c");
-
+        
+        // mysql: like '%\\c' ESCAPE '|' succeeds  , you must double any \ that you use in LIKE strings.
+        // %\\\\c fails, may be  to https://dev.mysql.com/doc/refman/8.0/en/string-comparison-functions.html, 
+        // MySQL uses C escape syntax in strings..  you must double any \ that you use in LIKE strings.
+        // platform specific mysql:
+        //likeResults.put("%\\\\\\\\c", "a\\c"); //
+        // other platforms ?
+        //likeResults.put("%\\\\c", "a\\c"); //
+        
         likeResults.put("a\\*c", "a*c");
         likeResults.put("a\\*%", "a*c");
-        likeResults.put("%\\*c", "a*c");
+        //likeResults.put("%\\*c", "a*c"); // mysql: %\\*c fails, only underscore (_) is wild card
+        // this matches multiple users
+        //likeResults.put("%*c", "a%c"); 
+        likeResults.put("_\\*c", "a*c"); 
 
         likeResults.put("a\\?c", "a?c");
         likeResults.put("a\\?%", "a?c");
@@ -1304,7 +1314,7 @@ public class DataTest extends BaseDataba
                                 e);
             }
             assertEquals(
-                    "AuthorList should contain one author"
+                    "AuthorList contained " + authorList.size() + ", but should contain one author"
                             + " when querying for " + likeResult.getKey(),
                             1,
                             authorList.size());

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DefaultValuesFromJavaTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DefaultValuesFromJavaTest.java?rev=1868941&r1=1868940&r2=1868941&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DefaultValuesFromJavaTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DefaultValuesFromJavaTest.java Fri Oct 25 15:20:53 2019
@@ -45,7 +45,7 @@ public class DefaultValuesFromJavaTest e
     private static String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
 
     /**
-     * Checks that if CURRENT_DATE is used as default value
+     * Checks that if CURRENT_DATE is used as non database default value (useDatabaseDefaultValue is not set)
      * then an object is constructed with current java time.
      *
      * @throws Exception if an error occurs.
@@ -65,6 +65,13 @@ public class DefaultValuesFromJavaTest e
         currentCalendarBefore.set(GregorianCalendar.SECOND, 0);
         currentCalendarBefore.set(GregorianCalendar.MILLISECOND, 0);
         JavaDefaultValues javaDefaultValues = new JavaDefaultValues();
+        
+        if (javaDefaultValues.getCurrentDateValue() == null) {
+            // if the schema has useDatabaseDefaultValue current time is set null.
+            log.error("testCurrentDateAsJavaDefault(): "
+                    + "useDatabaseDefaultValue is set, default value is set in database!");
+            return;
+        }
         GregorianCalendar currentCalendarAfter = new GregorianCalendar();
         currentCalendarAfter.set(GregorianCalendar.HOUR_OF_DAY, 0);
         currentCalendarAfter.set(GregorianCalendar.MINUTE, 0);
@@ -86,7 +93,8 @@ public class DefaultValuesFromJavaTest e
     }
 
     /**
-     * Checks that if CURRENT_TIME is used as default value
+     * Checks that if CURRENT_TIME is used as non database default value
+     * (useDatabaseDefaultValue is not set)
      * then an object is constructed with current java time.
      *
      * @throws Exception if an error occurs.
@@ -106,18 +114,21 @@ public class DefaultValuesFromJavaTest e
         currentCalendarBefore.set(1970, 1, 1);
         JavaDefaultValues javaDefaultValues = new JavaDefaultValues();
         if (javaDefaultValues.getCurrentTimeValue() == null) {
-        	// the schema has useDatabaseDefaultValue an current time is set null
-	        GregorianCalendar currentCalendarAfter = new GregorianCalendar();
-	        currentCalendarAfter.set(1970, 1, 1);
-	        assertFalse(
-	                "currentTime should be >= currentCalendarBefore",
-	                javaDefaultValues.getCurrentTimeValue().before(
-	                        currentCalendarBefore.getTime()));
-	        assertFalse(
-	                "currentTime should be <= currentDateAfter",
-	                javaDefaultValues.getCurrentTimeValue().after(
-                        currentCalendarAfter.getTime()));
+            // if the schema has useDatabaseDefaultValue current time is set null.
+            log.error("testCurrentDateAsJavaDefault(): "
+                    + "useDatabaseDefaultValue is set, default value is set in database!");
+            return;
         }
+        GregorianCalendar currentCalendarAfter = new GregorianCalendar();
+        currentCalendarAfter.set(1970, 1, 1);
+        assertFalse(
+                "currentTime should be >= currentCalendarBefore",
+                javaDefaultValues.getCurrentTimeValue().before(
+                        currentCalendarBefore.getTime()));
+        assertFalse(
+                "currentTime should be <= currentDateAfter",
+                javaDefaultValues.getCurrentTimeValue().after(
+                    currentCalendarAfter.getTime()));
     }
 
     /**



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