/*
* Copyright 2012-2015 Broad Institute, Inc.
* 
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
* 
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

package org.broadinstitute.gatk.engine.arguments;

import org.broadinstitute.gatk.engine.walkers.WalkerTest;
import org.broadinstitute.gatk.utils.exceptions.UserException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.util.Collections;

/**
 * Test the GATK core CRAM parsing mechanism.
 */
public class CramIntegrationTest extends WalkerTest {
    @DataProvider(name="cramData")
    public Object[][] getCRAMData() {
        return new Object[][] {
                {"PrintReads", "exampleBAM.bam", "", "cram", "95cce9111a377d8e84fd076f7f0744df"},
                {"PrintReads", "exampleCRAM.cram", "", "cram", "95cce9111a377d8e84fd076f7f0744df"},
                {"PrintReads", "exampleCRAM.cram", "", "bam", "7c716d5103c20e95a8115b3c2848bf0d"},
                {"PrintReads", "exampleCRAM.cram", " -L chr1:200", "bam", "5cc9cac96f7f9819688d47a28ed97778"},
                {"CountLoci", "exampleCRAM.cram", "", "txt", "ade93df31a6150321c1067e749cae9be"},
                {"CountLoci", "exampleCRAM.cram", " -L chr1:200", "txt", "b026324c6904b2a9cb4b88d6d61c81d1"},
                {"CountReads", "exampleCRAM.cram", "", "txt", "4fbafd6948b6529caa2b78e476359875"},
                {"CountReads", "exampleCRAM.cram", " -L chr1:200", "txt", "b026324c6904b2a9cb4b88d6d61c81d1"},
                {"PrintReads", "exampleCRAM.cram", " -L chr1:200 -L chr1:89597", "bam", "2e1b175c9b36154e2bbd1a23ebaf4c22"},
                {"CountLoci", "exampleCRAM.cram", " -L chr1:200 -L chr1:89597", "txt", "26ab0db90d72e28ad0ba1e22ee510510"},
                {"CountReads", "exampleCRAM.cram", " -L chr1:200 -L chr1:89597", "txt", "6d7fce9fee471194aa8b5b6e47267f03"},
        };
    }

    @Test(dataProvider = "cramData")
    public void testCRAM(String walker, String input, String args, String ext, String md5) {
        WalkerTestSpec spec = new WalkerTestSpec(
                " -T Test" + walker + "Walker" +
                    " -I " + publicTestDir + input +
                    " -R " + exampleFASTA +
                    args +
                    " -o %s",
                1, // just one output file
                Collections.singletonList(ext),
                Collections.singletonList(md5));
        executeTest(String.format("testCRAM %s %s -> %s: %s", walker, input, ext, args), spec);
    }

    @DataProvider(name = "cramNoBaiData")
    public Object[][] getCRAMNoBaiData() {
        return new Object[][]{
                {"exampleCRAM-nobai-nocrai.cram"},
                {"exampleCRAM-nobai-withcrai.cram"},
        };
    }

    @Test(dataProvider = "cramNoBaiData")
    public void testCRAMNoBai(String input) {
        WalkerTestSpec spec = new WalkerTestSpec(
                " -T TestPrintReadsWalker" +
                        " -I " + publicTestDir + input +
                        " -R " + exampleFASTA,
                0,
                UserException.class);
        executeTest(String.format("testCRAMNoBai %s", input), spec);
    }
}
