Search in sources :

Example 86 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class MappingTestHelper method testOpenMappingDiagram.

public void testOpenMappingDiagram() {
    final Object[] persClasses = getPersistenceClasses(true);
    final ConsoleConfiguration consCFG = getConsoleConfig();
    for (int i = 0; i < persClasses.length; i++) {
        Assert.assertTrue(persClasses[i] instanceof IPersistentClass);
        IPersistentClass persClass = (IPersistentClass) persClasses[i];
        IEditorPart editor = null;
        Throwable ex = null;
        try {
            editor = new OpenDiagramActionDelegate().openEditor(persClass, consCFG);
        } catch (PartInitException e) {
            ex = e;
        }
        if (ex == null) {
            ex = Utils.getExceptionIfItOccured(editor);
        }
        if (ex != null) {
            ex.printStackTrace();
            String out = NLS.bind(TestConsoleMessages.OpenMappingDiagramTest_mapping_diagram_for_not_opened, new Object[] { persClass.getClassName(), ex.getMessage() });
            Assert.fail(out);
        }
    }
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IEditorPart(org.eclipse.ui.IEditorPart) OpenDiagramActionDelegate(org.jboss.tools.hibernate.ui.view.OpenDiagramActionDelegate) PartInitException(org.eclipse.ui.PartInitException) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 87 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class MappingTestHelper method getPersistenceClasses.

private Object[] getPersistenceClasses(boolean resetCC) {
    final ConsoleConfiguration consCFG = getConsoleConfig();
    if (resetCC) {
        consCFG.reset();
        consCFG.build();
    }
    Assert.assertTrue(consCFG.hasConfiguration());
    if (resetCC) {
        consCFG.buildMappings();
    }
    Object[] configs = null;
    Object[] persClasses = null;
    try {
        configs = ccWorkbenchAdapter.getChildren(consCFG);
        Assert.assertNotNull(configs);
        Assert.assertEquals(3, configs.length);
        Assert.assertTrue(configs[0] instanceof IConfiguration);
        persClasses = configWorkbenchAdapter.getChildren(configs[0]);
    } catch (Exception ex) {
        String out = NLS.bind(TestConsoleMessages.OpenMappingDiagramTest_mapping_diagrams_for_package_cannot_be_opened, new Object[] { testName.getMethodName(), ex.getMessage() });
        Assert.fail(out);
    }
    return persClasses;
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IConfiguration(org.jboss.tools.hibernate.runtime.spi.IConfiguration) JavaModelException(org.eclipse.jdt.core.JavaModelException) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) FileNotFoundException(java.io.FileNotFoundException)

Example 88 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class MappingTestHelper method testOpenSourceFileTest.

public void testOpenSourceFileTest() {
    // fail("test fail");
    final Object[] persClasses = getPersistenceClasses(true);
    final ConsoleConfiguration consCFG = getConsoleConfig();
    for (int i = 0; i < persClasses.length; i++) {
        Assert.assertTrue(persClasses[i] instanceof IPersistentClass);
        IPersistentClass persClass = (IPersistentClass) persClasses[i];
        String fullyQualifiedName = persClass.getClassName();
        // test PersistentClasses
        openTest(persClass, consCFG, fullyQualifiedName);
        Object[] fields = pcWorkbenchAdapter.getChildren(persClass);
        for (int j = 0; j < fields.length; j++) {
            if (!(fields[j] instanceof IProperty && ((IProperty) fields[j]).classIsPropertyClass())) {
                continue;
            }
            fullyQualifiedName = persClass.getClassName();
            // test Properties
            openTest(fields[j], consCFG, fullyQualifiedName);
            if (fields[j] instanceof IProperty && ((IProperty) fields[j]).isComposite()) {
                fullyQualifiedName = ((IProperty) fields[j]).getValue().getComponentClassName();
                Object[] compProperties = propertyWorkbenchAdapter.getChildren(fields[j]);
                for (int k = 0; k < compProperties.length; k++) {
                    if (!(compProperties[k] instanceof IProperty && ((IProperty) compProperties[k]).classIsPropertyClass())) {
                        continue;
                    }
                    // test Composite properties
                    openTest(compProperties[k], consCFG, fullyQualifiedName);
                }
            }
        }
    }
// close all editors
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IProperty(org.jboss.tools.hibernate.runtime.spi.IProperty) IPersistentClass(org.jboss.tools.hibernate.runtime.spi.IPersistentClass)

Example 89 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration 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 90 with ConsoleConfiguration

use of org.hibernate.console.ConsoleConfiguration in project jbosstools-hibernate by jbosstools.

the class HQLEditorTest method setUp.

@Before
public void setUp() throws Exception {
    cfgXmlFile = new File(temporaryFolder.getRoot(), "hibernate.cfg.xml");
    FileWriter fw = new FileWriter(cfgXmlFile);
    fw.write(HIBERNATE_CFG_XML);
    fw.close();
    consolePrefs = new TestConsoleConfigurationPreferences(cfgXmlFile);
    consoleConfiguration = new ConsoleConfiguration(consolePrefs);
    KnownConfigurations.getInstance().addConfiguration(consoleConfiguration, false);
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) FileWriter(java.io.FileWriter) File(java.io.File) TestConsoleConfigurationPreferences(org.jboss.tools.hibernate.orm.test.utils.TestConsoleConfigurationPreferences) Before(org.junit.Before)

Aggregations

ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)107 IPersistentClass (org.jboss.tools.hibernate.runtime.spi.IPersistentClass)19 IConfiguration (org.jboss.tools.hibernate.runtime.spi.IConfiguration)17 CoreException (org.eclipse.core.runtime.CoreException)16 PartInitException (org.eclipse.ui.PartInitException)13 IProperty (org.jboss.tools.hibernate.runtime.spi.IProperty)12 KnownConfigurations (org.hibernate.console.KnownConfigurations)11 JavaModelException (org.eclipse.jdt.core.JavaModelException)10 TreePath (org.eclipse.jface.viewers.TreePath)10 Test (org.junit.Test)10 File (java.io.File)9 ArrayList (java.util.ArrayList)9 FileNotFoundException (java.io.FileNotFoundException)8 IPath (org.eclipse.core.runtime.IPath)8 TreeSelection (org.eclipse.jface.viewers.TreeSelection)8 IService (org.jboss.tools.hibernate.runtime.spi.IService)8 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)7 IEditorPart (org.eclipse.ui.IEditorPart)7 ConsoleConfigurationPreferences (org.hibernate.console.preferences.ConsoleConfigurationPreferences)7 GridLayout (org.eclipse.swt.layout.GridLayout)6