Search in sources :

Example 81 with ConsoleConfiguration

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

the class CriteriaEditorTest method testCriteriaCodeCompletion.

@Test
public void testCriteriaCodeCompletion() throws CoreException, NoSuchFieldException, IllegalAccessException, IOException {
    cleanUpProject();
    project = new SimpleTestProjectWithMapping(PROJ_NAME);
    IPackageFragmentRoot sourceFolder = project.createSourceFolder();
    IPackageFragment pf = sourceFolder.createPackageFragment(SimpleTestProject.PACKAGE_NAME, false, null);
    ConsoleConfigUtils.customizeCfgXmlForPack(pf);
    List<IPath> libs = new ArrayList<IPath>();
    project.generateClassPath(libs, sourceFolder);
    project.fullBuild();
    // setup console configuration
    IPath cfgFilePath = new Path(project.getIProject().getName() + File.separator + TestProject.SRC_FOLDER + File.separator + ConsoleConfigUtils.CFG_FILE_NAME);
    ConsoleConfigUtils.createConsoleConfig(PROJ_NAME, cfgFilePath, CONSOLE_NAME);
    ConsoleConfiguration cc = KnownConfigurations.getInstance().find(CONSOLE_NAME);
    // $NON-NLS-1$
    Assert.assertNotNull("Console Configuration not found", cc);
    cc.build();
    String query = // $NON-NLS-1$
    "Object o = new Object();\n" + // $NON-NLS-1$
    "System.out.print(o.toString());";
    IEditorPart editorPart = HibernateConsolePlugin.getDefault().openCriteriaEditor(CONSOLE_NAME, query);
    // $NON-NLS-1$
    Assert.assertTrue("Opened editor is not CriteriaEditor", editorPart instanceof CriteriaEditor);
    CriteriaEditor editor = (CriteriaEditor) editorPart;
    Assert.assertEquals(editor.getEditorText(), query);
    QueryInputModel model = editor.getQueryInputModel();
    Assert.assertTrue(model.getParameterCount() == 0);
    editor.setConsoleConfigurationName(CONSOLE_NAME);
    JavaCompletionProcessor processor = new JavaCompletionProcessor(editor);
    // $NON-NLS-1$
    int position = query.indexOf("toString()");
    ICompletionProposal[] proposals = processor.computeCompletionProposals(null, position);
    Assert.assertTrue(// $NON-NLS-1$
    "Class java.lang.Object has at least 9 methods. But " + proposals.length + " code completion proposals where provided.", // $NON-NLS-1$
    proposals.length >= 9);
    cc.reset();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) QueryInputModel(org.hibernate.console.QueryInputModel) SimpleTestProjectWithMapping(org.jboss.tools.hibernate.orm.test.utils.project.SimpleTestProjectWithMapping) CriteriaEditor(org.hibernate.eclipse.criteriaeditor.CriteriaEditor) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) JavaCompletionProcessor(org.hibernate.eclipse.criteriaeditor.JavaCompletionProcessor) Test(org.junit.Test)

Example 82 with ConsoleConfiguration

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

the class CriteriaEditorTest 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)

Example 83 with ConsoleConfiguration

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

the class ExporterAttributesTest 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();
    this.project = new LaunchConfigTestProject();
    TestConsoleConfigurationPreferences cfgprefs = new TestConsoleConfigurationPreferences(cfgXmlFile);
    consoleCfg = new ConsoleConfiguration(cfgprefs);
    service = consoleCfg.getHibernateExtension().getHibernateService();
    KnownConfigurations.getInstance().addConfiguration(consoleCfg, true);
}
Also used : ConsoleConfiguration(org.hibernate.console.ConsoleConfiguration) LaunchConfigTestProject(org.jboss.tools.hibernate.orm.test.utils.project.LaunchConfigTestProject) FileWriter(java.io.FileWriter) IFile(org.eclipse.core.resources.IFile) File(java.io.File) TestConsoleConfigurationPreferences(org.jboss.tools.hibernate.orm.test.utils.TestConsoleConfigurationPreferences) Before(org.junit.Before)

Example 84 with ConsoleConfiguration

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

the class CoreMappingTestHelper 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 85 with ConsoleConfiguration

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

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