<commit_before>import org.junit.Test
import static groovyx.net.http.ContentType.JSON
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue

class DrillDownIT extends BaseApiTest {

    @Test
    void canDrillDownJson() {
        doDrillDownJson(['nothing_to_see': 'here'], 21, 'numberOfPeople');
        doDrillDownJson(['numberOfPeople': '5'], 5, 'fuel');
        doDrillDownJson(['numberOfPeople': '5', 'fuel': 'Gas'], 1, 'uid');
    }

    def doDrillDownJson(query, choicesSize, choicesName) {
        versions.each { version -> doDrillDownJson(query, choicesSize, choicesName, version) };
    }

    def doDrillDownJson(query, choicesSize, choicesName, version) {
        if (version >= 3.3) {
            client.contentType = JSON;
            def response = client.get(
                    path: "/${version}/categories/Cooking/drill",
                    query: query);
            assertEquals 200, response.status;
            assertEquals 'application/json', response.contentType;
            assertTrue response.data instanceof net.sf.json.JSON;
            assertEquals 'OK', response.data.status;
            assertEquals choicesSize, response.data.drill.choices.values.size();
            assertEquals choicesName, response.data.drill.choices.name;
        }
    }
}<commit_msg>PL-10597 - Update DrillDownIT to include documentation and XML tests.<commit_after>import org.junit.Test
import static groovyx.net.http.ContentType.JSON
import static groovyx.net.http.ContentType.XML
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue

/**
 * Tests for the Data Category drill down API.
 */
class DrillDownIT extends BaseApiTest {

    /**
     * Tests drill down GETs against a Data Category using JSON responses.
     *
     * The parameters this resource supports are available in the representations as part of the
     * choices node in the representation.
     *
     * The purpose and behaviour of this resource is similar to the AMEE API V1 / V2 drill down resource. For
     * some background see http://my.amee.com/developers/wiki/DrillDown. The main difference is that the V3
     * implementation is quicker (backed by Lucene search) and the representations are tidier.
     */
    @Test
    void canDrillDownJson() {
        doDrillDownJson(['nothing_to_see': 'here'], 21, 'numberOfPeople');
        doDrillDownJson(['numberOfPeople': '5'], 5, 'fuel');
        doDrillDownJson(['numberOfPeople': '5', 'fuel': 'Gas'], 1, 'uid');
    }

    def doDrillDownJson(query, choicesSize, choicesName) {
        versions.each { version -> doDrillDownJson(query, choicesSize, choicesName, version) };
    }

    def doDrillDownJson(query, choicesSize, choicesName, version) {
        if (version >= 3.3) {
            def response = client.get(
                    path: "/${version}/categories/Cooking/drill",
                    query: query,
                    contentType: JSON);
            assertEquals 200, response.status;
            assertEquals 'application/json', response.contentType;
            assertTrue response.data instanceof net.sf.json.JSON;
            assertEquals 'OK', response.data.status;
            assertEquals choicesSize, response.data.drill.choices.values.size();
            assertEquals choicesName, response.data.drill.choices.name;
        }
    }

    /**
     * Tests drill down GETs against a Data Category using XML responses.
     *
     * See notes for canDrillDownJson above.
     */
    @Test
    void canDrillDownXml() {
        doDrillDownXml(['nothing_to_see': 'here'], 21, 'numberOfPeople');
        doDrillDownXml(['numberOfPeople': '5'], 5, 'fuel');
        doDrillDownXml(['numberOfPeople': '5', 'fuel': 'Gas'], 1, 'uid');
    }

    def doDrillDownXml(query, choicesSize, choicesName) {
        versions.each { version -> doDrillDownXml(query, choicesSize, choicesName, version) };
    }

    def doDrillDownXml(query, choicesSize, choicesName, version) {
        if (version >= 3.3) {
            def response = client.get(
                    path: "/${version}/categories/Cooking/drill",
                    query: query,
                    contentType: XML);
            assertEquals 200, response.status;
            assertEquals 'application/xml', response.contentType;
            assertEquals 'OK', response.data.Status.text();
            assertEquals choicesSize, response.data.Drill.Choices.Values.Value.size();
            assertEquals choicesName, response.data.Drill.Choices.Name.text();
        }
    }
}
{'fraction_non_alphanumeric': 0.11069624423457061, 'fraction_numerical': 0.009005051614320228, 'mean_word_length': 2.6666666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '1363202', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1223, 'n_words': 322}