Index: D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmToolTest.java =================================================================== --- D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmToolTest.java (revision 0) +++ D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmToolTest.java (revision 0) @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2007-2008 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.hibernate.tool.hbm2x.hbm2hbmxml; + +import org.hibernate.mapping.JoinedSubclass; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.mapping.RootClass; +import org.hibernate.mapping.SingleTableSubclass; +import org.hibernate.mapping.Subclass; +import org.hibernate.mapping.UnionSubclass; +import org.hibernate.tool.hbm2x.Cfg2HbmTool; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * @author Dmitry Geraskov + * + */ +public class Cfg2HbmToolTest extends TestCase { + + public void testNeedsTable(){ + Cfg2HbmTool c2h = new Cfg2HbmTool(); + PersistentClass pc = new RootClass(); + assertTrue(c2h.needsTable(pc)); + assertTrue(c2h.needsTable(new JoinedSubclass(pc))); + assertTrue(c2h.needsTable(new UnionSubclass(pc))); + assertFalse(c2h.needsTable(new Subclass(pc))); + assertFalse(c2h.needsTable(new SingleTableSubclass(pc))); + } + + public static Test suite() { + return new TestSuite(Cfg2HbmToolTest.class); + } + +} Property changes on: D:\workspaces\hibernate-ganymede\hibernateext_tools\src\test\org\hibernate\tool\hbm2x\hbm2hbmxml\Cfg2HbmToolTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Id Revision Date Name: svn:eol-style + native Index: D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/AbstractTest.java =================================================================== --- D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/AbstractTest.java (revision 0) +++ D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/AbstractTest.java (revision 0) @@ -0,0 +1,105 @@ +/******************************************************************************* + * Copyright (c) 2007-2009 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + * + * Contributor: + * Red Hat, Inc. - initial API and implementation + ******************************************************************************/ +package org.hibernate.tool.hbm2x.hbm2hbmxml; + +import java.io.File; +import java.util.Iterator; +import java.util.List; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.XPath; +import org.dom4j.io.SAXReader; +import org.hibernate.cfg.Configuration; +import org.hibernate.mapping.Backref; +import org.hibernate.mapping.PersistentClass; +import org.hibernate.tool.NonReflectiveTestCase; +import org.hibernate.tool.hbm2x.Exporter; +import org.hibernate.tool.hbm2x.HibernateMappingExporter; + +/** + * @author Dmitry Geraskov + * + */ +public class AbstractTest extends NonReflectiveTestCase { + + private String mappingFile = "Car.hbm.xml"; + + private Exporter hbmexporter; + + /** + * @param name + */ + public AbstractTest(String name) { + super(name, "cfg2hbmoutput"); + } + + protected String[] getMappings() { + return new String[] { + mappingFile + }; + } + + protected void setUp() throws Exception { + super.setUp(); + + hbmexporter = new HibernateMappingExporter(getCfg(), getOutputDir() ); + hbmexporter.start(); + } + + public void testAllFilesExistence() { + assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "Car.hbm.xml") ); + assertFileAndExists(new File(getOutputDir().getAbsolutePath(), getBaseForMappings() + "CarPart.hbm.xml") ); + } + + public void testAbstractPresent() { + File outputXml = new File(getOutputDir().getAbsolutePath() + "/org/hibernate/tool/hbm2x/hbm2hbmxml/CarPart.hbm.xml"); + assertFileAndExists(outputXml); + + SAXReader xmlReader = this.getSAXReader(); + + Document document; + try { + document = xmlReader.read(outputXml); + XPath xpath = DocumentHelper.createXPath("//hibernate-mapping/class"); + List list = xpath.selectNodes(document); + assertEquals("Expected to get one class element", 1, list.size()); + Element node = (Element) list.get(0); + assertNotNull("Abstract attrinute was not exported.", node.attribute( "abstract" )); + assertEquals(node.attribute( "abstract" ).getText(),"true"); + } catch (DocumentException e) { + fail("Can't parse file " + outputXml.getAbsolutePath()); + } + } + + public void testReadable() { + Configuration cfg = new Configuration(); + + cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "Car.hbm.xml")); + cfg.addFile(new File(getOutputDir(), getBaseForMappings() + "CarPart.hbm.xml")); + + cfg.buildMappings(); + } + + protected String getBaseForMappings() { + return "org/hibernate/tool/hbm2x/hbm2hbmxml/"; + } + + public static Test suite() { + return new TestSuite(AbstractTest.class); + } + +} Property changes on: D:\workspaces\hibernate-ganymede\hibernateext_tools\src\test\org\hibernate\tool\hbm2x\hbm2hbmxml\AbstractTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Author Id Revision Date Name: svn:eol-style + native Index: D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java =================================================================== --- D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java (revision 16054) +++ D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Cfg2HbmAllTests.java (working copy) @@ -19,6 +19,8 @@ suite.addTest(InheritanceTest.suite()); suite.addTest(SetElementTest.suite()); suite.addTest(BackrefTest.suite()); + suite.addTest(Cfg2HbmToolTest.suite()); + suite.addTest(AbstractTest.suite()); //$JUnit-END$ return suite; } Index: D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Car.hbm.xml =================================================================== --- D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Car.hbm.xml (revision 16054) +++ D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/Car.hbm.xml (working copy) @@ -16,7 +16,7 @@ - + Index: D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/CarPart.java =================================================================== --- D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/CarPart.java (revision 16054) +++ D:/workspaces/hibernate-ganymede/hibernateext_tools/src/test/org/hibernate/tool/hbm2x/hbm2hbmxml/CarPart.java (working copy) @@ -3,7 +3,7 @@ /** * @author Paco Hern�ndez */ -public class CarPart implements java.io.Serializable { +public abstract class CarPart implements java.io.Serializable { private long id; private String partName;