use of org.hibernate.tool.internal.export.java.POJOClass 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.java.POJOClass 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);
assertSame(pojoClass, ((IFacade) facade).getTarget());
}
Aggregations