Search in sources :

Example 36 with ArtifactCollector

use of org.hibernate.tool.hbm2x.ArtifactCollector in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateArtifactCollector.

@Test
public void testCreateArtifactCollector() {
    ArtifactCollector artifactCollector = new ArtifactCollector();
    IArtifactCollector facade = facadeFactory.createArtifactCollector(artifactCollector);
    Assert.assertSame(artifactCollector, ((IFacade) facade).getTarget());
}
Also used : IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) Test(org.junit.Test)

Example 37 with ArtifactCollector

use of org.hibernate.tool.hbm2x.ArtifactCollector in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterExtensionTest method testExportPOJO.

@Test
public void testExportPOJO() throws Exception {
    // first without a delegate exporter
    ArtifactCollector artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    File[] hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.assertFalse(new File("foo" + File.separator + "Bar.hbm.xml").exists());
    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);
    hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 1);
    Assert.assertEquals("foo" + File.separator + "Bar.hbm.xml", hbmXmlFiles[0].getPath());
    Assert.assertTrue(new File("foo" + File.separator + "Bar.hbm.xml").exists());
    Assert.assertNull(methodName);
    Assert.assertNull(arguments);
    // then with a delegate exporter
    artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
    delegateField.setAccessible(true);
    delegateField.set(hibernateMappingExporterExtension, exportPojoDelegate);
    hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.assertEquals("exportPOJO", methodName);
    Assert.assertSame(additionalContext, arguments[0]);
    Assert.assertSame(pojoClass, ((IFacade) arguments[1]).getTarget());
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 38 with ArtifactCollector

use of org.hibernate.tool.hbm2x.ArtifactCollector in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterExtensionTest method testSuperExportPOJO.

@Test
public void testSuperExportPOJO() {
    ArtifactCollector artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    File[] hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.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.getDefault().toString());
    additionalContext.put("c2h", c2h);
    hibernateMappingExporterExtension.superExportPOJO(additionalContext, pojoClass);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 1);
    Assert.assertEquals("foo" + File.separator + "Bar.hbm.xml", hbmXmlFiles[0].getPath());
    Assert.assertTrue(new File("foo" + File.separator + "Bar.hbm.xml").exists());
}
Also used : HashMap(java.util.HashMap) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 39 with ArtifactCollector

use of org.hibernate.tool.hbm2x.ArtifactCollector in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateArtifactCollector.

@Test
public void testCreateArtifactCollector() {
    ArtifactCollector artifactCollector = new ArtifactCollector();
    IArtifactCollector facade = facadeFactory.createArtifactCollector(artifactCollector);
    Assert.assertSame(artifactCollector, ((IFacade) facade).getTarget());
}
Also used : IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) Test(org.junit.Test)

Example 40 with ArtifactCollector

use of org.hibernate.tool.hbm2x.ArtifactCollector in project jbosstools-hibernate by jbosstools.

the class HibernateMappingExporterExtensionTest method testExportPOJO.

@Test
public void testExportPOJO() throws Exception {
    // first without a delegate exporter
    ArtifactCollector artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    File[] hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.assertFalse(new File("foo" + File.separator + "Bar.hbm.xml").exists());
    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);
    hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 1);
    Assert.assertEquals("foo" + File.separator + "Bar.hbm.xml", hbmXmlFiles[0].getPath());
    Assert.assertTrue(new File("foo" + File.separator + "Bar.hbm.xml").exists());
    Assert.assertNull(methodName);
    Assert.assertNull(arguments);
    // then with a delegate exporter
    artifactCollector = new ArtifactCollector();
    hibernateMappingExporterExtension.setArtifactCollector(artifactCollector);
    hbmXmlFiles = artifactCollector.getFiles("hbm.xml");
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Field delegateField = HibernateMappingExporterExtension.class.getDeclaredField("delegateExporter");
    delegateField.setAccessible(true);
    delegateField.set(hibernateMappingExporterExtension, exportPojoDelegate);
    hibernateMappingExporterExtension.exportPOJO(additionalContext, pojoClass);
    Assert.assertTrue(hbmXmlFiles.length == 0);
    Assert.assertEquals("exportPOJO", methodName);
    Assert.assertSame(additionalContext, arguments[0]);
    Assert.assertSame(pojoClass, ((IFacade) arguments[1]).getTarget());
}
Also used : Field(java.lang.reflect.Field) HashMap(java.util.HashMap) ArtifactCollector(org.hibernate.tool.hbm2x.ArtifactCollector) Cfg2HbmTool(org.hibernate.tool.hbm2x.Cfg2HbmTool) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ArtifactCollector (org.hibernate.tool.hbm2x.ArtifactCollector)44 Test (org.junit.Test)38 IArtifactCollector (org.jboss.tools.hibernate.runtime.spi.IArtifactCollector)28 File (java.io.File)18 Date (java.util.Date)16 HashMap (java.util.HashMap)16 Cfg2HbmTool (org.hibernate.tool.hbm2x.Cfg2HbmTool)16 AbstractArtifactCollectorFacade (org.jboss.tools.hibernate.runtime.common.AbstractArtifactCollectorFacade)14 Field (java.lang.reflect.Field)8 Method (java.lang.reflect.Method)6 MethodHandler (javassist.util.proxy.MethodHandler)6 ProxyFactory (javassist.util.proxy.ProxyFactory)6 ProxyObject (javassist.util.proxy.ProxyObject)6 Before (org.junit.Before)6 IFacade (org.jboss.tools.hibernate.runtime.common.IFacade)4 FileWriter (java.io.FileWriter)2 AbstractExporter (org.hibernate.tool.hbm2x.AbstractExporter)2 Exporter (org.hibernate.tool.hbm2x.Exporter)2 GenericExporter (org.hibernate.tool.hbm2x.GenericExporter)2 Hbm2DDLExporter (org.hibernate.tool.hbm2x.Hbm2DDLExporter)2