use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateSpecialRootClass.
@Test
public void testCreateSpecialRootClass() {
Property target = new Property();
PersistentClass pc = new RootClass();
target.setPersistentClass(pc);
IProperty property = facadeFactory.createProperty(target);
IPersistentClass specialRootClass = facadeFactory.createSpecialRootClass(property);
assertNotNull(specialRootClass);
Object object = ((IFacade) specialRootClass).getTarget();
assertTrue(specialRootClass instanceof SpecialRootClassFacadeImpl);
assertTrue(object instanceof RootClass);
assertSame(property, specialRootClass.getProperty());
}
use of org.hibernate.mapping.RootClass 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");
assertFalse(fooHbmXml.exists());
hibernateMappingExporterFacade.exportPOJO(additionalContext, pojoClass);
assertTrue(fooHbmXml.exists());
fooHbmXml.delete();
outputDir.delete();
}
use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.
the class HibernateMappingExporterFacadeTest method testStart.
@Test
public void testStart() throws Exception {
RootClass persistentClass = new RootClass();
Table table = new Table("FOO");
Column keyColumn = new Column("BAR");
SimpleValue key = new SimpleValue(configurationTarget.createMappings());
key.setTypeName("String");
key.addColumn(keyColumn);
key.setTable(table);
persistentClass.setClassName("Foo");
persistentClass.setEntityName("Foo");
persistentClass.setJpaEntityName("Foo");
persistentClass.setTable(table);
persistentClass.setIdentifier(key);
configurationFacade.addClass(FACADE_FACTORY.createPersistentClass(persistentClass));
hibernateMappingExporter.setOutputDirectory(outputDir);
final File fooHbmXml = new File(outputDir, "Foo.hbm.xml");
// First without a 'delegate' exporter
assertFalse(fooHbmXml.exists());
hibernateMappingExporterFacade.start();
assertTrue(fooHbmXml.exists());
assertTrue(fooHbmXml.delete());
// Now set a 'delegate' and invoke 'start' again
final File dummyDir = new File(outputDir, "dummy");
dummyDir.mkdir();
assertTrue(dummyDir.exists());
IExportPOJODelegate delegate = new IExportPOJODelegate() {
@Override
public void exportPOJO(Map<Object, Object> map, IPOJOClass pojoClass) {
assertTrue(dummyDir.delete());
Map<Object, Object> m = new HashMap<>();
for (Object key : map.keySet()) {
m.put((String) key, map.get(key));
}
hibernateMappingExporter.superExportPOJO(m, (POJOClass) ((IFacade) pojoClass).getTarget());
}
};
Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
delegateField.setAccessible(true);
delegateField.set(hibernateMappingExporter, delegate);
hibernateMappingExporterFacade.start();
assertFalse(dummyDir.exists());
assertTrue(fooHbmXml.exists());
assertTrue(fooHbmXml.delete());
assertTrue(outputDir.exists());
}
use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.
the class PersistentClassFacadeTest method testGetIdentifierProperty.
@Test
public void testGetIdentifierProperty() throws Exception {
Field field = AbstractPersistentClassFacade.class.getDeclaredField("identifierProperty");
field.setAccessible(true);
assertNull(field.get(persistentClassFacade));
Property propertyTarget = new Property();
assertNull(persistentClassFacade.getIdentifierProperty());
((RootClass) persistentClassTarget).setIdentifierProperty(propertyTarget);
IProperty propertyFacade = persistentClassFacade.getIdentifierProperty();
assertNotNull(propertyFacade);
assertSame(propertyTarget, ((IFacade) propertyFacade).getTarget());
assertSame(propertyFacade, field.get(persistentClassFacade));
}
use of org.hibernate.mapping.RootClass in project jbosstools-hibernate by jbosstools.
the class PersistentClassFacadeTest method testGetVersion.
@Test
public void testGetVersion() throws Exception {
assertNull(persistentClassFacade.getVersion());
Property versionTarget = new Property();
Field field = AbstractPersistentClassFacade.class.getDeclaredField("version");
field.setAccessible(true);
assertNull(field.get(persistentClassFacade));
((RootClass) persistentClassTarget).setVersion(versionTarget);
IProperty versionFacade = persistentClassFacade.getVersion();
assertNotNull(versionFacade);
assertSame(versionFacade, field.get(persistentClassFacade));
assertSame(versionTarget, ((IFacade) versionFacade).getTarget());
}
Aggregations