<commit_before>/*
 *  ProActive Parallel Suite(TM): The Java(TM) library for
 *     Parallel, Distributed, Multi-Core Computing for
 *     Enterprise Grids & Clouds
 *
 *  Copyright (C) 1997-2016 INRIA/University of
 *                  Nice-Sophia Antipolis/ActiveEon
 *  Contact: <EMAIL> or <EMAIL>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Affero General Public License
 *  as published by the Free Software Foundation; version 3 of
 *  the License.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 *  USA
 *
 *  If needed, contact us to obtain a release under GPL Version 2 or 3
 *  or a different license than the AGPL.
 *
 *  Initial developer(s):               The ProActive Team
 *                          http://proactive.inria.fr/team_members.htm
 */
package org.ow2.proactive.workflow_catalog.rest.query;

import java.util.Arrays;
import java.util.Collection;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

/**
 * Unit tests associated to {@link WorkflowCatalogQueryCompiler}.
 * <p>
 * Statically define some queries (written in WCQL) that should
 * be syntactically valid or invalid.
 *
 * @author ActiveEon Team
 * @see WorkflowCatalogQueryCompiler
 */
@RunWith(Parameterized.class)
public class WorkflowCatalogQueryCompilerTest {

    private final WorkflowCatalogQueryCompiler compiler;

    private final Assertion assertion;

    @Parameterized.Parameters(name = "testQuery{index}")
    public static Collection<Assertion> queriesUnderTest() {
        return Arrays.asList(new Assertion[] {

                // Queries that are syntactically correct

                validTestInput("name=\"\""),
                validTestInput("name=\"value\""),
                validTestInput("name=\"I love you\""),
                validTestInput("name=\"Escape \\\" character\""),
                validTestInput("name=\"Escape \\% character\""),
                validTestInput("name=\"Escape \\\\ character\""),
                validTestInput("name != \"value\""),
                validTestInput(" \t name  \r \n = \"\"  "),
                validTestInput("name=\"%suffix\""),
                validTestInput("name=\"prefix%\""),
                validTestInput("name=\"%contains%\""),

                validTestInput("project_name=\"\""),
                validTestInput("project_name=\"value\""),
                validTestInput("project_name=\"I love you\""),
                validTestInput("project_name=\"Escape \\\" character\""),
                validTestInput("project_name=\"Escape \\% character\""),
                validTestInput("project_name=\"Escape \\\\ character\""),
                validTestInput("project_name != \"value\""),
                validTestInput(" \t project_name  \r \n = \"\"  "),
                validTestInput("project_name=\"%suffix\""),
                validTestInput("project_name=\"prefix%\""),
                validTestInput("project_name=\"%contains%\""),

                validTestInput("generic_information(\"\", \"\")"),
                validTestInput("generic_information(\"name\", \"\")"),
                validTestInput("generic_information(\"\", \"value\")"),
                validTestInput("generic_information(\"name\", \"value\")"),
                validTestInput("generic_information(\"name\", \"%\")"),
                validTestInput("generic_information(\"%\", \"value\")"),
                validTestInput("generic_information(\"prefix%\", \"value\")"),
                validTestInput("generic_information(\"%suffix\", \"value\")"),
                validTestInput("generic_information(\"%contains%\", \"value\")"),
                validTestInput("generic_information(\"name\", \"prefix%\")"),
                validTestInput("generic_information(\"name\", \"%suffix\")"),
                validTestInput("generic_information(\"name\", \"%contains%\")"),
                validTestInput("generic_information(\"My Long Name\", \"value\")"),
                validTestInput("generic_information(\"name\", \"My Long Value\")"),
                validTestInput("generic_information(\"My Long Name\", \"My Long Value\")"),

                validTestInput("variable(\"\", \"\")"),
                validTestInput("variable(\"name\", \"\")"),
                validTestInput("variable(\"\", \"value\")"),
                validTestInput("variable(\"name\", \"value\")"),
                validTestInput("variable(\"name\", \"%\")"),
                validTestInput("variable(\"%\", \"value\")"),
                validTestInput("variable(\"prefix%\", \"value\")"),
                validTestInput("variable(\"%suffix\", \"value\")"),
                validTestInput("variable(\"%contains%\", \"value\")"),
                validTestInput("variable(\"name\", \"prefix%\")"),
                validTestInput("variable(\"name\", \"%suffix\")"),
                validTestInput("variable(\"name\", \"%contains%\")"),
                validTestInput("variable(\"My Long Name\", \"value\")"),
                validTestInput("variable(\"name\", \"My Long Value\")"),
                validTestInput("variable(\"My Long Name\", \"My Long Value\")"),

                validTestInput(
                        "generic_information(\"name1\", \"value1\") " +
                                "AND generic_information(\"name2\", \"value2\")"),
                validTestInput(
                        "generic_information(\"name1\", \"value1\") " +
                                "AND generic_information(\"name2\", \"value2\") " +
                                "AND generic_information(\"name3\", \"value3\")"),<commit_msg>Update WorkflowRevisionControllerQueryIntegrationTest to use the new widlcard character<commit_after>/*
 *  ProActive Parallel Suite(TM): The Java(TM) library for
 *     Parallel, Distributed, Multi-Core Computing for
 *     Enterprise Grids & Clouds
 *
 *  Copyright (C) 1997-2016 INRIA/University of
 *                  Nice-Sophia Antipolis/ActiveEon
 *  Contact: <EMAIL> or <EMAIL>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Affero General Public License
 *  as published by the Free Software Foundation; version 3 of
 *  the License.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 *  USA
 *
 *  If needed, contact us to obtain a release under GPL Version 2 or 3
 *  or a different license than the AGPL.
 *
 *  Initial developer(s):               The ProActive Team
 *                          http://proactive.inria.fr/team_members.htm
 */
package org.ow2.proactive.workflow_catalog.rest.query;

import java.util.Arrays;
import java.util.Collection;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

/**
 * Unit tests associated to {@link WorkflowCatalogQueryCompiler}.
 * <p>
 * Statically define some queries (written in WCQL) that should
 * be syntactically valid or invalid.
 *
 * @author ActiveEon Team
 * @see WorkflowCatalogQueryCompiler
 */
@RunWith(Parameterized.class)
public class WorkflowCatalogQueryCompilerTest {

    private final WorkflowCatalogQueryCompiler compiler;

    private final Assertion assertion;

    @Parameterized.Parameters(name = "testQuery{index}")
    public static Collection<Assertion> queriesUnderTest() {
        return Arrays.asList(new Assertion[] {

                // Queries that are syntactically correct

                validTestInput("name=\"\""),
                validTestInput("name=\"value\""),
                validTestInput("name=\"I love you\""),
                validTestInput("name=\"Escape \\\" character\""),
                validTestInput("name=\"Escape \\* character\""),
                validTestInput("name=\"Escape \\\\ character\""),
                validTestInput("name != \"value\""),
                validTestInput(" \t name  \r \n = \"\"  "),
                validTestInput("name=\"*suffix\""),
                validTestInput("name=\"prefix*\""),
                validTestInput("name=\"*contains*\""),

                validTestInput("project_name=\"\""),
                validTestInput("project_name=\"value\""),
                validTestInput("project_name=\"I love you\""),
                validTestInput("project_name=\"Escape \\\" character\""),
                validTestInput("project_name=\"Escape \\* character\""),
                validTestInput("project_name=\"Escape \\\\ character\""),
                validTestInput("project_name != \"value\""),
                validTestInput(" \t project_name  \r \n = \"\"  "),
                validTestInput("project_name=\"*suffix\""),
                validTestInput("project_name=\"prefix*\""),
                validTestInput("project_name=\"*contains*\""),

                validTestInput("generic_information(\"\", \"\")"),
                validTestInput("generic_information(\"name\", \"\")"),
                validTestInput("generic_information(\"\", \"value\")"),
                validTestInput("generic_information(\"name\", \"value\")"),
                validTestInput("generic_information(\"name\", \"*\")"),
                validTestInput("generic_information(\"*\", \"value\")"),
                validTestInput("generic_information(\"prefix*\", \"value\")"),
                validTestInput("generic_information(\"*suffix\", \"value\")"),
                validTestInput("generic_information(\"*contains*\", \"value\")"),
                validTestInput("generic_information(\"name\", \"prefix*\")"),
                validTestInput("generic_information(\"name\", \"*suffix\")"),
                validTestInput("generic_information(\"name\", \"*contains*\")"),
                validTestInput("generic_information(\"My Long Name\", \"value\")"),
                validTestInput("generic_information(\"name\", \"My Long Value\")"),
                validTestInput("generic_information(\"My Long Name\", \"My Long Value\")"),

                validTestInput("variable(\"\", \"\")"),
                validTestInput("variable(\"name\", \"\")"),
                validTestInput("variable(\"\", \"value\")"),
                validTestInput("variable(\"name\", \"value\")"),
                validTestInput("variable(\"name\", \"*\")"),
                validTestInput("variable(\"*\", \"value\")"),
                validTestInput("variable(\"prefix*\", \"value\")"),
                validTestInput("variable(\"*suffix\", \"value\")"),
                validTestInput("variable(\"*contains*\", \"value\")"),
                validTestInput("variable(\"name\", \"prefix*\")"),
                validTestInput("variable(\"name\", \"*suffix\")"),
                validTestInput("variable(\"name\", \"*contains*\")"),
                validTestInput("variable(\"My Long Name\", \"value\")"),
                validTestInput("variable(\"name\", \"My Long Value\")"),
                validTestInput("variable(\"My Long Name\", \"My Long Value\")"),

                validTestInput(
                        "generic_information(\"name1\", \"value1\") " +
                                "AND generic_information(\"name2\", \"value2\")"),
                validTestInput(
                        "generic_information(\"name1\", \"value1\") " +
                                "AND generic_information(\"name2\", \"value2\") " +
                                "AND generic_information(\"name3\", \"value3\")"),
{'fraction_non_alphanumeric': 0.16148967311758008, 'fraction_numerical': 0.005854610505773296, 'mean_word_length': 2.290262172284644, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '5715951', 'n_tokens_mistral': 3326, 'n_tokens_neox': 3088, 'n_words': 716}