[hibernate-commits] Hibernate SVN: r10625 - in trunk/HibernateExt/tools/src/test/org/hibernate/tool: . hbmlint

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Oct 19 13:11:29 EDT 2006


Author: max.andersen at jboss.com
Date: 2006-10-19 13:11:24 -0400 (Thu, 19 Oct 2006)
New Revision: 10625

Added:
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenLazy.hbm.xml
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenLazy.java
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenNonLazy.java
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/CachingSettings.hbm.xml
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/FakeNonLazy.java
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/HbmLintAllTests.java
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/HbmLintTest.java
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/IdentifierIssues.hbm.xml
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/SchemaAnalyzerTest.java
   trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/SchemaIssues.hbm.xml
Log:
Missing tests for hbmlint

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenLazy.hbm.xml
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenLazy.hbm.xml	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenLazy.hbm.xml	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC 
+	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.tool.hbmlint">
+
+    <!--  category has caching for collection but its target is not cached -->
+    <class name="BrokenLazy" lazy="true">
+    
+    	<id name="id" type="long">
+    		<generator class="native"/>
+    	</id>
+		
+	</class>
+	
+	<class name="BrokenNonLazy" lazy="false">
+	<id name="id" type="long">
+		<generator class="native" />
+	</id>
+
+	</class>
+	
+	<class name="FakeNonLazy" lazy="false">
+	<id name="id" type="long">
+		<generator class="native" />
+	</id>
+
+	</class>
+	
+
+</hibernate-mapping>

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenLazy.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenLazy.java	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenLazy.java	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,11 @@
+package org.hibernate.tool.hbmlint;
+
+public class BrokenLazy {
+
+	long id;
+	
+	public BrokenLazy(long id) {
+		this.id = id;
+	}
+}
+

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenNonLazy.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenNonLazy.java	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/BrokenNonLazy.java	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,11 @@
+package org.hibernate.tool.hbmlint;
+
+public class BrokenNonLazy {
+
+	long id;
+	
+	public BrokenNonLazy(long id) {
+		this.id = id;
+	}
+}
+

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/CachingSettings.hbm.xml
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/CachingSettings.hbm.xml	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/CachingSettings.hbm.xml	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,29 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC 
+	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.tool.hbmlint">
+
+    <!--  category has caching for collection but its target is not cached -->
+    <class name="Category">
+    
+    	<id name="id" type="long">
+    		<generator class="native"/>
+    	</id>
+		
+		<set name="childCategories">
+			<cache usage="read-only"/>
+			<key column="PARENT_ID"/>
+			<one-to-many class="Category"/>
+		</set>
+    	
+	</class>
+
+     <class name="NoTable">
+        <id name="id" type="long">
+    		<generator class="native"/>
+    	</id>
+		
+     </class>
+</hibernate-mapping>

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/FakeNonLazy.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/FakeNonLazy.java	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/FakeNonLazy.java	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,37 @@
+package org.hibernate.tool.hbmlint;
+
+import org.hibernate.bytecode.javassist.FieldHandled;
+import org.hibernate.bytecode.javassist.FieldHandler;
+
+import net.sf.cglib.transform.impl.InterceptFieldCallback;
+import net.sf.cglib.transform.impl.InterceptFieldEnabled;
+
+public class FakeNonLazy implements InterceptFieldEnabled, FieldHandled {
+
+	long id;
+	
+	public FakeNonLazy(long id) {
+		this.id = id;
+	}
+
+	public InterceptFieldCallback getInterceptFieldCallback() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public void setInterceptFieldCallback(InterceptFieldCallback callback) {
+		// TODO Auto-generated method stub
+		
+	}
+
+	public FieldHandler getFieldHandler() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	public void setFieldHandler(FieldHandler handler) {
+		// TODO Auto-generated method stub
+		
+	}
+}
+

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/HbmLintAllTests.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/HbmLintAllTests.java	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/HbmLintAllTests.java	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,17 @@
+package org.hibernate.tool.hbmlint;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class HbmLintAllTests {
+
+	public static Test suite() {
+		TestSuite suite = new TestSuite( "Test for org.hibernate.tool.hbmlint" );
+		//$JUnit-BEGIN$
+		suite.addTestSuite( HbmLintTest.class );
+		suite.addTestSuite( SchemaAnalyzerTest.class );
+		//$JUnit-END$
+		return suite;
+	}
+
+}

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/HbmLintTest.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/HbmLintTest.java	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/HbmLintTest.java	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,94 @@
+package org.hibernate.tool.hbmlint;
+
+import java.util.List;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.tool.JDBCMetaDataBinderTestCase;
+import org.hibernate.tool.hbm2x.HbmLintExporter;
+import org.hibernate.tool.hbmlint.detector.BadCachingDetector;
+import org.hibernate.tool.hbmlint.detector.InstrumentationDetector;
+import org.hibernate.tool.hbmlint.detector.ShadowedIdentifierDetector;
+
+public class HbmLintTest extends JDBCMetaDataBinderTestCase {
+
+	public HbmLintTest() {
+		super();
+	}
+
+	protected String[] getMappings() {
+		return new String[] { "hbmlint/CachingSettings.hbm.xml", "hbmlint/IdentifierIssues.hbm.xml", "hbmlint/BrokenLazy.hbm.xml" };
+	}
+	
+	public void testExporter() {
+	
+		Configuration cfg = new Configuration();
+		addMappings( getMappings(), cfg );
+		cfg.buildMappings();
+	
+		new HbmLintExporter(cfg, getOutputDir()).start();
+		
+	}
+	public void testValidateCache() {
+		
+		Configuration cfg = new Configuration();
+		addMappings( getMappings(), cfg );
+		cfg.buildMappings();
+		
+		HbmLint analyzer = new HbmLint(new Detector[] { new BadCachingDetector() });
+		
+		analyzer.analyze(cfg);
+		
+		List result = analyzer.getResults();
+		
+		assertEquals(1,result.size());
+
+		System.out.println(result);
+		
+	}
+
+	public void testValidateIdentifier() {
+		
+		Configuration cfg = new Configuration();
+		addMappings( getMappings(), cfg );
+		cfg.buildMappings();
+		
+		HbmLint analyzer = new HbmLint(new Detector[] { new ShadowedIdentifierDetector() });
+		
+		analyzer.analyze(cfg);
+		
+		List result = analyzer.getResults();
+		
+		assertEquals(1,result.size());
+
+		System.out.println(result);
+		
+	}
+	
+	public void testBytecodeRestrictions() {
+		
+		Configuration cfg = new Configuration();
+		addMappings( getMappings(), cfg );
+		cfg.buildMappings();
+		
+		HbmLint analyzer = new HbmLint(new Detector[] { new InstrumentationDetector() });
+		
+		analyzer.analyze(cfg);
+		
+		List result = analyzer.getResults();
+		
+		assertEquals(2,result.size());
+
+		System.out.println(result);
+		
+	}
+	
+	protected String[] getCreateSQL() {
+		return new String[0];// { "create table Category (id numeric(5), parent_id numeric(5))" };
+	}
+
+	protected String[] getDropSQL() {
+		return new String[0];// { "drop table Category" };
+	}
+	
+	
+}

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/IdentifierIssues.hbm.xml
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/IdentifierIssues.hbm.xml	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/IdentifierIssues.hbm.xml	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC 
+	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.tool.hbmlint">
+
+    <!--  category has caching for collection but its target is not cached -->
+    <class name="IdentifierProblem">
+    
+    	<id name="name" type="long">
+    		<generator class="native"/>
+    	</id>
+		
+		<property name="id" type="string"/>
+    	
+	</class>
+
+</hibernate-mapping>

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/SchemaAnalyzerTest.java
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/SchemaAnalyzerTest.java	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/SchemaAnalyzerTest.java	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,100 @@
+package org.hibernate.tool.hbmlint;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.hibernate.cfg.Configuration;
+import org.hibernate.mapping.Table;
+import org.hibernate.tool.JDBCMetaDataBinderTestCase;
+import org.hibernate.tool.hbm2x.HbmLintExporter;
+import org.hibernate.tool.hbmlint.detector.SchemaByMetaDataDetector;
+
+public class SchemaAnalyzerTest extends JDBCMetaDataBinderTestCase {
+
+	public SchemaAnalyzerTest() {
+		super();
+	}
+
+	protected String[] getMappings() {
+		return new String[] { "hbmlint/SchemaIssues.hbm.xml" };
+	}
+
+	static class MockCollector implements IssueCollector {
+		List problems = new ArrayList();
+		
+		public void reportIssue(Issue analyze) {
+			
+			problems.add(analyze);
+		}		
+	}
+	
+	public void testSchemaAnalyzer() {
+		Configuration cfg = new Configuration();
+		addMappings( getMappings(), cfg );
+		cfg.buildMappings();
+	
+		SchemaByMetaDataDetector analyzer = new SchemaByMetaDataDetector();
+		analyzer.initialize( cfg, cfg.buildSettings() );
+		
+		Iterator tableMappings = cfg.getTableMappings();
+		
+		
+		while ( tableMappings.hasNext() ) {
+			Table table = (Table) tableMappings.next();
+		
+			MockCollector mc = new MockCollector();
+			
+			if(table.getName().equalsIgnoreCase( "missingtable" )) {
+				analyzer.visit( cfg, table, mc );				
+				assertEquals(mc.problems.size(),1);
+				Issue ap = (Issue) mc.problems.get( 0 );
+				assertTrue(ap.getDescription().indexOf( "Missing table" ) >=0);
+			} else if(table.getName().equalsIgnoreCase( "category" )) {
+				analyzer.visit( cfg, table, mc );
+				assertEquals(mc.problems.size(),1);
+				Issue ap = (Issue) mc.problems.get( 0 );
+				assertTrue(ap.getDescription().indexOf( "missing column: name" ) >=0);							
+			} else if(table.getName().equalsIgnoreCase( "badtype" )) {
+				analyzer.visit( cfg, table, mc );
+				assertEquals(mc.problems.size(),1);
+				Issue ap = (Issue) mc.problems.get( 0 );
+				assertTrue(ap.getDescription().indexOf( "wrong column type for name" ) >=0);
+			} else {
+				fail("Unkown table " + table);
+			}
+		}
+		
+		MockCollector mc = new MockCollector();
+		analyzer.visitGenerators( cfg, mc );
+		assertEquals(1,mc.problems.size());
+		Issue issue = (Issue) mc.problems.get( 0 );
+		assertTrue(issue.getDescription().indexOf( "hibernate_unique_key" ) >=0);
+		
+	}
+	
+	
+		
+		public void testExporter() {
+			
+			Configuration cfg = new Configuration();
+			addMappings( getMappings(), cfg );
+			cfg.buildMappings();
+		
+			new HbmLintExporter(cfg, getOutputDir()).start();
+			
+		}
+		
+	protected String[] getCreateSQL() {
+		return new String[] { "create table Category (id int, parent_id numeric(5))",
+				"create table BadType (id int, name varchar(100))",
+				"create sequence should_be_there start with 1",
+				"create table hilo_table (id int)"};
+	}
+
+	protected String[] getDropSQL() {
+		return new String[] { "drop table Category", "drop table BadType", "drop sequence should_be_there", "drop table hilo_table" };
+	}
+	
+	
+}

Added: trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/SchemaIssues.hbm.xml
===================================================================
--- trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/SchemaIssues.hbm.xml	2006-10-19 17:10:48 UTC (rev 10624)
+++ trunk/HibernateExt/tools/src/test/org/hibernate/tool/hbmlint/SchemaIssues.hbm.xml	2006-10-19 17:11:24 UTC (rev 10625)
@@ -0,0 +1,37 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC 
+	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="org.hibernate.tool.hbmlint">
+
+    <class name="Category">
+    
+    	<id name="id" type="int">
+    		<generator class="sequence">
+    			<param name="sequence">should_be_there</param>
+    		</generator>
+    	</id>
+		
+		<property name="name" type="string"/>
+		
+	</class>
+
+    <class name="BadType">
+    
+    	<id name="id" type="int">
+    		<generator class="hilo"/>
+    	</id>
+		
+		<property name="name" type="text"/>
+		
+	</class>
+
+	<class name="MissingTable">
+		<id name="id" type="long">
+    		<generator class="hilo">
+    			<param name="table">hilo_table</param>
+    		</generator>
+    	</id>		
+	</class>	
+</hibernate-mapping>




More information about the hibernate-commits mailing list