Author: mikedd
Date: Wed Aug 10 19:45:29 2011
New Revision: 1156339

URL: http://svn.apache.org/viewvc?rev=1156339&view=rev
Log:
OPENJPA-2038: Add tests for tablename including schema

Modified:
    
openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java

Modified: 
openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java
URL: 
http://svn.apache.org/viewvc/openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java?rev=1156339&r1=1156338&r2=1156339&view=diff
==============================================================================
--- 
openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java
 (original)
+++ 
openjpa/branches/2.1.x/openjpa-jdbc/src/test/java/org/apache/openjpa/jdbc/sql/TestDBDictionaryGeneratedSQL.java
 Wed Aug 10 19:45:29 2011
@@ -113,6 +113,64 @@ public class TestDBDictionaryGeneratedSQ
         assertEquals(1, sqls.length);
         assertTrue(sqls[0].contains("NameIsRight"));
         assertTrue(sqls[0].contains("IAmASchema"));
-    }    
+    }
+    
+    public void testOverrideProperty() {
+        final JDBCConfiguration mockConfiguration = 
mock(JDBCConfiguration.class);
+        final DBIdentifierUtilImpl idImpl = new DBIdentifierUtilImpl();
+        
+        checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getIdentifierUtilInstance();
+                will(returnValue(idImpl)); 
 
+                allowing(mockConfiguration);
+            }
+        });
+        
+        DBDictionary dict = new DBDictionary();
+        dict.setConfiguration(mockConfiguration);
+        dict.tableLengthIncludesSchema=true;
+        dict.maxTableNameLength = 12;
+
+        Table table = new Table();
+        table.setIdentifier(DBIdentifier.newTable("NameIsTooLong"));
+        table.setSchemaIdentifier(DBIdentifier.newSchema("IAmASchema"));
+        
+        try {
+            dict.getCreateTableSQL(table);
+            fail("Expected a UserException");
+        } catch (UserException ue) {
+            // expected - check message in case a different UserException is 
thrown.
+            assertTrue(ue.getMessage().contains("Table name 
\"IAmASchema.NameIsTooLong\""));
+        } 
+    }
+    
+    public void testOverridePropertyShortName() {
+        final JDBCConfiguration mockConfiguration = 
mock(JDBCConfiguration.class);
+        final DBIdentifierUtilImpl idImpl = new DBIdentifierUtilImpl();
+        
+        checking(new Expectations() {
+            {
+                allowing(mockConfiguration).getIdentifierUtilInstance();
+                will(returnValue(idImpl)); 
+
+                allowing(mockConfiguration);
+            }
+        });
+        
+        DBDictionary dict = new DBDictionary();
+        dict.setConfiguration(mockConfiguration);
+        dict.tableLengthIncludesSchema=true;
+        dict.maxTableNameLength = 18;
+
+        Table table = new Table();
+        table.setIdentifier(DBIdentifier.newTable("NameIsRight"));
+        table.setSchemaIdentifier(DBIdentifier.newSchema("schema"));
+        
+        String[] sqls = dict.getCreateTableSQL(table);
+        assertEquals(1, sqls.length);
+        assertTrue(sqls[0].contains("NameIsRight"));
+        assertTrue(sqls[0].contains("schema"));
+    }
 }


Reply via email to