Author: anthonyHib
Date: 2008-09-16 05:08:18 -0400 (Tue, 16 Sep 2008)
New Revision: 15199
Added:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TeamView.hbm.xml
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TeamView.java
Modified:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TestSchemaTools.java
Log:
JBPAPP-965 unitest
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TeamView.hbm.xml
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TeamView.hbm.xml
(rev 0)
+++
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TeamView.hbm.xml 2008-09-16
09:08:18 UTC (rev 15199)
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping SYSTEM
+ "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.test.tool">
+
+
+ <class name="TeamView" table="`TeamView`">
+ <id name="id" column="`iD`">
+ <generator class="native">
+ <param name="sequence">TEAM_SEQ</param>
+ </generator>
+ </id>
+ <property name="name"/>
+ <property name="duplicatedName"/>
+ </class>
+
+</hibernate-mapping>
Added: core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TeamView.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TeamView.java
(rev 0)
+++
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TeamView.java 2008-09-16
09:08:18 UTC (rev 15199)
@@ -0,0 +1,27 @@
+package org.hibernate.test.tool;
+
+
+public class TeamView {
+ private Long id;
+ private String name;
+ private String duplicatedName;
+ public Long getId() {
+ return id;
+ }
+ public void setId(Long id) {
+ this.id = id;
+ }
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public String getDuplicatedName() {
+ return duplicatedName;
+ }
+ public void setDuplicatedName(String duplicatedName) {
+ this.duplicatedName = duplicatedName;
+ }
+
+}
Modified:
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TestSchemaTools.java
===================================================================
---
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TestSchemaTools.java 2008-09-15
21:16:40 UTC (rev 15198)
+++
core/branches/Branch_3_2_4_SP1_CP/test/org/hibernate/test/tool/TestSchemaTools.java 2008-09-16
09:08:18 UTC (rev 15199)
@@ -35,7 +35,7 @@
}
public String[] getMappings() {
- return new String[] { "tool/Team.hbm.xml" };
+ return new String[] { "tool/Team.hbm.xml", "tool/TeamView.hbm.xml"
};
}
public boolean createSchema() {
@@ -115,6 +115,44 @@
session.close();
}
+ public void testViewValidation() throws Exception{
+ // database schema have been created thanks to the setUp method
+ // we have 2 schemas SA et SB, SB must be set as the default schema
+ // used by hibernate hibernate.default_schema SB
+ SchemaExport se = new SchemaExport(getCfg());
+ se.create(true,true);
+
+ // here we drop the table generated for TeamView and create a view in order to test
View validation
+ Session session = openSession();
+ Connection conn = session.connection();
+ Statement stat = conn.createStatement();
+ stat.execute("DROP TABLE \"SB\".\"TeamView\" ");
+ stat.execute("CREATE VIEW \"SB\".\"TeamView\" AS SELECT
\"iD\",name, name as duplicatedname FROM
\"SB\".\"Team\"");
+
+
+ // update schema, here should do nothing
+ SchemaUpdate su = new SchemaUpdate(getCfg());
+ su.execute(true,true);
+
+ // we can run schema validation.
+ // if schema validator chooses the bad db schema, then the testcase will fail
(exception)
+ SchemaValidator sv = new SchemaValidator(getCfg());
+ sv.validate();
+
+ // it's time to clean our database
+ se.drop(true,true);
+
+ // then the schemas and false table.
+
+ stat.execute("DROP TABLE \"SA\".\"Team\" ");
+ stat.execute(" DROP SCHEMA sa ");
+ stat.execute("DROP VIEW \"SB\".\"TeamView\" ");
+ stat.execute("DROP TABLE \"SB\".\"Team\" ");
+ stat.execute("DROP SCHEMA sb ");
+ stat.close();
+ session.close();
+ }
+
public void testSchemaToolsNonQuote() throws Exception{
// database schema have been created thanks to the setUp method
// we have 2 schemas SA et SB, SB must be set as the default schema
Show replies by date