Search in sources :

Example 1 with IHibernateMappingExporter

use of org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter in project jbosstools-hibernate by jbosstools.

the class WripperException method testHbmExportExceptionTest.

public void testHbmExportExceptionTest() throws Exception {
    try {
        Object[] persClassesInit = getPersistenceClasses(false);
        final ConsoleConfiguration consCFG = getConsoleConfig();
        IConfiguration config = consCFG.getConfiguration();
        // delete old hbm files
        assertNotNull(testPackage);
        int nDeleted = 0;
        if (testPackage.getNonJavaResources().length > 0) {
            Object[] ress = testPackage.getNonJavaResources();
            for (int i = 0; i < ress.length; i++) {
                if (ress[i] instanceof IFile) {
                    IFile res = (IFile) ress[i];
                    if (res.getName().endsWith(".hbm.xml")) {
                        // $NON-NLS-1$
                        res.delete(true, false, null);
                        nDeleted++;
                    }
                }
            }
        }
        IHibernateMappingExporter hce = service.newHibernateMappingExporter(config, getSrcFolder());
        try {
            hce.start();
            IArtifactCollector collector = service.newArtifactCollector();
            collector.formatFiles();
            try {
                // build generated configuration
                testPackage.getResource().refreshLocal(IResource.DEPTH_INFINITE, null);
                testPackage.getJavaProject().getProject().build(IncrementalProjectBuilder.FULL_BUILD, new NullProgressMonitor());
                ConsoleConfigUtils.customizeCfgXmlForPack(testPackage);
                assertNotNull(consCFG);
                consCFG.reset();
                consCFG.build();
                assertTrue(consCFG.hasConfiguration());
                consCFG.getConfiguration().buildMappings();
                config = consCFG.getConfiguration();
            } catch (CoreException e) {
                String out = NLS.bind(ConsoleTestMessages.UpdateConfigurationTest_error_customising_file_for_package, new Object[] { ConsoleConfigUtils.CFG_FILE_NAME, testPackage.getPath(), e.getMessage() });
                fail(out);
            }
        } catch (Exception e) {
            throw (Exception) e.getCause();
        }
        // 
        Object[] persClassesReInit = getPersistenceClasses(false);
        // 
        int nCreated = 0;
        if (testPackage.getNonJavaResources().length > 0) {
            Object[] ress = testPackage.getNonJavaResources();
            for (int i = 0; i < ress.length; i++) {
                if (ress[i] instanceof IFile) {
                    IFile res = (IFile) ress[i];
                    if (res.getName().endsWith(".hbm.xml")) {
                        // $NON-NLS-1$
                        nCreated++;
                    }
                }
            }
        }
        // 
        assertTrue(persClassesInit.length == persClassesReInit.length);
        assertTrue(nCreated > 0);
        assertTrue(nDeleted >= 0 && persClassesInit.length > 0);
        assertTrue(nCreated <= persClassesInit.length);
    } catch (Exception e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        String newMessage = "\nPackage " + testPackage.getElementName() + ":";
        throw new WripperException(newMessage, e);
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IFile(org.eclipse.core.resources.IFile) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) IArtifactCollector(org.jboss.tools.hibernate.runtime.spi.IArtifactCollector) CoreException(org.eclipse.core.runtime.CoreException) IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration)

Example 2 with IHibernateMappingExporter

use of org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateHibernateMappingExporter.

@Test
public void testCreateHibernateMappingExporter() {
    HibernateMappingExporter hibernateMappingExporter = new HibernateMappingExporter();
    IHibernateMappingExporter facade = facadeFactory.createHibernateMappingExporter(hibernateMappingExporter);
    Assert.assertSame(hibernateMappingExporter, ((IFacade) facade).getTarget());
}
Also used : IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) HibernateMappingExporter(org.hibernate.tool.hbm2x.HibernateMappingExporter) IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) Test(org.junit.Test)

Example 3 with IHibernateMappingExporter

use of org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter in project jbosstools-hibernate by jbosstools.

the class FacadeFactoryTest method testCreateHibernateMappingExporter.

@Test
public void testCreateHibernateMappingExporter() {
    HibernateMappingExporter hibernateMappingExporter = new HibernateMappingExporter();
    IHibernateMappingExporter facade = facadeFactory.createHibernateMappingExporter(hibernateMappingExporter);
    Assert.assertSame(hibernateMappingExporter, ((IFacade) facade).getTarget());
}
Also used : IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) HibernateMappingExporter(org.hibernate.tool.hbm2x.HibernateMappingExporter) IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) Test(org.junit.Test)

Example 4 with IHibernateMappingExporter

use of org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewHibernateMappingExporter.

@Test
public void testNewHibernateMappingExporter() {
    IConfiguration configuration = service.newDefaultConfiguration();
    File file = new File("");
    IHibernateMappingExporter hibernateMappingExporter = service.newHibernateMappingExporter(configuration, file);
    Configuration cfg = (Configuration) ((IFacade) configuration).getTarget();
    HibernateMappingExporterExtension hmee = (HibernateMappingExporterExtension) ((IFacade) hibernateMappingExporter).getTarget();
    Assert.assertSame(file, hmee.getOutputDirectory());
    Assert.assertSame(cfg, hmee.getConfiguration());
}
Also used : Configuration(org.hibernate.cfg.Configuration) JDBCMetaDataConfiguration(org.hibernate.cfg.JDBCMetaDataConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) File(java.io.File) Test(org.junit.Test)

Example 5 with IHibernateMappingExporter

use of org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter in project jbosstools-hibernate by jbosstools.

the class ServiceImplTest method testNewHibernateMappingExporter.

@Test
public void testNewHibernateMappingExporter() {
    IConfiguration configuration = service.newDefaultConfiguration();
    File file = new File("");
    IHibernateMappingExporter hibernateMappingExporter = service.newHibernateMappingExporter(configuration, file);
    HibernateMappingExporterExtension hmee = (HibernateMappingExporterExtension) ((IFacade) hibernateMappingExporter).getTarget();
    Assert.assertSame(file, hmee.getOutputDirectory());
    Assert.assertSame(((ConfigurationFacadeImpl) configuration).getMetadata(), hmee.getMetadata());
}
Also used : IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) File(java.io.File) Test(org.junit.Test)

Aggregations

IHibernateMappingExporter (org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter)15 Test (org.junit.Test)12 HibernateMappingExporter (org.hibernate.tool.hbm2x.HibernateMappingExporter)8 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)7 File (java.io.File)6 IFile (org.eclipse.core.resources.IFile)3 CoreException (org.eclipse.core.runtime.CoreException)3 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 JavaModelException (org.eclipse.jdt.core.JavaModelException)3 Configuration (org.hibernate.cfg.Configuration)3 JDBCMetaDataConfiguration (org.hibernate.cfg.JDBCMetaDataConfiguration)3 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)3 IArtifactCollector (org.jboss.tools.hibernate.runtime.spi.IArtifactCollector)3 FileNotFoundException (java.io.FileNotFoundException)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 PartInitException (org.eclipse.ui.PartInitException)2 IService (org.jboss.tools.hibernate.runtime.spi.IService)2