<commit_before>/* This file is part of VoltDB.
 * Copyright (C) 2008-2015 VoltDB Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

package vmcTest.pages

import geb.error.RequiredPageContentNotPresent
import geb.navigator.Navigator
import geb.waiting.WaitTimeoutException
import org.openqa.selenium.support.ui.Select

/**
 * This class represents the 'SQL Query' tab of the VoltDB Management Center
 * page, which is the VoltDB web UI (replacing the old Web Studio).
 */
class SqlQueryPage extends VoltDBManagementCenterPage {
    static content = {
        // Tables, Views & Stored Procedures elements
        tabArea     { $('#tabMain') }
        tabControls { tabArea.find('.tabs') }
        tablesTab   { tabControls.find("a[href='#tab1']") }
        viewsTab    { tabControls.find("a[href='#tab2']") }
        storedProcsTab  { tabControls.find("a[href='#tab3']") }
        listsArea   { tabArea.find('#tabScroller') }
        tablesNames { listsArea.find('#accordionTable').find('h3') }
        viewsNames  { listsArea.find('#accordionViews').find('h3') }
        storedProcs { listsArea.find('#accordionProcedures') }
        systemStoredProcsHeader  { storedProcs.find('.systemHeader').first() }
        defaultStoredProcsHeader { storedProcs.find('.systemHeader').first().next('h3') }
        systemStoredProcs   { storedProcs.find('#systemProcedure').find('h3') }
        defaultStoredProcs  { storedProcs.find('#defaultProcedure').find('h3') }
        userStoredProcsHeader {defaultStoredProcsHeader.next('h3') }
        userStoredProcs { storedProcs.find('#userProcedure').find('h3') }
        allStoredProcs  { storedProcs.find('h3') }

        queryStatus			{ $("th", text:"STATUS") }

        // Query elements
        queryInput  { $('#theQueryText') }
        runButton   { $('#runBTn') }
        clearButton { $('#clearQuery') }
        qrFormatDropDown    { $('#exportType') }
        qrfddOptions    { qrFormatDropDown.find('option') }
        qrfddSelected   { qrFormatDropDown.find('option', selected: "selected") }
        queryResHtml    { $('#resultHtml') }
        queryTables     (required: false) { queryResHtml.find('table') }
        queryErrHtml    (required: false) { queryResHtml.find('span') }
        queryDurHtml    { $('#queryResults') }


        //popup query ok and cancel
        cancelpopupquery        { $("#btnQueryDatabasePausedErrorCancel", text:"Cancel")}
        okpopupquery            { $("#btnQueryDatabasePausedErrorOk", text:"Ok")}
        switchadminport         { $("#queryDatabasePausedInnerErrorPopup > div.overlay-contentError.errorQueryDbPause > p:nth-child(3) > span")}
        queryexecutionerror     { $("#queryDatabasePausedInnerErrorPopup > div.overlay-title", text:"Query Execution Error")}
        queryerrortxt           { $("#queryDatabasePausedInnerErrorPopup > div.overlay-contentError.errorQueryDbPause > p:nth-child(1)")}

        htmltableresult 	    { $("#table_r0_html_0")}
        createerrorresult	    { $("#resultHtml > span")}
        htmlresultallcolumns	{ $("#table_r0_html_0 > thead")}

        htmlresultselect	    { $("#table_r0_html_0 > thead > tr")}
        refreshquery		    { $("#tabMain > button", text:"Refresh")}

        //options
        htmlOptions				{ $("option", text:"HTML") }
        csvOptions				{ $("option", text:"CSV") }
        monospaceOptions		{ $("option", text:"Monospace") }

        // for view
        checkview		{ $("#tabMain > ul > li.active > a")}

        //result
        resultHtml		{ $("#resultHtml") }
        resultCsv		{ $("#resultCsv") }
        resultMonospace	{ $("#resultMonospace") }
        
        errorObjectNameAlreadyExist     { $("span", class:"errorValue") }
    }
    static at = {
        sqlQueryTab.displayed
        sqlQueryTab.attr('class') == 'active'
        tablesTab.displayed
        viewsTab.displayed
        storedProcsTab.displayed
        listsArea.displayed
        queryInput.displayed
        queryResHtml.displayed
    }

    /**
     * Displays the list of Tables (by clicking the "Tables" tab).
     */

    def showTables() {
        clickToDisplay(tablesTab, tablesNames)
    }

    /**
     * Displays the list of Views (by clicking the "Views" tab).
     */

    def showViews() {
        clickToDisplay(viewsTab, viewsNames)
    }

    /**
     * Displays the list of Stored Procedures (by clicking the "Stored Procedures" tab).
     */

    def showStoredProcedures() {
        clickToDisplay(storedProcsTab, allStoredProcs)
    }

    /**
     * Returns the list of Tables (as displayed on the "Tables" tab).<p>
     * Note: as a side effect, the "Tables" tab is opened.
     * @return the list of Table names.
     */
    def List<String> getTableNames() {
        def names = []
        showTables()
        tablesNames.each {
            scrollIntoView(it);
            names.add(it.text())
        }
        return names
    }

    /**
     * Returns the list of Views (as displayed on the "Views" tab).<p>
     * Note: as a side effect, the "Views" tab is opened.
     * @return the list of View names.
     */
    def List<String> getViewNames() {
        def names = []
        showViews()
        viewsNames.each {
            scrollIntoView(it);
            names.add(it.text())
        }
        return names
    }

    /**
     * Returns the list of System Stored Procedures (as displayed on the
     * "Stored Procedures" tab, under the "System Stored Procedures" heading).<p>
     * Note: as a side effect, the "Stored Procedures" tab is opened (if
     * needed), and the "System Stored Procedures" list is opened (if needed),
     * and then closed.
     * @return the list of System Stored Procedure names.
     */
    def List<String> getSystemStoredProcedures() {
        def storedProcs = []
        showStoredProcedures()
        clickToDisplay(systemStoredProcsHeader, systemStoredProcs)
        systemStoredProcs.each {
            scrollIntoView(it);
            storedProcs.add(it.text())
        }
        clickToNotDisplay(systemStoredProcsHeader, systemStoredProcs)
        return storedProcs
    }

    /**
     * Returns the list of Default Stored Procedures (as displayed on the
     * "Stored Procedures" tab, under the "Default Stored Procedures" heading).<p>
     * Note: as a side effect, the "Stored Procedures" tab is opened (if
     * needed), and the "Default Stored Procedures" list is opened (if needed),
     * and then closed.
     * @return the list of Default Stored Procedure names.
     */
    def List<String> getDefaultStoredProcedures() { // defaultStoredProcsHeader
        def storedProcs = []
        showStoredProcedures()
        clickToDisplay(defaultStoredProcsHeader, defaultStoredProcs)
        defaultStoredProcs.each {
            scrollIntoView(it);
            storedProcs.add(it.text())
        }
        clickToNotDisplay(defaultStoredProcsHeader, defaultStoredProcs)
        return storedProcs
    }

    /**
     * Returns the list of User-defined Stored Procedures (as displayed on
     * the "Stored Procedures" tab, after the "System Stored Procedures" and
     * "Default Stored Procedures").<p>
     * Note: as a side effect, the "Stored Procedures" tab is opened (if
     * needed).
     * @return the list of User-defined Stored Procedure names.
     */
    def List<String> getUserStoredProcedures() {
        def storedProcs = []
        showStoredProcedures()
        clickToDisplay(userStoredProcsHeader, userStoredProcs)
        try {
            userStoredProcs.each {
                scrollIntoView(it)
                storedProcs.add(it.text())
            }
        } catch (RequiredPageContentNotPresent e) {
            // do nothing: empty list will be returned
        }<commit_msg>VMC-218 VMC SqlQueriesTests GEB tests failing<commit_after>/* This file is part of VoltDB.
 * Copyright (C) 2008-2015 VoltDB Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */

package vmcTest.pages

import geb.error.RequiredPageContentNotPresent
import geb.navigator.Navigator
import geb.waiting.WaitTimeoutException
import org.openqa.selenium.support.ui.Select

/**
 * This class represents the 'SQL Query' tab of the VoltDB Management Center
 * page, which is the VoltDB web UI (replacing the old Web Studio).
 */
class SqlQueryPage extends VoltDBManagementCenterPage {
    static content = {
        // Tables, Views & Stored Procedures elements
        tabArea     { $('#tabMain') }
        tabControls { tabArea.find('.tabs') }
        tablesTab   { tabControls.find("a[href='#tab1']") }
        viewsTab    { tabControls.find("a[href='#tab2']") }
        storedProcsTab  { tabControls.find("a[href='#tab3']") }
        listsArea   { tabArea.find('#tabScroller') }
        tablesNames { listsArea.find('#accordionTable').find('h3') }
        viewsNames  { listsArea.find('#accordionViews').find('h3') }
        storedProcs { listsArea.find('#accordionProcedures') }
        systemStoredProcsHeader  { storedProcs.find('.systemHeader').first() }
        defaultStoredProcsHeader { storedProcs.find('.systemHeader').first().next('h3') }
        systemStoredProcs   { storedProcs.find('#systemProcedure').find('h3') }
        defaultStoredProcs  { storedProcs.find('#defaultProcedure').find('h3') }
        userStoredProcs { defaultStoredProcsHeader.nextAll('h3') }
        allStoredProcs  { storedProcs.find('h3') }

        queryStatus			{ $("th", text:"STATUS") }

        // Query elements
        queryInput  { $('#theQueryText') }
        runButton   { $('#runBTn') }
        clearButton { $('#clearQuery') }
        qrFormatDropDown    { $('#exportType') }
        qrfddOptions    { qrFormatDropDown.find('option') }
        qrfddSelected   { qrFormatDropDown.find('option', selected: "selected") }
        queryResHtml    { $('#resultHtml') }
        queryTables     (required: false) { queryResHtml.find('table') }
        queryErrHtml    (required: false) { queryResHtml.find('span') }
        queryDurHtml    { $('#queryResults') }


        //popup query ok and cancel
        cancelpopupquery        { $("#btnQueryDatabasePausedErrorCancel", text:"Cancel")}
        okpopupquery            { $("#btnQueryDatabasePausedErrorOk", text:"Ok")}
        switchadminport         { $("#queryDatabasePausedInnerErrorPopup > div.overlay-contentError.errorQueryDbPause > p:nth-child(3) > span")}
        queryexecutionerror     { $("#queryDatabasePausedInnerErrorPopup > div.overlay-title", text:"Query Execution Error")}
        queryerrortxt           { $("#queryDatabasePausedInnerErrorPopup > div.overlay-contentError.errorQueryDbPause > p:nth-child(1)")}

        htmltableresult 	    { $("#table_r0_html_0")}
        createerrorresult	    { $("#resultHtml > span")}
        htmlresultallcolumns	{ $("#table_r0_html_0 > thead")}

        htmlresultselect	    { $("#table_r0_html_0 > thead > tr")}
        refreshquery		    { $("#tabMain > button", text:"Refresh")}

        //options
        htmlOptions				{ $("option", text:"HTML") }
        csvOptions				{ $("option", text:"CSV") }
        monospaceOptions		{ $("option", text:"Monospace") }

        // for view
        checkview		{ $("#tabMain > ul > li.active > a")}

        //result
        resultHtml		{ $("#resultHtml") }
        resultCsv		{ $("#resultCsv") }
        resultMonospace	{ $("#resultMonospace") }
        
        errorObjectNameAlreadyExist     { $("span", class:"errorValue") }
    }
    static at = {
        sqlQueryTab.displayed
        sqlQueryTab.attr('class') == 'active'
        tablesTab.displayed
        viewsTab.displayed
        storedProcsTab.displayed
        listsArea.displayed
        queryInput.displayed
        queryResHtml.displayed
    }

    /**
     * Displays the list of Tables (by clicking the "Tables" tab).
     */

    def showTables() {
        clickToDisplay(tablesTab, tablesNames)
    }

    /**
     * Displays the list of Views (by clicking the "Views" tab).
     */

    def showViews() {
        clickToDisplay(viewsTab, viewsNames)
    }

    /**
     * Displays the list of Stored Procedures (by clicking the "Stored Procedures" tab).
     */

    def showStoredProcedures() {
        clickToDisplay(storedProcsTab, allStoredProcs)
    }

    /**
     * Returns the list of Tables (as displayed on the "Tables" tab).<p>
     * Note: as a side effect, the "Tables" tab is opened.
     * @return the list of Table names.
     */
    def List<String> getTableNames() {
        def names = []
        showTables()
        tablesNames.each {
            scrollIntoView(it);
            names.add(it.text())
        }
        return names
    }

    /**
     * Returns the list of Views (as displayed on the "Views" tab).<p>
     * Note: as a side effect, the "Views" tab is opened.
     * @return the list of View names.
     */
    def List<String> getViewNames() {
        def names = []
        showViews()
        viewsNames.each {
            scrollIntoView(it);
            names.add(it.text())
        }
        return names
    }

    /**
     * Returns the list of System Stored Procedures (as displayed on the
     * "Stored Procedures" tab, under the "System Stored Procedures" heading).<p>
     * Note: as a side effect, the "Stored Procedures" tab is opened (if
     * needed), and the "System Stored Procedures" list is opened (if needed),
     * and then closed.
     * @return the list of System Stored Procedure names.
     */
    def List<String> getSystemStoredProcedures() {
        def storedProcs = []
        showStoredProcedures()
        clickToDisplay(systemStoredProcsHeader, systemStoredProcs)
        systemStoredProcs.each {
            scrollIntoView(it);
            storedProcs.add(it.text())
        }
        clickToNotDisplay(systemStoredProcsHeader, systemStoredProcs)
        return storedProcs
    }

    /**
     * Returns the list of Default Stored Procedures (as displayed on the
     * "Stored Procedures" tab, under the "Default Stored Procedures" heading).<p>
     * Note: as a side effect, the "Stored Procedures" tab is opened (if
     * needed), and the "Default Stored Procedures" list is opened (if needed),
     * and then closed.
     * @return the list of Default Stored Procedure names.
     */
    def List<String> getDefaultStoredProcedures() { // defaultStoredProcsHeader
        def storedProcs = []
        showStoredProcedures()
        clickToDisplay(defaultStoredProcsHeader, defaultStoredProcs)
        defaultStoredProcs.each {
            scrollIntoView(it);
            storedProcs.add(it.text())
        }
        clickToNotDisplay(defaultStoredProcsHeader, defaultStoredProcs)
        return storedProcs
    }

    /**
     * Returns the list of User-defined Stored Procedures (as displayed on
     * the "Stored Procedures" tab, after the "System Stored Procedures" and
     * "Default Stored Procedures").<p>
     * Note: as a side effect, the "Stored Procedures" tab is opened (if
     * needed).
     * @return the list of User-defined Stored Procedure names.
     */
    def List<String> getUserStoredProcedures() {
        def storedProcs = []
        showStoredProcedures()
        //clickToDisplay(userStoredProcsHeader, userStoredProcs)
        try {
            userStoredProcs.each {
                scrollIntoView(it)
                storedProcs.add(it.text())
            }
        } catch (RequiredPageContentNotPresent e) {
            // do nothing: empty list will be returned
        }
{'fraction_non_alphanumeric': 0.1079161415969756, 'fraction_numerical': 0.0032076984763432237, 'mean_word_length': 2.654039347007116, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3007191', 'n_tokens_mistral': 5085, 'n_tokens_neox': 4861, 'n_words': 1371}