<commit_before>package uk.ac.ebi.atlas.acceptance.rest.tests;

import com.google.common.collect.Lists;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.response.ResponseBody;
import org.junit.Test;
import uk.ac.ebi.atlas.acceptance.rest.EndPoint;
import uk.ac.ebi.atlas.search.SemanticQuery;
import uk.ac.ebi.atlas.search.SemanticQueryTerm;

import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;

public class AutocompleteControllerEIT {

    private static final String END_POINT_URL = "/gxa/json/suggestions";

    private EndPoint subject = new EndPoint(END_POINT_URL,"query=ASP&species=homo sapiens");

    @Test
    public void verifyHeader() {
        Response response = subject.getResponse();

        // http status code OK
        assertThat(response.getStatusCode(), is(200));

        // unicode encoded plain text
        assertThat(response.getContentType(), is("application/json;charset=UTF-8"));

    }

    @Test
    public void shouldReturnNonEmptyJSonObject(){
        //given
        ResponseBody responseBody = subject.getResponse().body();
        String jsonString = responseBody.asString();
        //when
        SemanticQuery query = SemanticQuery.fromJson(jsonString);
        SemanticQueryTerm firstTerm = query.iterator().next();
        //then
        assertThat(firstTerm.value(), is("ASPA"));
        assertThat(firstTerm.category(), is("symbol"));
        assertEquals(query.size(), 15);

    }

    @Test
    public void shouldReturnNonEmptyJSonObjectForBlankSpecies(){
        //given
        EndPoint emptySpeciesRequest = new EndPoint(END_POINT_URL,"query=ASP");
        ResponseBody responseBody = emptySpeciesRequest.getResponse().body();
        String jsonString = responseBody.asString();
        //when
        SemanticQuery query = SemanticQuery.fromJson(jsonString);
        List<SemanticQueryTerm> suggestionList = Lists.newArrayList(query);
        //then
        assertThat(suggestionList, hasSize(15));
        for (SemanticQueryTerm queryTerm : suggestionList) {
            assertThat(queryTerm.value().toLowerCase(), containsString("asp"));
        }
    }

}
<commit_msg>Make tests more robust<commit_after>package uk.ac.ebi.atlas.acceptance.rest.tests;

import com.google.common.collect.Lists;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.response.ResponseBody;
import org.junit.Test;
import uk.ac.ebi.atlas.acceptance.rest.EndPoint;
import uk.ac.ebi.atlas.search.SemanticQuery;
import uk.ac.ebi.atlas.search.SemanticQueryTerm;

import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;

public class AutocompleteControllerEIT {

    private static final String END_POINT_URL = "/gxa/json/suggestions";
    private static final String QUERY_TEXT = "ASP";

    private EndPoint subject = new EndPoint(END_POINT_URL,"query=" + QUERY_TEXT + "&species=homo_sapiens");

    @Test
    public void verifyHeader() {
        Response response = subject.getResponse();

        // http status code OK
        assertThat(response.getStatusCode(), is(200));

        // unicode encoded plain text
        assertThat(response.getContentType(), is("application/json;charset=UTF-8"));

    }

    @Test
    public void shouldReturnNonEmptyJSonObject(){
        //given
        ResponseBody responseBody = subject.getResponse().body();
        String jsonString = responseBody.asString();
        //when
        SemanticQuery query = SemanticQuery.fromJson(jsonString);
        SemanticQueryTerm firstTerm = query.iterator().next();
        //then
        assertThat(firstTerm.value(), startsWith(QUERY_TEXT));
        assertThat(firstTerm.category(), is("symbol"));
        assertThat(query.size(), greaterThan(5));

    }

    @Test
    public void shouldReturnNonEmptyJSonObjectForBlankSpecies() {
        //given
        EndPoint emptySpeciesRequest = new EndPoint(END_POINT_URL,"query=" + QUERY_TEXT);
        ResponseBody responseBody = emptySpeciesRequest.getResponse().body();
        String jsonString = responseBody.asString();
        //when
        SemanticQuery query = SemanticQuery.fromJson(jsonString);
        List<SemanticQueryTerm> suggestionList = Lists.newArrayList(query);
        //then
        assertThat(suggestionList, hasSize(greaterThan(0)));
        for (SemanticQueryTerm queryTerm : suggestionList) {
            assertThat(queryTerm.value().toLowerCase(), containsString(QUERY_TEXT.toLowerCase()));
        }
    }

}

{'fraction_non_alphanumeric': 0.109979633401222, 'fraction_numerical': 0.0028513238289205704, 'mean_word_length': 3.6242937853107344, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4744530', 'n_tokens_mistral': 1420, 'n_tokens_neox': 1386, 'n_words': 260}