/*
 * Copyright (c) 2007-2012 The Broad Institute, Inc.
 * SOFTWARE COPYRIGHT NOTICE
 * This software and its documentation are the copyright of the Broad Institute, Inc. All rights are reserved.
 *
 * This software is supplied without any warranty or guaranteed support whatsoever. The Broad Institute is not responsible for its use, misuse, or functionality.
 *
 * This software is licensed under the terms of the GNU Lesser General Public License (LGPL),
 * Version 2.1 which is available at http://www.opensource.org/licenses/lgpl-2.1.php.
 */

package org.broad.igv.track;

import org.broad.igv.feature.genome.Genome;
import org.broad.igv.ui.AbstractHeadedTest;
import org.broad.igv.util.ResourceLocator;
import org.broad.igv.util.TestUtils;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/**
 * @author Jim Robinson
 * @date 10/3/11
 */
public class TrackLoaderTestHeaded extends AbstractHeadedTest {

    TrackLoader trackLoader;

    @Before
    public void setUp() throws Exception {
        super.setUp();
        trackLoader = new TrackLoader();
    }

    @Test
    public void testFilesHeaded() throws Exception {

        String ex_filename = "/vcf/example4-last-gsnap-2_fixed.vcf";
        Genome genome = TestUtils.loadGenome();
        List<String> finames = new ArrayList<String>(Arrays.asList(TrackLoaderTest.filenames));

        finames.add(ex_filename);

        for (String finame : finames) {
            TrackLoaderTest.tstLoadFi(trackLoader, TestUtils.DATA_DIR + finame, null, genome, true);
        }
    }


    @Test
    public void testReadVCF() throws Exception {
        String file = TestUtils.DATA_DIR + "vcf/outputPileup.flt1.vcf";
        TestUtils.createIndex(file);
        ResourceLocator locator = new ResourceLocator(file);
        //For files with 1 record, this threw a null pointer exception prior to r1595
        List<Track> tracks = igv.load(locator);

        Assert.assertEquals(1, tracks.size());
    }


}

@@ -656,24 +656,53 @@
 HeadedTest;%0A
+import org.broad.igv.ui.IGV;%0A
 import org.b
@@ -920,16 +920,62 @@
 .List;%0A%0A
+import static org.junit.Assert.assertEquals;%0A%0A
 %0A/**%0A * 
@@ -2127,11 +2127,533 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void testLoadBAMFtpHeaded() throws Exception%7B%0A        String path = %22ftp://ftp.broadinstitute.org/pub/igv/TEST/HG00171.hg18.bam%22;%0A        Integer expected_tracks = 2;%0A%0A%0A        List%3CTrack%3E tracks = IGV.getInstance().getAllTracks();%0A        int initTracks = tracks.size();%0A%0A        ResourceLocator locator = new ResourceLocator(path);%0A%0A        IGV.getInstance().load(locator);%0A%0A        tracks = IGV.getInstance().getAllTracks();%0A%0A        assertEquals(initTracks + expected_tracks, tracks.size());%0A    %7D
 %0A%7D%0A

Add test for loading BAM from ftp headed