use of org.hibernate.eclipse.console.views.QueryParametersPage 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);
}
Aggregations