/*
 * 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;
        }
    }

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

        return;
    }
}

@@ -1725,33 +1725,59 @@
       assert
-Equals( 4
+True( %22Expected at least 5 results%22
 , actualResu
@@ -1777,32 +1777,37 @@
 ualResult.size()
+ %3E= 5
  ); // at least,
@@ -1825,35 +1825,118 @@
 he result on
- 8/10
+%0A                                                                                    // 4
 /200
-6.
+8
 %0A        %7D c
@@ -2080,29 +2080,25 @@
     %7D%0A    %7D%0A
-    
 %0A
+
     public v
@@ -2571,17 +2571,41 @@
 sert
-Equals( 4
+True( %22Expect at least 5 results%22
 , ac
@@ -2613,32 +2613,37 @@
 ualResult.size()
+ %3E= 5
  ); // at least,
@@ -2661,34 +2661,118 @@
 he result on
- 8/10
+%0A                                                                                    // 4
 /200
-6
+8
 .%0A        %7D 
@@ -2921,20 +2921,16 @@
 %7D%0A    %7D%0A
-    
 %0A    /*%0A

update test and protect against future failures due to pubmed updates