<commit_before>/*
 * Copyright 2014-2017 EMBL - European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.ac.ebi.eva.lib.metadata.dgva;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;

import uk.ac.ebi.eva.lib.utils.QueryOptions;
import uk.ac.ebi.eva.lib.utils.QueryResult;
import uk.ac.ebi.eva.lib.utils.QueryOptionsConstants;

import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static uk.ac.ebi.eva.lib.metadata.MetadataTestData.CHICKEN;
import static uk.ac.ebi.eva.lib.metadata.MetadataTestData.CHIMPANZEE;
import static uk.ac.ebi.eva.lib.metadata.MetadataTestData.HUMAN;
import static uk.ac.ebi.eva.lib.metadata.MetadataTestData.MOUSE;

@RunWith(SpringRunner.class)
@DataJpaTest
@Sql({"classpath:dgva-schema.sql", "classpath:dgva-data.sql"})
public class ArchiveDgvaDBAdaptorTest {

    @Autowired
    private TestEntityManager entityManager;

    @Autowired
    private ArchiveDgvaDBAdaptor archiveDgvaDBAdaptor;

    @Before
    public void setUp() throws Exception {
        //DgvaStudyTestData.persistTestData(entityManager);
    }

    @Test
    public void countStudies() throws Exception {
        QueryResult<Long> queryResult = archiveDgvaDBAdaptor.countStudies();

        assertEquals(1, queryResult.getNumTotalResults());
        assertEquals(205, queryResult.first().longValue());
    }

    @Test
    public void countStudiesPerSpeciesFilteringBySpecies() throws Exception {
        QueryResult<Map.Entry<String, Long>> queryResult = archiveDgvaDBAdaptor
                .countStudiesPerSpecies(new QueryOptions(QueryOptionsConstants.SPECIES, HUMAN));

        assertEquals(7, queryResult.getNumTotalResults());
        Map.Entry<String, Long> result = queryResult.first();
        assertEquals(HUMAN, result.getKey());
        assertEquals(155, result.getValue().longValue());
    }

    @Test<commit_msg>Removed unnecessary code from ArchiveDgvaDBAdaptorTest<commit_after>/*
 * Copyright 2014-2017 EMBL - European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package uk.ac.ebi.eva.lib.metadata.dgva;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;

import uk.ac.ebi.eva.lib.utils.QueryOptions;
import uk.ac.ebi.eva.lib.utils.QueryResult;
import uk.ac.ebi.eva.lib.utils.QueryOptionsConstants;

import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static uk.ac.ebi.eva.lib.metadata.MetadataTestData.CHICKEN;
import static uk.ac.ebi.eva.lib.metadata.MetadataTestData.CHIMPANZEE;
import static uk.ac.ebi.eva.lib.metadata.MetadataTestData.HUMAN;
import static uk.ac.ebi.eva.lib.metadata.MetadataTestData.MOUSE;

@RunWith(SpringRunner.class)
@DataJpaTest
@Sql({"classpath:dgva-schema.sql", "classpath:dgva-data.sql"})
public class ArchiveDgvaDBAdaptorTest {

    @Autowired
    private ArchiveDgvaDBAdaptor archiveDgvaDBAdaptor;

    @Test
    public void countStudies() throws Exception {
        QueryResult<Long> queryResult = archiveDgvaDBAdaptor.countStudies();

        assertEquals(1, queryResult.getNumTotalResults());
        assertEquals(205, queryResult.first().longValue());
    }

    @Test
    public void countStudiesPerSpeciesFilteringBySpecies() throws Exception {
        QueryResult<Map.Entry<String, Long>> queryResult = archiveDgvaDBAdaptor
                .countStudiesPerSpecies(new QueryOptions(QueryOptionsConstants.SPECIES, HUMAN));

        assertEquals(7, queryResult.getNumTotalResults());
        Map.Entry<String, Long> result = queryResult.first();
        assertEquals(HUMAN, result.getKey());
        assertEquals(155, result.getValue().longValue());
    }

    @Test
{'fraction_non_alphanumeric': 0.10099868098737516, 'fraction_numerical': 0.00791407574901074, 'mean_word_length': 4.427402862985685, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5714836', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1565, 'n_words': 362}