use of org.jboss.tools.hibernate.runtime.spi.IPOJOClass in project jbosstools-hibernate by jbosstools.
the class HibernateMappingExporterFacadeTest method testSetExportPOJODelegate.
@Test
public void testSetExportPOJODelegate() throws Exception {
IExportPOJODelegate delegate = new IExportPOJODelegate() {
@Override
public void exportPOJO(Map<Object, Object> map, IPOJOClass pojoClass) {
}
};
Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
delegateField.setAccessible(true);
Assert.assertNull(delegateField.get(hibernateMappingExporter));
hibernateMappingExporterFacade.setExportPOJODelegate(delegate);
Assert.assertSame(delegate, delegateField.get(hibernateMappingExporter));
}
use of org.jboss.tools.hibernate.runtime.spi.IPOJOClass in project jbosstools-hibernate by jbosstools.
the class HibernateMappingExporterFacadeTest method testStart.
@Test
public void testStart() throws Exception {
Configuration configuration = new Configuration();
RootClass persistentClass = new RootClass();
Table table = new Table("FOO");
persistentClass.setClassName("Foo");
persistentClass.setEntityName("Foo");
persistentClass.setTable(table);
Mappings mappings = configuration.createMappings();
mappings.addClass(persistentClass);
hibernateMappingExporter.setConfiguration(configuration);
hibernateMappingExporter.setOutputDirectory(outputDir);
final File fooHbmXml = new File(outputDir, "Foo.hbm.xml");
// First without a 'delegate' exporter
Assert.assertFalse(fooHbmXml.exists());
hibernateMappingExporterFacade.start();
Assert.assertTrue(fooHbmXml.exists());
Assert.assertTrue(fooHbmXml.delete());
// Now set a 'delegate' and invoke 'start' again
final File dummyDir = new File(outputDir, "dummy");
dummyDir.mkdir();
Assert.assertTrue(dummyDir.exists());
IExportPOJODelegate delegate = new IExportPOJODelegate() {
@Override
public void exportPOJO(Map<Object, Object> map, IPOJOClass pojoClass) {
Assert.assertTrue(dummyDir.delete());
hibernateMappingExporter.superExportPOJO(map, (POJOClass) ((IFacade) pojoClass).getTarget());
}
};
Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
delegateField.setAccessible(true);
delegateField.set(hibernateMappingExporter, delegate);
hibernateMappingExporterFacade.start();
Assert.assertFalse(dummyDir.exists());
Assert.assertTrue(fooHbmXml.exists());
Assert.assertTrue(fooHbmXml.delete());
Assert.assertTrue(outputDir.exists());
}
use of org.jboss.tools.hibernate.runtime.spi.IPOJOClass in project jbosstools-hibernate by jbosstools.
the class HibernateMappingExporterFacadeTest method testSetExportPOJODelegate.
@Test
public void testSetExportPOJODelegate() throws Exception {
IExportPOJODelegate delegate = new IExportPOJODelegate() {
@Override
public void exportPOJO(Map<Object, Object> map, IPOJOClass pojoClass) {
}
};
Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
delegateField.setAccessible(true);
Assert.assertNull(delegateField.get(hibernateMappingExporter));
hibernateMappingExporterFacade.setExportPOJODelegate(delegate);
Assert.assertSame(delegate, delegateField.get(hibernateMappingExporter));
}
use of org.jboss.tools.hibernate.runtime.spi.IPOJOClass 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();
}
use of org.jboss.tools.hibernate.runtime.spi.IPOJOClass in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreatePOJOClass.
@Test
public void testCreatePOJOClass() {
POJOClass pojoClass = (POJOClass) Proxy.newProxyInstance(facadeFactory.getClassLoader(), new Class[] { POJOClass.class }, new TestInvocationHandler());
IPOJOClass facade = facadeFactory.createPOJOClass(pojoClass);
Assert.assertSame(pojoClass, ((IFacade) facade).getTarget());
}
Aggregations