Search in sources :

Example 6 with IHibernateMappingExporter

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

the class CoreMappingTestHelper method testHbmExportExceptionTest.

public void testHbmExportExceptionTest(String packageName) throws Exception {
    String projectName = testProject.getIProject().getName();
    String pathName = "/" + projectName + "/src/" + packageName.replace('.', '/');
    IPackageFragment testPackage = testProject.getIJavaProject().findPackageFragment(new Path(pathName));
    try {
        Object[] persClassesInit = getPersistenceClasses(true);
        final ConsoleConfiguration consCFG = getConsoleConfig();
        IConfiguration config = consCFG.getConfiguration();
        // delete old hbm files
        Assert.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++;
                    }
                }
            }
        }
        String[] versions = ServiceLookup.getVersions();
        IService service = ServiceLookup.findService(versions[0]);
        File srcFolder = testProject.getIProject().getFolder(TestProject.SRC_FOLDER).getLocation().toFile();
        IHibernateMappingExporter hce = service.newHibernateMappingExporter(config, srcFolder);
        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);
                Assert.assertNotNull(consCFG);
                consCFG.reset();
                consCFG.build();
                Assert.assertTrue(consCFG.hasConfiguration());
                consCFG.getConfiguration().buildMappings();
                config = consCFG.getConfiguration();
            } catch (CoreException e) {
                String out = NLS.bind(TestConsoleMessages.UpdateConfigurationTest_error_customising_file_for_package, new Object[] { ConsoleConfigUtils.CFG_FILE_NAME, testPackage.getPath(), e.getMessage() });
                Assert.fail(out);
            }
        } catch (Exception e) {
            throw 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++;
                    }
                }
            }
        }
        // 
        Assert.assertTrue(persClassesInit.length == persClassesReInit.length);
        Assert.assertTrue(nCreated > 0);
        Assert.assertTrue(nDeleted >= 0 && persClassesInit.length > 0);
        Assert.assertTrue(nCreated <= persClassesInit.length);
    } catch (Exception e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        String newMessage = "\nPackage " + testPackage.getElementName() + ":";
        throw new WrapperException(newMessage, e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IFile(org.eclipse.core.resources.IFile) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) FileNotFoundException(java.io.FileNotFoundException) 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) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 7 with IHibernateMappingExporter

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

the class MappingTestHelper method testHbmExportExceptionTest.

public void testHbmExportExceptionTest() throws Exception {
    String projectName = testProject.getIProject().getName();
    String pathName = "/" + projectName + "/src/" + packageName.replace('.', '/');
    IPackageFragment testPackage = testProject.getIJavaProject().findPackageFragment(new Path(pathName));
    try {
        Object[] persClassesInit = getPersistenceClasses(true);
        final ConsoleConfiguration consCFG = getConsoleConfig();
        IConfiguration config = consCFG.getConfiguration();
        // delete old hbm files
        Assert.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++;
                    }
                }
            }
        }
        String[] versions = ServiceLookup.getVersions();
        IService service = ServiceLookup.findService(versions[0]);
        File srcFolder = testProject.getIProject().getFolder(TestProject.SRC_FOLDER).getLocation().toFile();
        IHibernateMappingExporter hce = service.newHibernateMappingExporter(config, srcFolder);
        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);
                Assert.assertNotNull(consCFG);
                consCFG.reset();
                consCFG.build();
                Assert.assertTrue(consCFG.hasConfiguration());
                consCFG.getConfiguration().buildMappings();
                config = consCFG.getConfiguration();
            } catch (CoreException e) {
                String out = NLS.bind(TestConsoleMessages.UpdateConfigurationTest_error_customising_file_for_package, new Object[] { ConsoleConfigUtils.CFG_FILE_NAME, testPackage.getPath(), e.getMessage() });
                Assert.fail(out);
            }
        } catch (Exception e) {
            // throw (Exception)e.getCause();
            throw e;
        }
        // 
        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++;
                    }
                }
            }
        }
        // 
        Assert.assertTrue(persClassesInit.length == persClassesReInit.length);
        Assert.assertTrue(nCreated > 0);
        Assert.assertTrue(nDeleted >= 0 && persClassesInit.length > 0);
        Assert.assertTrue(nCreated <= persClassesInit.length);
    } catch (Exception e) {
        // $NON-NLS-1$ //$NON-NLS-2$
        String newMessage = "\nPackage " + testPackage.getElementName() + ":";
        throw new WrapperException(newMessage, e);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IFile(org.eclipse.core.resources.IFile) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) FileNotFoundException(java.io.FileNotFoundException) 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) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IService(org.jboss.tools.hibernate.runtime.spi.IService)

Example 8 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 9 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 : HibernateMappingExporter(org.hibernate.tool.hbm2x.HibernateMappingExporter) IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) IHibernateMappingExporter(org.jboss.tools.hibernate.runtime.spi.IHibernateMappingExporter) Test(org.junit.Test)

Example 10 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)

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