schema generation for hibernate mysql as a starting point before
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 9 Apr 2010 21:53:46 +0000 (21:53 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 9 Apr 2010 21:53:46 +0000 (21:53 +0000)
starting with jpa

trunk/security/src/test/java/org/wamblee/security/authorization/hibernate/PersistentAuthorizationServiceTest.java

index 2dcefee78715e77c4ceba8563b9050a0ca8041b2..f55fc293865f9f3ae8bc86e47a81510bd0e71383 100644 (file)
@@ -19,6 +19,10 @@ package org.wamblee.security.authorization.hibernate;
 import java.sql.SQLException;
 
 import org.apache.log4j.Logger;
+import org.hibernate.cfg.Configuration;
+import org.hibernate.dialect.MySQL5Dialect;
+import org.hibernate.dialect.MySQL5InnoDBDialect;
+import org.hibernate.tool.hbm2ddl.SchemaExport;
 import org.springframework.orm.hibernate3.HibernateTemplate;
 import org.wamblee.general.BeanKernel;
 import org.wamblee.security.authorization.AuthorizationService;
@@ -69,17 +73,17 @@ public class PersistentAuthorizationServiceTest extends
         _container = new DefaultContainer("top");
         DatabaseComponentFactory.addDatabaseConfig(_container);
         _container.addComponent(new DatasourceComponent("datasource"));
-        ClassConfiguration useraccessorConfig = new ClassConfiguration(TestUserAccessor.class); 
+        ClassConfiguration useraccessorConfig = new ClassConfiguration(
+                TestUserAccessor.class);
         useraccessorConfig.getObjectConfig().getSetterConfig().initAllSetters();
         _container.addComponent("userAccessor", useraccessorConfig);
         _container.addComponent(new AuthorizationComponent("authorization",
                 true));
 
-        
-        ClassConfiguration dbtesterConfig = new ClassConfiguration(DatabaseTesterComponent.class); 
+        ClassConfiguration dbtesterConfig = new ClassConfiguration(
+                DatabaseTesterComponent.class);
         dbtesterConfig.getObjectConfig().getSetterConfig().initAllSetters();
-        _container
-                .addComponent("databaseTester", dbtesterConfig);
+        _container.addComponent("databaseTester", dbtesterConfig);
 
         ObjectConfiguration config = new ObjectConfiguration(
                 PersistentAuthorizationServiceTest.class);
@@ -106,7 +110,7 @@ public class PersistentAuthorizationServiceTest extends
     public void setHibernateTemplate(HibernateTemplate aHibernateTemplate) {
         _hibernateTemplate = aHibernateTemplate;
     }
-    
+
     public void setAuthorizationService(
             AuthorizationService aAuthorizationService) {
         _authorizationService = aAuthorizationService;
@@ -115,7 +119,9 @@ public class PersistentAuthorizationServiceTest extends
     /*
      * (non-Javadoc)
      * 
-     * @see org.wamblee.security.authorization.AuthorizationServiceTest#createService()
+     * @see
+     * org.wamblee.security.authorization.AuthorizationServiceTest#createService
+     * ()
      */
     @Override
     protected AuthorizationService createService() {
@@ -127,23 +133,38 @@ public class PersistentAuthorizationServiceTest extends
     /*
      * (non-Javadoc)
      * 
-     * @see org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount(int)
+     * @see
+     * org.wamblee.security.authorization.AuthorizationServiceTest#checkRuleCount
+     * (int)
      */
     @Override
     protected void checkRuleCount(int aCount) {
         try {
             assertEquals(1, _databaseTester.getTableSize(SERVICE_TABLE));
             assertEquals(aCount, _databaseTester.getTableSize(RULES_TABLE));
-            assertEquals(aCount, _databaseTester.getTableSize(SERVICE_RULES_TABLE));
+            assertEquals(aCount, _databaseTester
+                    .getTableSize(SERVICE_RULES_TABLE));
             assertEquals(aCount, _databaseTester.getTableSize(USERCOND_TABLE));
             assertEquals(aCount, _databaseTester.getTableSize(PATHCOND_TABLE));
-            assertEquals(aCount, _databaseTester.getTableSize(OPERATIONCOND_TABLE));
+            assertEquals(aCount, _databaseTester
+                    .getTableSize(OPERATIONCOND_TABLE));
         } catch (SQLException e) {
             throw new RuntimeException(e);
         }
 
     }
 
+    public void testSchemaExport() { 
+        Configuration config = new Configuration();
+        for (String mappingFile: new AuthorizationMappingFiles()) { 
+           config.addResource(mappingFile);
+        }
+        config.setProperty("hibernate.dialect", MySQL5InnoDBDialect.class.getName());
+        SchemaExport exporter = new SchemaExport(config);
+        exporter.setOutputFile("target/mysql5.schema.sql");
+        exporter.create(true,false);
+    }
+
     public void testPerformance() {
 
         PersistentAuthorizationService service = (PersistentAuthorizationService) getService();