use of org.hibernate.console.QueryInputModel in project jbosstools-hibernate by jbosstools.
the class QueryParametersTest method testQueryParameter.
@Test
public void testQueryParameter() {
QueryInputModel model = new QueryInputModel(service);
ConsoleQueryParameter[] cqps = model.getQueryParameters();
Assert.assertNotNull(cqps);
QueryInputModel qpmodel = model;
Assert.assertNotNull(qpmodel);
class TestObserver implements Observer {
int cnt = 0;
public void update(Observable o, Object arg) {
cnt++;
}
}
;
TestObserver testObserver = new TestObserver();
qpmodel.addObserver(testObserver);
ConsoleQueryParameter consoleQueryParameter = new ConsoleQueryParameter(service);
qpmodel.addParameter(consoleQueryParameter);
Assert.assertEquals(1, testObserver.cnt);
qpmodel.removeParameter(consoleQueryParameter);
Assert.assertEquals(2, testObserver.cnt);
}
use of org.hibernate.console.QueryInputModel in project jbosstools-hibernate by jbosstools.
the class HQLEditorTest method testHQLEditorOpen.
@Test
public void testHQLEditorOpen() {
IEditorPart editorPart = HibernateConsolePlugin.getDefault().openScratchHQLEditor(consoleConfiguration.getName(), // $NON-NLS-1$
"");
// $NON-NLS-1$
Assert.assertNotNull("Editor was not opened", editorPart);
// $NON-NLS-1$
Assert.assertTrue("Opened editor is not HQLEditor", editorPart instanceof HQLEditor);
HQLEditor editor = (HQLEditor) editorPart;
QueryInputModel model = editor.getQueryInputModel();
// $NON-NLS-1$
Assert.assertNotNull("Model is NULL", model);
}
use of org.hibernate.console.QueryInputModel in project jbosstools-hibernate by jbosstools.
the class HQLEditorTest method testHQLEditorCodeCompletionWithTabs.
@Test
public void testHQLEditorCodeCompletionWithTabs() throws CoreException, NoSuchFieldException, IllegalAccessException {
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();
// $NON-NLS-1$
final String codeCompletionPlaceMarker = " from ";
final String query = // $NON-NLS-1$
"select\t \tt1." + codeCompletionPlaceMarker + project.getFullyQualifiedTestClassName() + // $NON-NLS-1$
" t1";
IEditorPart editorPart = HibernateConsolePlugin.getDefault().openScratchHQLEditor(CONSOLE_NAME, query);
// $NON-NLS-1$
Assert.assertTrue("Opened editor is not HQLEditor", editorPart instanceof HQLEditor);
HQLEditor editor = (HQLEditor) editorPart;
Assert.assertEquals(editor.getEditorText(), query);
QueryInputModel model = editor.getQueryInputModel();
Assert.assertTrue(model.getParameterCount() == 0);
editor.setConsoleConfigurationName(CONSOLE_NAME);
IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
HQLCompletionProcessor processor = new HQLCompletionProcessor(editor);
int position = query.indexOf(codeCompletionPlaceMarker);
ICompletionProposal[] proposals = processor.computeCompletionProposals(doc, position);
Assert.assertTrue(proposals.length > 0);
cc.reset();
}
use of org.hibernate.console.QueryInputModel in project jbosstools-hibernate by jbosstools.
the class HQLEditorTest method testSingleLineCommentsCutOff.
@Test
public void testSingleLineCommentsCutOff() throws PartInitException {
String query = // $NON-NLS-1$
"from pack.Article a\n" + // $NON-NLS-1$
"where a.articleid in (:a, :b) --or a.articleid = :c";
IEditorPart editorPart = HibernateConsolePlugin.getDefault().openScratchHQLEditor(consoleConfiguration.getName(), query);
// $NON-NLS-1$
Assert.assertTrue("Opened editor is not HQLEditor", editorPart instanceof HQLEditor);
HQLEditor editor = (HQLEditor) editorPart;
Assert.assertEquals(editor.getEditorText(), query);
// $NON-NLS-1$ //$NON-NLS-2$
Assert.assertFalse("Comments were not cut off", editor.getQueryString().contains("--"));
QueryInputModel model = editor.getQueryInputModel();
Assert.assertTrue(model.getParameterCount() == 0);
IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(// $NON-NLS-1$
"org.hibernate.eclipse.console.views.QueryParametersView");
// $NON-NLS-1$
Assert.assertNotNull("View was not opened", view);
// $NON-NLS-1$
Assert.assertTrue("Opened view is not QueryParametersView", view instanceof QueryParametersView);
QueryParametersView paramView = (QueryParametersView) view;
IPage ipage = paramView.getCurrentPage();
// $NON-NLS-1$
Assert.assertNotNull("Current Page is NULL", ipage);
// $NON-NLS-1$
Assert.assertTrue("Page is not Query Parameters Page", ipage instanceof QueryParametersPage);
QueryParametersPage page = (QueryParametersPage) ipage;
IToolBarManager manager = page.getSite().getActionBars().getToolBarManager();
IContributionItem[] items = manager.getItems();
ActionContributionItem addParamItem = null;
for (int i = 0; i < items.length; i++) {
ActionContributionItem item = (ActionContributionItem) items[i];
if (item.getAction().getClass().getName().endsWith("NewRowAction")) {
// $NON-NLS-1$
addParamItem = item;
break;
}
}
Assert.assertNotNull(HibernateConsoleMessages.QueryParametersPage_add_query_parameter_tooltip + " item not found", // $NON-NLS-1$
addParamItem);
// add query parameters automatically
addParamItem.getAction().run();
// a and b
Assert.assertTrue(model.getParameterCount() == 2);
}
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;
}
Aggregations