package org.broad.igv.util.ftp;

import static junit.framework.Assert.*;

import org.junit.Test;

import java.net.URL;


/**
 * @author Jim Robinson
 * @since 10/4/11
 */
public class FTPUtilsTest {

    @Test
    public void testResourceAvailable() throws Exception {
        URL goodUrl = new URL("ftp://ftp.broadinstitute.org/pub/igv/TEST/test.txt");
        assertTrue(FTPUtils.resourceAvailable(goodUrl));

        URL nonExistentURL = new URL("ftp://ftp.broadinstitute.org/pub/igv/TEST/doesntExist");
        assertFalse(FTPUtils.resourceAvailable(nonExistentURL));

        URL nonExistentServer = new URL("ftp://noSuchServer/pub/igv/TEST/doesntExist");
        assertFalse(FTPUtils.resourceAvailable(nonExistentServer));
    }

    @Test
    public void testNCBIResourceAvailable() throws Exception {

        URL vcfURL = new URL("ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/release/20110521/ALL.wgs.phase1_release_v3.20101123.snps_indels_sv.sites.vcf.gz");
        assertTrue(FTPUtils.resourceAvailable(vcfURL));

        URL tabixURL = new URL("ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/release/20110521/ALL.wgs.phase1_release_v3.20101123.snps_indels_sv.sites.vcf.gz.tbi");
        assertTrue(FTPUtils.resourceAvailable(tabixURL));

    }

    @Test
    public void testGetContentLength() throws Exception {

        URL vcfURL = new URL("ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/release/20110521/ALL.wgs.phase1_release_v3.20101123.snps_indels_sv.sites.vcf.gz");

        long contentLength = 1297662912;

        assertEquals(contentLength, FTPUtils.getContentLength(vcfURL));

    }
}

@@ -1,77 +1,622 @@
-package org.broad.igv.util.ftp;%0A%0Aimport static junit.framework.Assert.*;%0A
+/*%0A * Copyright (c) 2007-2013 The Broad Institute, Inc.%0A * SOFTWARE COPYRIGHT NOTICE%0A * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.%0A *%0A * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.%0A *%0A * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),%0A * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.%0A */%0A%0Apackage org.broad.igv.util.ftp;%0A%0Aimport org.broad.igv.util.TestUtils;
 %0Aimp
@@ -658,16 +658,57 @@
 t.URL;%0A%0A
+import static junit.framework.Assert.*;%0A%0A
 %0A/**%0A * 
@@ -882,60 +882,35 @@
 URL(
-%22ftp://ftp.broadinstitute.org/pub/igv/TEST/test.txt%22
+TestUtils.AVAILABLE_FTP_URL
 );%0A 

Change reused url string to use static field