use of org.hibernate.tool.internal.export.hbm.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class HibernateMappingExporterExtensionTest method testSuperExportPOJO.
@Test
public void testSuperExportPOJO() throws Exception {
initializeTemplateHelper();
ArtifactCollector artifactCollector = new DefaultArtifactCollector();
hibernateMappingExporterExtension.getProperties().put(ExporterConstants.ARTIFACT_COLLECTOR, artifactCollector);
File[] hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
assertTrue(hbmXmlFiles.length == 0);
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.CURRENT_VERSION);
additionalContext.put("c2h", c2h);
hibernateMappingExporterExtension.superExportPOJO(additionalContext, createPojoClass());
hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
assertTrue(hbmXmlFiles.length == 1);
assertEquals("foo" + File.separator + "Bar.hbm.xml", hbmXmlFiles[0].getPath());
assertTrue(new File("foo" + File.separator + "Bar.hbm.xml").exists());
}
use of org.hibernate.tool.internal.export.hbm.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class HibernateMappingExporterExtensionTest method testExportPOJO.
@Test
public void testExportPOJO() throws Exception {
initializeTemplateHelper();
POJOClass pojoClass = createPojoClass();
// first without a delegate exporter
ArtifactCollector artifactCollector = new DefaultArtifactCollector();
hibernateMappingExporterExtension.getProperties().put(ExporterConstants.ARTIFACT_COLLECTOR, artifactCollector);
File[] hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
Map<Object, Object> additionalContext = new HashMap<Object, Object>();
Cfg2HbmTool c2h = new Cfg2HbmTool();
additionalContext.put("date", new Date().toString());
additionalContext.put("version", Version.CURRENT_VERSION);
additionalContext.put("c2h", c2h);
assertTrue(hbmXmlFiles.length == 0);
assertFalse(new File("foo" + File.separator + "Bar.hbm.xml").exists());
hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
assertTrue(hbmXmlFiles.length == 1);
assertEquals("foo" + File.separator + "Bar.hbm.xml", hbmXmlFiles[0].getPath());
assertTrue(new File("foo" + File.separator + "Bar.hbm.xml").exists());
// then with a delegate exporter
artifactCollector = new DefaultArtifactCollector();
hibernateMappingExporterExtension.getProperties().put(ExporterConstants.ARTIFACT_COLLECTOR, artifactCollector);
final HashMap<Object, Object> arguments = new HashMap<Object, Object>();
IExportPOJODelegate exportPojoDelegate = new IExportPOJODelegate() {
@Override
public void exportPOJO(Map<Object, Object> map, IPOJOClass pojoClass) {
arguments.put("map", map);
arguments.put("pojoClass", pojoClass);
}
};
hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
delegateField.setAccessible(true);
delegateField.set(hibernateMappingExporterExtension, exportPojoDelegate);
assertTrue(hbmXmlFiles.length == 0);
assertNull(arguments.get("map"));
assertNull(arguments.get("pojoClass"));
hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
assertTrue(hbmXmlFiles.length == 0);
assertSame(additionalContext, arguments.get("map"));
assertSame(pojoClass, ((IFacade) arguments.get("pojoClass")).getTarget());
}
use of org.hibernate.tool.internal.export.hbm.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class HibernateMappingExporterFacadeTest method testExportPOJO.
@Test
public void testExportPOJO() throws Exception {
RootClass persistentClass = new RootClass(DummyMetadataBuildingContext.INSTANCE);
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.CURRENT_VERSION);
additionalContext.put("c2h", c2h);
hibernateMappingExporter.getProperties().put(ExporterConstants.DESTINATION_FOLDER, 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");
assertFalse(fooHbmXml.exists());
hibernateMappingExporterFacade.exportPOJO(additionalContext, pojoClass);
assertTrue(fooHbmXml.exists());
fooHbmXml.delete();
outputDir.delete();
}
use of org.hibernate.tool.internal.export.hbm.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateCfg2HbmTool.
@Test
public void testCreateCfg2HbmTool() {
Cfg2HbmTool cfg2HbmTool = new Cfg2HbmTool();
ICfg2HbmTool facade = facadeFactory.createCfg2HbmTool(cfg2HbmTool);
assertSame(cfg2HbmTool, ((IFacade) facade).getTarget());
}
use of org.hibernate.tool.internal.export.hbm.Cfg2HbmTool in project jbosstools-hibernate by jbosstools.
the class Cfg2HbmToolFacadeTest method before.
@BeforeEach
public void before() {
cfg2HbmToolTarget = new Cfg2HbmTool();
cfg2HbmToolFacade = new AbstractCfg2HbmToolFacade(FACADE_FACTORY, cfg2HbmToolTarget) {
};
}
Aggregations