[hibernate-commits] Hibernate SVN: r10999 - in branches/Branch_3_2/HibernateExt/tools/src: java/org/hibernate/tool/ant java/org/hibernate/tool/hbm2x test/org/hibernate/tool/ant test/org/hibernate/tool/hbm2x testsupport

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Mon Dec 18 15:58:27 EST 2006


Author: max.andersen at jboss.com
Date: 2006-12-18 15:58:17 -0500 (Mon, 18 Dec 2006)
New Revision: 10999

Added:
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java
Removed:
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java
Modified:
   branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java
   branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java
   branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntAllTests.java
   branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java
   branches/Branch_3_2/HibernateExt/tools/src/testsupport/anttest-build.xml
Log:
HBX-842 add control to hbmtemplate about what model parts should be processed

Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java	2006-12-15 16:30:55 UTC (rev 10998)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/GenericExporterTask.java	2006-12-18 20:58:17 UTC (rev 10999)
@@ -22,6 +22,7 @@
 	String templateName;
 	String exporterClass;
 	String filePattern;
+	String forEach;
 	
 	/**
 	 * The FilePattern defines the pattern used to generate files.
@@ -31,6 +32,10 @@
 		this.filePattern = filePattern;
 	}
 	
+	public void setForEach(String forEach) {
+		this.forEach = forEach;
+	}
+	
 	public void setTemplate(String templateName) {
 		this.templateName = templateName;
 	}
@@ -62,7 +67,8 @@
 		if(exp instanceof GenericExporter) {
 			GenericExporter exporter = (GenericExporter) exp;
 			if(filePattern!=null) exporter.setFilePattern(filePattern);
-			if(templateName!=null) exporter.setTemplateName(templateName);			
+			if(templateName!=null) exporter.setTemplateName(templateName);
+			if(forEach!=null) exporter.setForEach(forEach);
 		}
 		
 		return exp;

Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java	2006-12-15 16:30:55 UTC (rev 10998)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/ant/HibernateToolTask.java	2006-12-18 20:58:17 UTC (rev 10999)
@@ -148,7 +148,8 @@
     public void setClasspath(Path s) {
 		classPath = s;
     }
-
+    
+    
     /**
      * Adds a path to the classpath.
      *
@@ -324,4 +325,5 @@
 		properties.put(property.getKey(), property.getValue());
 	}
 	
+	
 }

Modified: branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java	2006-12-15 16:30:55 UTC (rev 10998)
+++ branches/Branch_3_2/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/GenericExporter.java	2006-12-18 20:58:17 UTC (rev 10999)
@@ -1,11 +1,15 @@
 package org.hibernate.tool.hbm2x;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
+import java.util.StringTokenizer;
 
 import org.hibernate.cfg.Configuration;
+import org.hibernate.engine.CascadeStyle;
 import org.hibernate.mapping.Component;
 import org.hibernate.tool.hbm2x.pojo.ComponentPOJOClass;
 import org.hibernate.tool.hbm2x.pojo.POJOClass;
@@ -14,8 +18,56 @@
 
 public class GenericExporter extends AbstractExporter {
 
+	static abstract class ModelIterator {		
+		abstract void process(GenericExporter ge);
+	}
+	
+	static Map modelIterators = new HashMap();
+	static {
+		modelIterators.put( "configuration", new ModelIterator() {
+
+			void process(GenericExporter ge) {
+				TemplateProducer producer = new TemplateProducer(ge.getTemplateHelper(),ge.getArtifactCollector());
+				producer.produce(new HashMap(), ge.getTemplateName(), new File(ge.getOutputDirectory(),ge.filePattern), ge.templateName);				
+			}
+			
+		});
+		modelIterators.put("entity", new ModelIterator() {
+		
+			void process(GenericExporter ge) {
+				Iterator iterator = ge.getCfg2JavaTool().getPOJOIterator(ge.getConfiguration().getClassMappings());
+				Map additionalContext = new HashMap();
+				while ( iterator.hasNext() ) {					
+					POJOClass element = (POJOClass) iterator.next();											
+					ge.exportPersistentClass( additionalContext, element );
+				}
+			}
+		});
+		modelIterators.put("component", new ModelIterator() {
+			
+			void process(GenericExporter ge) {
+				Map components = new HashMap();
+				
+				Iterator iterator = ge.getCfg2JavaTool().getPOJOIterator(ge.getConfiguration().getClassMappings());
+				Map additionalContext = new HashMap();
+				while ( iterator.hasNext() ) {					
+					POJOClass element = (POJOClass) iterator.next();
+					ConfigurationNavigator.collectComponents(components, element);											
+				}
+						
+				iterator = components.values().iterator();
+				while ( iterator.hasNext() ) {					
+					Component component = (Component) iterator.next();
+					ComponentPOJOClass element = new ComponentPOJOClass(component,ge.getCfg2JavaTool());
+					ge.exportComponent( additionalContext, element );
+				}
+			}
+		});
+	}
+	
 	private String templateName;
 	private String filePattern;
+	private String forEach;
 	
 	public GenericExporter(Configuration cfg, File outputdir) {
 		super(cfg,outputdir);
@@ -31,38 +83,49 @@
 	public void setTemplateName(String templateName) {
 		this.templateName = templateName;
 	}
-			
+		
+	
+	public void setForEach(String foreach) {
+		this.forEach = foreach;
+	}
+	
+	
 	protected void doStart() {
 				
-		if(filePattern==null) throw new ExporterException("File pattern not set on " + this.getClass());
-		if(templateName==null) throw new ExporterException("Template name not set on " + this.getClass());
+		if(filePattern==null) {
+			throw new ExporterException("File pattern not set on " + this.getClass());
+		}
+		if(templateName==null) {
+			throw new ExporterException("Template name not set on " + this.getClass());
+		}
 		
-		if(filePattern.indexOf("{class-name}")>=0) {				
-			exportClasses();
+		List exporters = new ArrayList();
+	
+		if(StringHelper.isEmpty( forEach )) {
+			if(filePattern.indexOf("{class-name}")>=0) {				
+				exporters.add( modelIterators.get( "entity" ) );
+				exporters.add( modelIterators.get( "component") );
+			} else {
+				exporters.add( modelIterators.get( "configuration" ));			
+			}
 		} else {
-			TemplateProducer producer = new TemplateProducer(getTemplateHelper(),getArtifactCollector());
-			producer.produce(new HashMap(), getTemplateName(), new File(getOutputDirectory(),filePattern), templateName);
+			StringTokenizer tokens = new StringTokenizer(forEach, ",");
+		 
+			while ( tokens.hasMoreTokens() ) {
+				String nextToken = tokens.nextToken();
+				Object object = modelIterators.get(nextToken);
+				if(object==null) {
+					throw new ExporterException("for-each does not support [" + nextToken + "]");
+				}
+				exporters.add( object );
+			}
 		}
-	}
 
-	private void exportClasses() {
-		Map components = new HashMap();
-		
-		Iterator iterator = getCfg2JavaTool().getPOJOIterator(getConfiguration().getClassMappings());
-		Map additionalContext = new HashMap();
-		while ( iterator.hasNext() ) {					
-			POJOClass element = (POJOClass) iterator.next();
-			ConfigurationNavigator.collectComponents(components, element);						
-			exportPersistentClass( additionalContext, element );
+		Iterator it = exporters.iterator();
+		while(it.hasNext()) {
+			ModelIterator mit = (ModelIterator) it.next();
+			mit.process( this );
 		}
-				
-		iterator = components.values().iterator();
-		while ( iterator.hasNext() ) {					
-			Component component = (Component) iterator.next();
-			ComponentPOJOClass element = new ComponentPOJOClass(component,getCfg2JavaTool());
-			exportComponent( additionalContext, element );
-		}
-				        
 	}
 
 	protected void exportComponent(Map additionalContext, POJOClass element) {

Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntAllTests.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntAllTests.java	2006-12-15 16:30:55 UTC (rev 10998)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntAllTests.java	2006-12-18 20:58:17 UTC (rev 10999)
@@ -8,7 +8,7 @@
 	public static Test suite() {
 		TestSuite suite = new TestSuite("Test for org.hibernate.tool.ant");
 		//$JUnit-BEGIN$
-		suite.addTestSuite(HibernateToolTest.class);
+		suite.addTestSuite(AntHibernateToolTest.class);
 		suite.addTestSuite(SeamAntTest.class);
 		suite.addTestSuite(JavaFormatterTest.class);
 		//$JUnit-END$

Copied: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java (from rev 10966, branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java)
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java	2006-12-09 12:10:27 UTC (rev 10966)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/AntHibernateToolTest.java	2006-12-18 20:58:17 UTC (rev 10999)
@@ -0,0 +1,203 @@
+/*
+ * Created on 13-Feb-2005
+ *
+ */
+package org.hibernate.tool.ant;
+
+import java.io.File;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.tools.ant.BuildException;
+import org.hibernate.tool.test.TestHelper;
+
+/**
+ * @author max
+ *
+ */
+public class AntHibernateToolTest extends BuildFileTestCase {
+
+	private String property;
+	
+	public AntHibernateToolTest(String name) {
+		super(name);
+	}
+	
+	protected void tearDown() throws Exception {
+		executeTarget("cleanup");
+		System.out.println(getLog());
+		super.tearDown();
+	}
+	protected void setUp() throws Exception {
+		configureProject("src/testsupport/anttest-build.xml");
+	}
+	
+	public void testHbm2DDLLogic() {
+		executeTarget("testantcfg");
+		File baseDir = new File(project.getProperty("build.dir"), "topdown");
+		File onlyCreate = new File(baseDir, "onlycreate.sql");
+		File onlyDrop = new File(baseDir, "onlydrop.sql");
+		File dropAndCreate = new File(baseDir, "dropandcreate.sql");
+		
+		assertTrue(onlyCreate.exists());
+		assertTrue(onlyDrop.exists());
+		assertTrue(dropAndCreate.exists());
+		
+		assertNotNull(TestHelper.findFirstString("drop", dropAndCreate));
+		assertNotNull(TestHelper.findFirstString("create", dropAndCreate));
+		
+		assertEquals(null, TestHelper.findFirstString("create", onlyDrop));
+		assertNotNull(TestHelper.findFirstString("drop", onlyDrop));
+		
+		assertEquals(null, TestHelper.findFirstString("drop", onlyCreate));
+		assertNotNull(TestHelper.findFirstString("create", onlyCreate));		
+		
+	}
+
+	public void testJDBCConfiguration() {
+		executeTarget("testantjdbccfg");
+	}
+	
+	public void testAnnotationConfigurationFailureExpected() {
+		executeTarget("testantannotationcfg");
+	}
+	
+	public void testEJB3ConfigurationFailureExpected() {
+		executeTarget("testantejb3cfg");
+		File baseDir = new File(project.getProperty("build.dir"));
+		File ejb3 = new File(baseDir, "ejb3.sql");
+		
+		assertTrue(ejb3.exists());
+		assertEquals(null, TestHelper.findFirstString("drop", ejb3));
+		
+		assertTrue(getLog().indexOf("<ejb3configuration> is deprecated")>0);
+		
+	}
+	
+	public void testJPABogusPUnit() {
+		try {
+			executeTarget("jpa-bogusunit");
+			fail("Bogus unit accepted");
+		} catch(BuildException be) {
+			// should happen
+		}
+	}
+	
+	public void testJPAPUnit() {
+		executeTarget("jpa-punit");		
+	}
+	
+	public void testHbm2JavaConfiguration() {
+		executeTarget("testanthbm2java");
+	}
+	
+	public void testHbm2JavaEJB3Configuration() {
+		executeTarget("testantejb3hbm2java");
+	}
+	
+    public void testCfg2HbmNoError() {
+        executeTarget("testantcfg2hbm1");
+    }
+    
+    public void testCfg2HbmWithCustomReverseNamingStrategy() {
+        executeTarget("testantcfg2hbm2");
+    }
+    
+    public void testCfg2HbmWithInvalidReverseNamingStrategy() {
+        expectSpecificBuildException("testantcfg2hbm3", 
+                "namingStrategy attribute should not be loaded", 
+                "Could not create or find invalid.classname with one argument delegate constructor");
+    }
+    
+    public void testCfg2HbmWithPackageName() {
+        executeTarget("testantcfg2hbm4");
+    }
+    
+    public void testCfg2HbmWithPackageNameAndReverseNamingStrategy() {
+        executeTarget("testantcfg2hbm5");
+    }
+    
+  
+	public void testJDBCConfigWithRevEngXml() {
+		executeTarget("testantjdbccfgoverrides");
+	}
+	
+	public void testProperties() {
+		executeTarget("testproperties");		
+	}
+	
+	public void testGenericExport() {
+		executeTarget("testgeneric");
+		
+		property = project.getProperty("build.dir");
+		assertTrue(new File(property, "generic").exists());
+		assertTrue(new File(property, "generic/org/hibernate/tool/hbm2x/ant/TopDown.quote").exists());
+	}
+	
+	public void testNoConnInfoExport() {
+		executeTarget("noconinfoexport");
+		File baseDir = new File(project.getProperty("build.dir"), "noconinfo");
+		File onlyCreate = new File(baseDir, "noconinfo.sql");
+		
+		assertTrue(onlyCreate.toString() + " should exist", onlyCreate.exists());
+		
+		assertTrue(onlyCreate.length()>0);
+		
+		assertNotNull(TestHelper.findFirstString("create", onlyCreate));
+		
+		
+	}
+
+	public void testNoExporters() {
+		try {
+		executeTarget("testnoexporters");
+		fail("should have failed with no exporters!");
+		} catch(BuildException be) {
+			// should happen!
+			assertTrue(be.getMessage().indexOf("No exporters specified")>=0);
+		}
+		
+	}
+	
+	public void testException() {
+		try {
+		executeTarget("testexceptions");
+		fail("should have failed with an exception!");
+		} catch(BuildException be) {
+			// should happen!			
+		}
+	}
+
+	public void testQuery() {
+		executeTarget("testquery");
+		
+		File baseDir = new File(project.getProperty("build.dir"), "querytest");
+		
+		assertTrue(new File(baseDir, "queryresult.txt").exists());
+		
+	}
+	
+	public void testHbmLint() {
+		executeTarget("testhbmlint");
+		
+		File baseDir = new File(project.getProperty("build.dir"), "linttest");
+		
+		assertTrue(new File(baseDir, "hbmlint-result.txt").exists());
+		
+	}
+	
+	public void testNoConfig() {
+		try {
+			executeTarget("noconfig-shoulderror");
+		} catch(BuildException e) {
+			assertTrue(e.getMessage().indexOf("No configuration specified")>=0);
+		}
+		
+	}
+	public static Test suite() {
+		return new TestSuite(AntHibernateToolTest.class);
+	}
+
+	
+}

Deleted: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java	2006-12-15 16:30:55 UTC (rev 10998)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/ant/HibernateToolTest.java	2006-12-18 20:58:17 UTC (rev 10999)
@@ -1,203 +0,0 @@
-/*
- * Created on 13-Feb-2005
- *
- */
-package org.hibernate.tool.ant;
-
-import java.io.File;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-import org.apache.tools.ant.BuildException;
-import org.hibernate.tool.test.TestHelper;
-
-/**
- * @author max
- *
- */
-public class HibernateToolTest extends BuildFileTestCase {
-
-	private String property;
-	
-	public HibernateToolTest(String name) {
-		super(name);
-	}
-	
-	protected void tearDown() throws Exception {
-		executeTarget("cleanup");
-		System.out.println(getLog());
-		super.tearDown();
-	}
-	protected void setUp() throws Exception {
-		configureProject("src/testsupport/anttest-build.xml");
-	}
-	
-	public void testHbm2DDLLogic() {
-		executeTarget("testantcfg");
-		File baseDir = new File(project.getProperty("build.dir"), "topdown");
-		File onlyCreate = new File(baseDir, "onlycreate.sql");
-		File onlyDrop = new File(baseDir, "onlydrop.sql");
-		File dropAndCreate = new File(baseDir, "dropandcreate.sql");
-		
-		assertTrue(onlyCreate.exists());
-		assertTrue(onlyDrop.exists());
-		assertTrue(dropAndCreate.exists());
-		
-		assertNotNull(TestHelper.findFirstString("drop", dropAndCreate));
-		assertNotNull(TestHelper.findFirstString("create", dropAndCreate));
-		
-		assertEquals(null, TestHelper.findFirstString("create", onlyDrop));
-		assertNotNull(TestHelper.findFirstString("drop", onlyDrop));
-		
-		assertEquals(null, TestHelper.findFirstString("drop", onlyCreate));
-		assertNotNull(TestHelper.findFirstString("create", onlyCreate));		
-		
-	}
-
-	public void testJDBCConfiguration() {
-		executeTarget("testantjdbccfg");
-	}
-	
-	public void testAnnotationConfigurationFailureExpected() {
-		executeTarget("testantannotationcfg");
-	}
-	
-	public void testEJB3ConfigurationFailureExpected() {
-		executeTarget("testantejb3cfg");
-		File baseDir = new File(project.getProperty("build.dir"));
-		File ejb3 = new File(baseDir, "ejb3.sql");
-		
-		assertTrue(ejb3.exists());
-		assertEquals(null, TestHelper.findFirstString("drop", ejb3));
-		
-		assertTrue(getLog().indexOf("<ejb3configuration> is deprecated")>0);
-		
-	}
-	
-	public void testJPABogusPUnit() {
-		try {
-			executeTarget("jpa-bogusunit");
-			fail("Bogus unit accepted");
-		} catch(BuildException be) {
-			// should happen
-		}
-	}
-	
-	public void testJPAPUnit() {
-		executeTarget("jpa-punit");		
-	}
-	
-	public void testHbm2JavaConfiguration() {
-		executeTarget("testanthbm2java");
-	}
-	
-	public void testHbm2JavaEJB3Configuration() {
-		executeTarget("testantejb3hbm2java");
-	}
-	
-    public void testCfg2HbmNoError() {
-        executeTarget("testantcfg2hbm1");
-    }
-    
-    public void testCfg2HbmWithCustomReverseNamingStrategy() {
-        executeTarget("testantcfg2hbm2");
-    }
-    
-    public void testCfg2HbmWithInvalidReverseNamingStrategy() {
-        expectSpecificBuildException("testantcfg2hbm3", 
-                "namingStrategy attribute should not be loaded", 
-                "Could not create or find invalid.classname with one argument delegate constructor");
-    }
-    
-    public void testCfg2HbmWithPackageName() {
-        executeTarget("testantcfg2hbm4");
-    }
-    
-    public void testCfg2HbmWithPackageNameAndReverseNamingStrategy() {
-        executeTarget("testantcfg2hbm5");
-    }
-    
-  
-	public void testJDBCConfigWithRevEngXml() {
-		executeTarget("testantjdbccfgoverrides");
-	}
-	
-	public void testProperties() {
-		executeTarget("testproperties");		
-	}
-	
-	public void testGenericExport() {
-		executeTarget("testgeneric");
-		
-		property = project.getProperty("build.dir");
-		assertTrue(new File(property, "generic").exists());
-		assertTrue(new File(property, "generic/org/hibernate/tool/hbm2x/ant/TopDown.quote").exists());
-	}
-	
-	public void testNoConnInfoExport() {
-		executeTarget("noconinfoexport");
-		File baseDir = new File(project.getProperty("build.dir"), "noconinfo");
-		File onlyCreate = new File(baseDir, "noconinfo.sql");
-		
-		assertTrue(onlyCreate.toString() + " should exist", onlyCreate.exists());
-		
-		assertTrue(onlyCreate.length()>0);
-		
-		assertNotNull(TestHelper.findFirstString("create", onlyCreate));
-		
-		
-	}
-
-	public void testNoExporters() {
-		try {
-		executeTarget("testnoexporters");
-		fail("should have failed with no exporters!");
-		} catch(BuildException be) {
-			// should happen!
-			assertTrue(be.getMessage().indexOf("No exporters specified")>=0);
-		}
-		
-	}
-	
-	public void testException() {
-		try {
-		executeTarget("testexceptions");
-		fail("should have failed with an exception!");
-		} catch(BuildException be) {
-			// should happen!			
-		}
-	}
-
-	public void testQuery() {
-		executeTarget("testquery");
-		
-		File baseDir = new File(project.getProperty("build.dir"), "querytest");
-		
-		assertTrue(new File(baseDir, "queryresult.txt").exists());
-		
-	}
-	
-	public void testHbmLint() {
-		executeTarget("testhbmlint");
-		
-		File baseDir = new File(project.getProperty("build.dir"), "linttest");
-		
-		assertTrue(new File(baseDir, "hbmlint-result.txt").exists());
-		
-	}
-	
-	public void testNoConfig() {
-		try {
-			executeTarget("noconfig-shoulderror");
-		} catch(BuildException e) {
-			assertTrue(e.getMessage().indexOf("No configuration specified")>=0);
-		}
-		
-	}
-	public static Test suite() {
-		return new TestSuite(HibernateToolTest.class);
-	}
-
-	
-}

Modified: branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java	2006-12-15 16:30:55 UTC (rev 10998)
+++ branches/Branch_3_2/HibernateExt/tools/src/test/org/hibernate/tool/hbm2x/GenericExporterTest.java	2006-12-18 20:58:17 UTC (rev 10999)
@@ -101,6 +101,41 @@
 		"genericHelloUniverse.txt" ) );
 	}
 
+	public void testForEachGeneration() {
+
+		GenericExporter ge = new GenericExporter();
+		ge.setConfiguration(getCfg());
+		ge.setOutputDirectory(getOutputDir());
+		ge.setTemplateName("generictemplates/pojo/generic-class.ftl");
+		ge.setFilePattern("{package-name}/generic{class-name}.txt");
+		ge.setForEach("entity");
+		ge.start();
+
+		assertFileAndExists( new File( getOutputDir(),
+				"org/hibernate/tool/hbm2x/genericAuthor.txt" ) );
+		
+		assertFileAndExists( new File( getOutputDir(),
+		"org/hibernate/tool/hbm2x/genericArticle.txt" ) );
+
+		assertFileAndExists( new File( getOutputDir(),
+		"org/hibernate/tool/hbm2x/genericArticle.txt" ) );		
+		
+		assertFalse("component file should not exist", new File( getOutputDir(), "genericUniversalAddress.txt" ).exists());
+		
+		
+		assertFileAndExists( new File( getOutputDir(),
+		"genericHelloUniverse.txt" ) );
+		
+		
+		try {
+			ge.setForEach( "does, not, exist" );
+			ge.start();
+			fail();
+		} catch(Exception e) {
+			e.printStackTrace();
+		}
+	}
+	
 	public void testPropertySet() throws FileNotFoundException, IOException {
 		GenericExporter ge = new GenericExporter();
 		ge.setConfiguration(getCfg());

Modified: branches/Branch_3_2/HibernateExt/tools/src/testsupport/anttest-build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/tools/src/testsupport/anttest-build.xml	2006-12-15 16:30:55 UTC (rev 10998)
+++ branches/Branch_3_2/HibernateExt/tools/src/testsupport/anttest-build.xml	2006-12-18 20:58:17 UTC (rev 10999)
@@ -133,7 +133,7 @@
 				</fileset>
 			</configuration>
 
-			<hbmtemplate templateprefix="pojo/" template="pojo/Pojo.ftl" filepattern="X{package-name}/{class-name}.java">
+			<hbmtemplate templateprefix="pojo/" template="pojo/Pojo.ftl" filepattern="X{package-name}/{class-name}.java" foreach="entity">
 				<property key="jdk5" value="false" />
 				<property key="ejb3" value="false" />
 			</hbmtemplate>




More information about the hibernate-commits mailing list