<commit_before>package org.ga4gh.cts.api.rnaquantification;

import com.google.protobuf.InvalidProtocolBufferException;
import com.mashape.unirest.http.exceptions.UnirestException;
import ga4gh.RnaQuantificationServiceOuterClass.*;
import junitparams.JUnitParamsRunner;
import org.ga4gh.ctk.transport.URLMAPPING;
import org.ga4gh.ctk.transport.protocols.Client;
import org.ga4gh.ctk.transport.GAWrapperException;
import org.ga4gh.cts.api.Utils;
import ga4gh.RnaQuantificationOuterClass.ExpressionLevel;
import ga4gh.SequenceAnnotationServiceOuterClass.*;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Tests for <tt>GET /expressionlevels/{id}</tt>.
 */
@Category(RnaQuantificationTests.class)
@RunWith(JUnitParamsRunner.class)
public class ExpressionLevelsIT {

    private static Client client = new Client(URLMAPPING.getInstance());

    /**
     * Verify that ExpressionLevels that we obtain by way of {@link ga4gh.RnaQuantificationServiceOuterClass.SearchExpressionLevelsRequest} match the ones
     * we get via <tt>GET /expressionlevels/{id}</tt>.
     * @throws GAWrapperException if the server finds the request invalid in some way
     * @throws UnirestException if there's a problem speaking HTTP to the server
     * @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
     */
    @Test
    public void checkExpressionLevelGetResultsMatchSearchResults() throws InvalidProtocolBufferException, UnirestException, GAWrapperException {
        final String rnaQuantificationSetId = Utils.getRnaQuantificationSetId(client);
        final String rnaQuantificationId = Utils.getRnaQuantificationId(client, rnaQuantificationSetId);
        final String expressionLevelId = Utils.getExpressionLevelId(client, rnaQuantificationId);
        final ExpressionLevel expressionLevelFromGet = client.rnaquantifications.getExpressionLevel(expressionLevelId);
        assertThat(expressionLevelFromGet).isNotNull();
        assertThat(expressionLevelFromGet.getId()).isEqualTo(expressionLevelId);
    }


    /**
     * Fetch expression levels and count them.  The number must
     * equal what we're expecting by visual examination of the data.
     *
     * @throws GAWrapperException if the server finds the request invalid in some way
     * @throws UnirestException if there's a problem speaking HTTP to the server
     * @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
     */
    @Test
    public void checkExpectedNumberOfExpressionLevels() throws InvalidProtocolBufferException, UnirestException, GAWrapperException {
        final int expectedNumberOfExpressionLevels = 4;
        final String rnaQuantificationSetId = Utils.getRnaQuantificationSetId(client);
        final String rnaQuantificationId = Utils.getRnaQuantificationId(client, rnaQuantificationSetId);

        final SearchExpressionLevelsRequest req =
                SearchExpressionLevelsRequest.newBuilder()
                        .setRnaQuantificationId(rnaQuantificationId)
                        .build();
        final SearchExpressionLevelsResponse resp = client.rnaquantifications.searchExpressionLevel(req);

        final List<ExpressionLevel> expressionLevels = resp.getExpressionLevelsList();
        assertThat(expressionLevels).hasSize(expectedNumberOfExpressionLevels);
    }

    /**
     * Search expression levels using feature ID filtering. Ensures that returned
     * expression levels have the appropriate feature IDs.
     *
     * @throws GAWrapperException if the server finds the request invalid in some way
     * @throws UnirestException if there's a problem speaking HTTP to the server
     * @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
     */
    @Test
    public void checkFilterByFeatureIds() throws InvalidProtocolBufferException, UnirestException, GAWrapperException {
        final String rnaQuantificationSetId = Utils.getRnaQuantificationSetId(client);
        final String rnaQuantificationId = Utils.getRnaQuantificationId(client, rnaQuantificationSetId);
        // Search expression levels without filter
        final SearchExpressionLevelsRequest req =
                SearchExpressionLevelsRequest.newBuilder()<commit_msg>Change expected number of expressions<commit_after>package org.ga4gh.cts.api.rnaquantification;

import com.google.protobuf.InvalidProtocolBufferException;
import com.mashape.unirest.http.exceptions.UnirestException;
import ga4gh.RnaQuantificationServiceOuterClass.*;
import junitparams.JUnitParamsRunner;
import org.ga4gh.ctk.transport.URLMAPPING;
import org.ga4gh.ctk.transport.protocols.Client;
import org.ga4gh.ctk.transport.GAWrapperException;
import org.ga4gh.cts.api.Utils;
import ga4gh.RnaQuantificationOuterClass.ExpressionLevel;
import ga4gh.SequenceAnnotationServiceOuterClass.*;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Tests for <tt>GET /expressionlevels/{id}</tt>.
 */
@Category(RnaQuantificationTests.class)
@RunWith(JUnitParamsRunner.class)
public class ExpressionLevelsIT {

    private static Client client = new Client(URLMAPPING.getInstance());

    /**
     * Verify that ExpressionLevels that we obtain by way of {@link ga4gh.RnaQuantificationServiceOuterClass.SearchExpressionLevelsRequest} match the ones
     * we get via <tt>GET /expressionlevels/{id}</tt>.
     * @throws GAWrapperException if the server finds the request invalid in some way
     * @throws UnirestException if there's a problem speaking HTTP to the server
     * @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
     */
    @Test
    public void checkExpressionLevelGetResultsMatchSearchResults() throws InvalidProtocolBufferException, UnirestException, GAWrapperException {
        final String rnaQuantificationSetId = Utils.getRnaQuantificationSetId(client);
        final String rnaQuantificationId = Utils.getRnaQuantificationId(client, rnaQuantificationSetId);
        final String expressionLevelId = Utils.getExpressionLevelId(client, rnaQuantificationId);
        final ExpressionLevel expressionLevelFromGet = client.rnaquantifications.getExpressionLevel(expressionLevelId);
        assertThat(expressionLevelFromGet).isNotNull();
        assertThat(expressionLevelFromGet.getId()).isEqualTo(expressionLevelId);
    }


    /**
     * Fetch expression levels and count them.  The number must
     * equal what we're expecting by visual examination of the data.
     *
     * @throws GAWrapperException if the server finds the request invalid in some way
     * @throws UnirestException if there's a problem speaking HTTP to the server
     * @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
     */
    @Test
    public void checkExpectedNumberOfExpressionLevels() throws InvalidProtocolBufferException, UnirestException, GAWrapperException {
        final int expectedNumberOfExpressionLevels = 8;
        final String rnaQuantificationSetId = Utils.getRnaQuantificationSetId(client);
        final String rnaQuantificationId = Utils.getRnaQuantificationId(client, rnaQuantificationSetId);

        final SearchExpressionLevelsRequest req =
                SearchExpressionLevelsRequest.newBuilder()
                        .setRnaQuantificationId(rnaQuantificationId)
                        .build();
        final SearchExpressionLevelsResponse resp = client.rnaquantifications.searchExpressionLevel(req);

        final List<ExpressionLevel> expressionLevels = resp.getExpressionLevelsList();
        assertThat(expressionLevels).hasSize(expectedNumberOfExpressionLevels);
    }

    /**
     * Search expression levels using feature ID filtering. Ensures that returned
     * expression levels have the appropriate feature IDs.
     *
     * @throws GAWrapperException if the server finds the request invalid in some way
     * @throws UnirestException if there's a problem speaking HTTP to the server
     * @throws InvalidProtocolBufferException if there's a problem processing the JSON response from the server
     */
    @Test
    public void checkFilterByFeatureIds() throws InvalidProtocolBufferException, UnirestException, GAWrapperException {
        final String rnaQuantificationSetId = Utils.getRnaQuantificationSetId(client);
        final String rnaQuantificationId = Utils.getRnaQuantificationId(client, rnaQuantificationSetId);
        // Search expression levels without filter
        final SearchExpressionLevelsRequest req =
                SearchExpressionLevelsRequest.newBuilder()
{'fraction_non_alphanumeric': 0.06468609865470852, 'fraction_numerical': 0.002242152466367713, 'mean_word_length': 4.406666666666666, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4630823', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2215, 'n_words': 603}