Search in sources :

Example 6 with QueryInputModel

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

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

the class CriteriaEditorTest method testCriteriaEditorOpen.

@Test
public void testCriteriaEditorOpen() {
    IEditorPart editorPart = HibernateConsolePlugin.getDefault().openCriteriaEditor(consoleConfiguration.getName(), // $NON-NLS-1$
    "");
    // $NON-NLS-1$
    Assert.assertNotNull("Criteria Editor was not opened", editorPart);
    // $NON-NLS-1$
    Assert.assertTrue("Opened editor is not CriteriaEditor", editorPart instanceof CriteriaEditor);
    CriteriaEditor editor = (CriteriaEditor) editorPart;
    QueryInputModel model = editor.getQueryInputModel();
    // $NON-NLS-1$
    Assert.assertNotNull("Model is NULL", model);
}
Also used : CriteriaEditor(org.hibernate.eclipse.criteriaeditor.CriteriaEditor) IEditorPart(org.eclipse.ui.IEditorPart) QueryInputModel(org.hibernate.console.QueryInputModel) Test(org.junit.Test)

Example 8 with QueryInputModel

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

the class QueryParametersTest method testCreateUnique.

@Test
public void testCreateUnique() {
    QueryInputModel model = new QueryInputModel(service);
    // $NON-NLS-1$
    ConsoleQueryParameter parameter = model.createUniqueParameter("param");
    model.addParameter(parameter);
    // $NON-NLS-1$
    Assert.assertFalse(model.createUniqueParameter("param").getName().equals(parameter.getName()));
}
Also used : ConsoleQueryParameter(org.hibernate.console.ConsoleQueryParameter) QueryInputModel(org.hibernate.console.QueryInputModel) Test(org.junit.Test)

Example 9 with QueryInputModel

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

the class AbstractQueryEditor method getQueryInputModel.

public QueryInputModel getQueryInputModel() {
    if (queryInputModel == null) {
        IService service = getConsoleConfiguration().getHibernateExtension().getHibernateService();
        queryInputModel = new QueryInputModel(service);
    }
    return queryInputModel;
}
Also used : IService(org.jboss.tools.hibernate.runtime.spi.IService) QueryInputModel(org.hibernate.console.QueryInputModel)

Aggregations

QueryInputModel (org.hibernate.console.QueryInputModel)9 Test (org.junit.Test)8 IEditorPart (org.eclipse.ui.IEditorPart)5 ConsoleQueryParameter (org.hibernate.console.ConsoleQueryParameter)3 HQLEditor (org.hibernate.eclipse.hqleditor.HQLEditor)3 ArrayList (java.util.ArrayList)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)2 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2 IViewPart (org.eclipse.ui.IViewPart)2 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)2 CriteriaEditor (org.hibernate.eclipse.criteriaeditor.CriteriaEditor)2 SimpleTestProjectWithMapping (org.jboss.tools.hibernate.orm.test.utils.project.SimpleTestProjectWithMapping)2 Observable (java.util.Observable)1 Observer (java.util.Observer)1 ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 IToolBarManager (org.eclipse.jface.action.IToolBarManager)1