Search in sources :

Example 16 with Cfg2HbmTool

use of org.hibernate.tool.hbm2x.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.

the class Cfg2HbmToolFacadeTest method setUp.

@Before
public void setUp() {
    cfg2HbmTool = new Cfg2HbmTool();
    cfg2HbmToolFacade = new AbstractCfg2HbmToolFacade(FACADE_FACTORY, cfg2HbmTool) {
    };
}
Also used : AbstractCfg2HbmToolFacade(org.jboss.tools.hibernate.runtime.common.AbstractCfg2HbmToolFacade) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) ICfg2HbmTool(org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool) Before(org.junit.Before)

Example 17 with Cfg2HbmTool

use of org.hibernate.tool.hbm2x.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterExtensionTest method testSuperExportPOJO.

@Test
public void testSuperExportPOJO() {
    ArtifactCollector artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    File[] hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.assertFalse(new File("foo" + File.separator + "Bar.hbm.xml").exists());
    Map<String, Object> additionalContext = new HashMap<String, Object>();
    Cfg2HbmTool c2h = new Cfg2HbmTool();
    additionalContext.put("date", new Date().toString());
    additionalContext.put("version", Version.getDefault().toString());
    additionalContext.put("c2h", c2h);
    hibernateMappingExporterExtension.superExportPOJO(additionalContext, pojoClass);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 1);
    Assert.assertEquals("foo" + File.separator + "Bar.hbm.xml", hbmXmlFiles[0].getPath());
    Assert.assertTrue(new File("foo" + File.separator + "Bar.hbm.xml").exists());
}
Also used : HashMap(java.util.HashMap) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 18 with Cfg2HbmTool

use of org.hibernate.tool.hbm2x.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterExtensionTest method testExportPOJO.

@Test
public void testExportPOJO() throws Exception {
    // first without a delegate exporter
    ArtifactCollector artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    File[] hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.assertFalse(new File("foo" + File.separator + "Bar.hbm.xml").exists());
    Map<Object, Object> additionalContext = new HashMap<Object, Object>();
    Cfg2HbmTool c2h = new Cfg2HbmTool();
    additionalContext.put("date", new Date().toString());
    additionalContext.put("version", Version.getDefault().toString());
    additionalContext.put("c2h", c2h);
    hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 1);
    Assert.assertEquals("foo" + File.separator + "Bar.hbm.xml", hbmXmlFiles[0].getPath());
    Assert.assertTrue(new File("foo" + File.separator + "Bar.hbm.xml").exists());
    Assert.assertNull(methodName);
    Assert.assertNull(arguments);
    // then with a delegate exporter
    artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
    delegateField.setAccessible(true);
    delegateField.set(hibernateMappingExporterExtension, exportPojoDelegate);
    hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.assertEquals("exportPOJO", methodName);
    Assert.assertSame(additionalContext, arguments[0]);
    Assert.assertSame(pojoClass, ((IFacade) arguments[1]).getTarget());
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 19 with Cfg2HbmTool

use of org.hibernate.tool.hbm2x.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterFacadeTest method testExportPOJO.

@Test
public void testExportPOJO() throws Exception {
    RootClass persistentClass = new RootClass();
    Table rootTable = new Table();
    rootTable.setName("FOO");
    persistentClass.setTable(rootTable);
    persistentClass.setEntityName("Foo");
    persistentClass.setClassName("Foo");
    IPOJOClass pojoClass = FACADE_FACTORY.createPOJOClass(new EntityPOJOClass(persistentClass, new Cfg2JavaTool()));
    Map<Object, Object> additionalContext = new HashMap<Object, Object>();
    Cfg2HbmTool c2h = new Cfg2HbmTool();
    additionalContext.put("date", new Date().toString());
    additionalContext.put("version", Version.getDefault().toString());
    additionalContext.put("c2h", c2h);
    hibernateMappingExporter.setOutputDirectory(outputDir);
    Method setTemplateHelperMethod = AbstractExporter.class.getDeclaredMethod("setTemplateHelper", new Class[] { TemplateHelper.class });
    setTemplateHelperMethod.setAccessible(true);
    TemplateHelper templateHelper = new TemplateHelper();
    templateHelper.init(null, new String[0]);
    setTemplateHelperMethod.invoke(hibernateMappingExporter, new Object[] { templateHelper });
    final File fooHbmXml = new File(outputDir, "Foo.hbm.xml");
    Assert.assertFalse(fooHbmXml.exists());
    hibernateMappingExporterFacade.exportPOJO(additionalContext, pojoClass);
    Assert.assertTrue(fooHbmXml.exists());
    fooHbmXml.delete();
    outputDir.delete();
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) HashMap(java.util.HashMap) TemplateHelper(org.hibernate.tool.hbm2x.TemplateHelper) Method(java.lang.reflect.Method) Date(java.util.Date) EntityPOJOClass(org.hibernate.tool.hbm2x.pojo.EntityPOJOClass) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) Cfg2JavaTool(org.hibernate.tool.hbm2x.Cfg2JavaTool) File(java.io.File) Test(org.junit.Test)

Example 20 with Cfg2HbmTool

use of org.hibernate.tool.hbm2x.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterExtensionTest method testExportPOJO.

@Test
public void testExportPOJO() throws Exception {
    // first without a delegate exporter
    ArtifactCollector artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    File[] hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.assertFalse(new File("foo" + File.separator + "Bar.hbm.xml").exists());
    Map<Object, Object> additionalContext = new HashMap<Object, Object>();
    Cfg2HbmTool c2h = new Cfg2HbmTool();
    additionalContext.put("date", new Date().toString());
    additionalContext.put("version", Version.getDefault().toString());
    additionalContext.put("c2h", c2h);
    hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 1);
    Assert.assertEquals("foo" + File.separator + "Bar.hbm.xml", hbmXmlFiles[0].getPath());
    Assert.assertTrue(new File("foo" + File.separator + "Bar.hbm.xml").exists());
    Assert.assertNull(methodName);
    Assert.assertNull(arguments);
    // then with a delegate exporter
    artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
    delegateField.setAccessible(true);
    delegateField.set(hibernateMappingExporterExtension, exportPojoDelegate);
    hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.assertEquals("exportPOJO", methodName);
    Assert.assertSame(additionalContext, arguments[0]);
    Assert.assertSame(pojoClass, ((IFacade) arguments[1]).getTarget());
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Cfg2HbmTool (org.hibernate.tool.hbm2x.Cfg2HbmTool)44 Test (org.junit.Test)36 File (java.io.File)24 Date (java.util.Date)24 HashMap (java.util.HashMap)24 ICfg2HbmTool (org.jboss.tools.hibernate.runtime.spi.ICfg2HbmTool)20 ArtifactCollector (org.hibernate.tool.hbm2x.ArtifactCollector)16 Field (java.lang.reflect.Field)8 Method (java.lang.reflect.Method)8 RootClass (org.hibernate.mapping.RootClass)8 Table (org.hibernate.mapping.Table)8 Cfg2JavaTool (org.hibernate.tool.hbm2x.Cfg2JavaTool)8 TemplateHelper (org.hibernate.tool.hbm2x.TemplateHelper)8 EntityPOJOClass (org.hibernate.tool.hbm2x.pojo.EntityPOJOClass)8 AbstractCfg2HbmToolFacade (org.jboss.tools.hibernate.runtime.common.AbstractCfg2HbmToolFacade)8 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)8 Before (org.junit.Before)8 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)4