use of org.hibernate.tool.api.export.ArtifactCollector 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.api.export.ArtifactCollector 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.api.export.ArtifactCollector in project jbosstools-hibernate by jbosstools.
the class FacadeFactoryTest method testCreateArtifactCollector.
@Test
public void testCreateArtifactCollector() {
ArtifactCollector artifactCollector = new DefaultArtifactCollector();
IArtifactCollector facade = facadeFactory.createArtifactCollector(artifactCollector);
assertSame(artifactCollector, ((IFacade) facade).getTarget());
}
use of org.hibernate.tool.api.export.ArtifactCollector in project jbosstools-hibernate by jbosstools.
the class ExporterFacadeTest method testSetArtifactCollector.
@Test
public void testSetArtifactCollector() {
ArtifactCollector artifactCollectorTarget = new DefaultArtifactCollector();
IArtifactCollector artifactCollectorFacade = new AbstractArtifactCollectorFacade(FACADE_FACTORY, artifactCollectorTarget) {
};
exporterFacade.setArtifactCollector(artifactCollectorFacade);
assertSame(exporterTarget.getProperties().get(ExporterConstants.ARTIFACT_COLLECTOR), artifactCollectorTarget);
}
use of org.hibernate.tool.api.export.ArtifactCollector in project jbosstools-hibernate by jbosstools.
the class ServiceImplTest method testNewArtifactCollector.
@Test
public void testNewArtifactCollector() {
IArtifactCollector artifactCollector = service.newArtifactCollector();
assertNotNull(artifactCollector);
Object target = ((IFacade) artifactCollector).getTarget();
assertNotNull(target);
assertTrue(target instanceof ArtifactCollector);
}
Aggregations