/*
 * 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.expression.geo.fetcher;

import java.util.Collection;
import java.util.concurrent.ExecutionException;

import junit.framework.TestCase;

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

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

/**
 * @author pavlidis
 * @version $Id$
 */
public class RawDataFetcherTest extends TestCase {
    private static Log log = LogFactory.getLog( RawDataFetcherTest.class.getName() );

    /*
     * @see TestCase#setUp()
     */
    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    /*
     * @see TestCase#tearDown()
     */
    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    /*
     * Test method for 'ubic.gemma.loader.expression.geo.RawDataFetcher.fetch(String)'
     */
    public void testFetch() throws Exception {
        RawDataFetcher rdf = new RawDataFetcher();
        try {
            Collection<LocalFile> result = rdf.fetch( "GSE1105" );
            assertEquals( 8, result.size() );
        } catch ( Exception e ) {
            if ( e.getCause() instanceof ExecutionException ) {
                log.error( "Failed to get file -- skipping rest of test" );
                return;
            } else if ( e.getCause() instanceof java.net.UnknownHostException ) {
                log.error( "Failed to connect to NCBI, skipping test" );
                return;
            } else if ( e.getCause() instanceof org.apache.commons.net.ftp.FTPConnectionClosedException ) {
                log.error( "Failed to connect to NCBI, skipping test" );
                return;
            }
            throw e;
        }

    }

    /*
     * Test method for 'ubic.gemma.loader.expression.geo.RawDataFetcher.fetch(String)'
     */
    public void testFetchNothingThere() {
        RawDataFetcher rdf = new RawDataFetcher();
        Collection<LocalFile> result = rdf.fetch( "GSE1001" );
        assert ( result == null );
    }

}

@@ -2509,19 +2509,36 @@
 gThere()
+ throws Exception
  %7B%0A
-
         
@@ -2572,32 +2572,51 @@
 wDataFetcher();%0A
+%0A        try %7B%0A    
         Collecti
@@ -2666,24 +2666,28 @@
  );%0A        
+    
 assert ( res
@@ -2697,21 +2697,477 @@
  == null );%0A
+        %7D catch ( Exception e ) %7B%0A            if ( e.getCause() instanceof java.net.UnknownHostException ) %7B%0A                log.error( %22Failed to connect to NCBI, skipping test%22 );%0A                return;%0A            %7D else if ( e.getCause() instanceof org.apache.commons.net.ftp.FTPConnectionClosedException ) %7B%0A                log.error( %22Failed to connect to NCBI, skipping test%22 );%0A                return;%0A            %7D%0A            throw e;%0A        %7D%0A
     %7D%0A%0A%7D%0A

test resilience