use of org.hibernate.eclipse.criteriaeditor.JavaCompletionProcessor 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();
}
Aggregations