Search in sources :

Example 1 with DefaultArtifactCollector

use of org.hibernate.tool.internal.export.common.DefaultArtifactCollector 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());
}
Also used : DefaultArtifactCollector(org.hibernate.tool.internal.export.common.DefaultArtifactCollector) HashMap(java.util.HashMap) ArtifactCollector(org.hibernate.tool.api.export.ArtifactCollector) DefaultArtifactCollector(org.hibernate.tool.internal.export.common.DefaultArtifactCollector) Cfg2HbmTool(org.hibernate.tool.internal.export.hbm.Cfg2HbmTool) File(java.io.File) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultArtifactCollector

use of org.hibernate.tool.internal.export.common.DefaultArtifactCollector 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());
}
Also used : DefaultArtifactCollector(org.hibernate.tool.internal.export.common.DefaultArtifactCollector) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) HashMap(java.util.HashMap) EntityPOJOClass(org.hibernate.tool.internal.export.java.EntityPOJOClass) POJOClass(org.hibernate.tool.internal.export.java.POJOClass) IPOJOClass(org.jboss.tools.hibernate.runtime.spi.IPOJOClass) Date(java.util.Date) Field(java.lang.reflect.Field) ArtifactCollector(org.hibernate.tool.api.export.ArtifactCollector) DefaultArtifactCollector(org.hibernate.tool.internal.export.common.DefaultArtifactCollector) IExportPOJODelegate(org.jboss.tools.hibernate.runtime.spi.IExportPOJODelegate) Cfg2HbmTool(org.hibernate.tool.internal.export.hbm.Cfg2HbmTool) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultArtifactCollector

use of org.hibernate.tool.internal.export.common.DefaultArtifactCollector 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());
}
Also used : DefaultArtifactCollector(org.hibernate.tool.internal.export.common.DefaultArtifactCollector) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) ArtifactCollector(org.hibernate.tool.api.export.ArtifactCollector) DefaultArtifactCollector(org.hibernate.tool.internal.export.common.DefaultArtifactCollector) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultArtifactCollector

use of org.hibernate.tool.internal.export.common.DefaultArtifactCollector 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);
}
Also used : DefaultArtifactCollector(org.hibernate.tool.internal.export.common.DefaultArtifactCollector) AbstractArtifactCollectorFacade(org.jboss.tools.hibernate.runtime.common.AbstractArtifactCollectorFacade) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) ArtifactCollector(org.hibernate.tool.api.export.ArtifactCollector) DefaultArtifactCollector(org.hibernate.tool.internal.export.common.DefaultArtifactCollector) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) Test(org.junit.jupiter.api.Test)

Aggregations

ArtifactCollector (org.hibernate.tool.api.export.ArtifactCollector)4 DefaultArtifactCollector (org.hibernate.tool.internal.export.common.DefaultArtifactCollector)4 Test (org.junit.jupiter.api.Test)4 File (java.io.File)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Cfg2HbmTool (org.hibernate.tool.internal.export.hbm.Cfg2HbmTool)2 IArtifactCollector (org.jboss.tools.hibernate.runtime.spi.IArtifactCollector)2 Field (java.lang.reflect.Field)1 Map (java.util.Map)1 EntityPOJOClass (org.hibernate.tool.internal.export.java.EntityPOJOClass)1 POJOClass (org.hibernate.tool.internal.export.java.POJOClass)1 AbstractArtifactCollectorFacade (org.jboss.tools.hibernate.runtime.common.AbstractArtifactCollectorFacade)1 IExportPOJODelegate (org.jboss.tools.hibernate.runtime.spi.IExportPOJODelegate)1 IPOJOClass (org.jboss.tools.hibernate.runtime.spi.IPOJOClass)1