<commit_before>/*
 * The Gemma project
 * 
 * Copyright (c) 2006 University of British Columbia
 * 
 * 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 ubic.gemma.loader.entrez.pubmed;

import java.util.Collection;
import java.util.HashSet;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ubic.gemma.model.common.description.BibliographicReference;

/**
 * @author pavlidis
 * @version $Id$
 */
public class PubMedSearchTest extends TestCase {

    private static Log log = LogFactory.getLog( PubMedSearchTest.class.getName() );

    /*
     * Test method for 'ubic.gemma.loader.entrez.pubmed.PubMedSearch.searchAndRetriveByHTTP(Collection<String>)'
     */
    public void testSearchAndRetrieveByHTTP() throws Exception {
        try {
            PubMedSearch pms = new PubMedSearch();
            Collection<String> searchTerms = new HashSet<String>();
            searchTerms.add( "brain" );
            searchTerms.add( "hippocampus" );
            searchTerms.add( "habenula" );
            searchTerms.add( "glucose" );
            Collection<BibliographicReference> actualResult = pms.searchAndRetrieveByHTTP( searchTerms );
            assertEquals( 4, actualResult.size() ); // at least, this was the result on 8/10/2006.
        } catch ( java.net.UnknownHostException e ) {
            log.warn( "Test skipped due to unknown host exception" );
            return;
        }
    }
    
    public void testSearchAndRetrievIdsByHTTP() throws Exception {
        try {
            PubMedSearch pms = new PubMedSearch();
            Collection<String> searchTerms = new HashSet<String>();
            searchTerms.add( "brain" );
            searchTerms.add( "hippocampus" );
            searchTerms.add( "habenula" );
            searchTerms.add( "glucose" );
            Collection<String> actualResult = pms.searchAndRetrieveIdsByHTTP( searchTerms );
            assertEquals( 4, actualResult.size() ); // at least, this was the result on 8/10/2006.
        } catch ( java.net.UnknownHostException e ) {
            log.warn( "Test skipped due to unknown host exception" );
            return;
        }
    }
    
    /*
     * Test method for 'ubic.gemma.loader.entrez.pubmed.PubMedSearch.searchAndRetriveByHTTP(Collection<String>)'
     */
    public void testSearchAndRetrieveIdByHTTP() throws Exception {
        try {
            PubMedSearch pms = new PubMedSearch();
            Collection<String> searchTerms = new HashSet<String>();
            searchTerms.add( "17084362" );
            Collection<BibliographicReference> actualResult = pms.searchAndRetrieveIdByHTTP( searchTerms );
            assertEquals( 1, actualResult.size() ); // at least, this was the result on 8/10/2006.
        } catch ( java.net.UnknownHostException e ) {
            log.warn( "Test skipped due to unknown host exception" );
            return;
        }
    }<commit_msg>update test and protect against future failures due to pubmed updates<commit_after>/*
 * The Gemma project
 * 
 * Copyright (c) 2006 University of British Columbia
 * 
 * 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 ubic.gemma.loader.entrez.pubmed;

import java.util.Collection;
import java.util.HashSet;

import junit.framework.TestCase;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import ubic.gemma.model.common.description.BibliographicReference;

/**
 * @author pavlidis
 * @version $Id$
 */
public class PubMedSearchTest extends TestCase {

    private static Log log = LogFactory.getLog( PubMedSearchTest.class.getName() );

    /*
     * Test method for 'ubic.gemma.loader.entrez.pubmed.PubMedSearch.searchAndRetriveByHTTP(Collection<String>)'
     */
    public void testSearchAndRetrieveByHTTP() throws Exception {
        try {
            PubMedSearch pms = new PubMedSearch();
            Collection<String> searchTerms = new HashSet<String>();
            searchTerms.add( "brain" );
            searchTerms.add( "hippocampus" );
            searchTerms.add( "habenula" );
            searchTerms.add( "glucose" );
            Collection<BibliographicReference> actualResult = pms.searchAndRetrieveByHTTP( searchTerms );
            assertTrue( "Expected at least 5 results", actualResult.size() >= 5 ); // at least, this was the result on
                                                                                    // 4/2008
        } catch ( java.net.UnknownHostException e ) {
            log.warn( "Test skipped due to unknown host exception" );
            return;
        }
    }

    public void testSearchAndRetrievIdsByHTTP() throws Exception {
        try {
            PubMedSearch pms = new PubMedSearch();
            Collection<String> searchTerms = new HashSet<String>();
            searchTerms.add( "brain" );
            searchTerms.add( "hippocampus" );
            searchTerms.add( "habenula" );
            searchTerms.add( "glucose" );
            Collection<String> actualResult = pms.searchAndRetrieveIdsByHTTP( searchTerms );
            assertTrue( "Expect at least 5 results", actualResult.size() >= 5 ); // at least, this was the result on
                                                                                    // 4/2008.
        } catch ( java.net.UnknownHostException e ) {
            log.warn( "Test skipped due to unknown host exception" );
            return;
        }
    }

    /*
     * Test method for 'ubic.gemma.loader.entrez.pubmed.PubMedSearch.searchAndRetriveByHTTP(Collection<String>)'
     */
    public void testSearchAndRetrieveIdByHTTP() throws Exception {
        try {
            PubMedSearch pms = new PubMedSearch();
            Collection<String> searchTerms = new HashSet<String>();
            searchTerms.add( "17084362" );
            Collection<BibliographicReference> actualResult = pms.searchAndRetrieveIdByHTTP( searchTerms );
            assertEquals( 1, actualResult.size() ); // at least, this was the result on 8/10/2006.
        } catch ( java.net.UnknownHostException e ) {
            log.warn( "Test skipped due to unknown host exception" );
            return;
        }
    }
{'fraction_non_alphanumeric': 0.09566662051779039, 'fraction_numerical': 0.010798837048317873, 'mean_word_length': 2.4831243972999038, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3319088', 'n_tokens_mistral': 1995, 'n_tokens_neox': 1897, 'n_words': 554}