Search in sources :

Example 1 with QueryParametersPage

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);
}
Also used : QueryParametersPage(org.hibernate.eclipse.console.views.QueryParametersPage) IViewPart(org.eclipse.ui.IViewPart) IContributionItem(org.eclipse.jface.action.IContributionItem) IEditorPart(org.eclipse.ui.IEditorPart) QueryInputModel(org.hibernate.console.QueryInputModel) IPage(org.eclipse.ui.part.IPage) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) QueryParametersView(org.hibernate.eclipse.console.views.QueryParametersView) IToolBarManager(org.eclipse.jface.action.IToolBarManager) HQLEditor(org.hibernate.eclipse.hqleditor.HQLEditor) Test(org.junit.Test)

Aggregations

ActionContributionItem (org.eclipse.jface.action.ActionContributionItem)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 IToolBarManager (org.eclipse.jface.action.IToolBarManager)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IViewPart (org.eclipse.ui.IViewPart)1 IPage (org.eclipse.ui.part.IPage)1 QueryInputModel (org.hibernate.console.QueryInputModel)1 QueryParametersPage (org.hibernate.eclipse.console.views.QueryParametersPage)1 QueryParametersView (org.hibernate.eclipse.console.views.QueryParametersView)1 HQLEditor (org.hibernate.eclipse.hqleditor.HQLEditor)1 Test (org.junit.Test)1