1 package org.broadinstitute.hellbender.cmdline;
2 
3 import org.broadinstitute.hellbender.CommandLineProgramTest;
4 import org.broadinstitute.hellbender.exceptions.PicardNonZeroExitException;
5 import org.broadinstitute.hellbender.testutils.IntegrationTestSpec;
6 import org.testng.Assert;
7 import org.testng.annotations.Test;
8 
9 import java.io.File;
10 import java.io.IOException;
11 import java.util.List;
12 
13 
14 // Test that we can successfully run Picard tools.
15 public final class PicardCommandLineProgramExecutorIntegrationTest extends CommandLineProgramTest {
16 
17     // Use the Picard tool "NormalizeFasta" as a simple test case.
18     private static final File TEST_DATA_PATH = new File(getTestDataDir(), "picard/fastq/NormalizeFasta");
19 
20     @Override
getTestedClassName()21     public String getTestedClassName() {
22         return picard.reference.NormalizeFasta.class.getSimpleName();
23     }
24 
25     @Override
injectDefaultVerbosity(final List<String> args)26     public List<String> injectDefaultVerbosity(final List<String> args) {
27         // override/suppress GATK-specific argument injection
28         return args;
29     }
30 
31     @Test
testPicardNormalizeFasta()32     public void testPicardNormalizeFasta() throws IOException {
33         final File input = new File(TEST_DATA_PATH, "testfasta.fasta");
34         final File expectedFile = new File(TEST_DATA_PATH, "testFASTA_WS_4.fasta");
35         final File outfile = createTempFile("normalized", ".fasta");
36 
37         final String[] args = {
38                 "-I", input.getAbsolutePath(),
39                 "-O", outfile.getAbsolutePath(),
40                 "--TRUNCATE_SEQUENCE_NAMES_AT_WHITESPACE", "TRUE",
41                 "--LINE_LENGTH", "5",
42         };
43 
44         Assert.assertEquals(runCommandLine(args), 0);
45 
46         IntegrationTestSpec.assertEqualTextFiles(outfile, expectedFile);
47     }
48 
49     @Test(expectedExceptions=PicardNonZeroExitException.class)
testPicardNormalizeFastaWithBadArgs()50     public void testPicardNormalizeFastaWithBadArgs() throws IOException {
51         final File input = new File(TEST_DATA_PATH, "testfasta.fasta");
52         final File outfile = createTempFile("normalized", ".fasta");
53 
54         // Use GATK-style lower case argument names, which are rejected by Picard
55         // because it uses upper cased argument names (--INPUT/--OUTPUT)
56         final String[] args = {
57                 "--input", input.getAbsolutePath(),
58                 "--output", outfile.getAbsolutePath(),
59                 "--TRUNCATE_SEQUENCE_NAMES_AT_WHITESPACE", "TRUE",
60                 "--LINE_LENGTH", "5",
61         };
62 
63         // The tool should fail due to the lower case argument name; Picard doesn't throw but
64         // does return a non-zero return code
65         Assert.assertNotEquals(runCommandLine(args), 0);
66     }
67 
68 }
69