-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow BCFCodec subclasses to provide custom version compatibility. (#…
- Loading branch information
Showing
4 changed files
with
150 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package htsjdk.variant.bcf2; | ||
|
||
import htsjdk.variant.VariantBaseTest; | ||
import org.testng.Assert; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
public class BCF2VersionTest extends VariantBaseTest { | ||
|
||
@DataProvider(name = "bcfVersionEqualsHashData") | ||
public Object[][] bcfVersionEqualsHashData() { | ||
return new Object[][]{ | ||
{ | ||
BCF2Codec.ALLOWED_BCF_VERSION, | ||
new BCFVersion(BCF2Codec.ALLOWED_MAJOR_VERSION, BCF2Codec.ALLOWED_MINOR_VERSION), | ||
true | ||
}, | ||
{ | ||
new BCFVersion(0, 0), | ||
new BCFVersion(0, 0), | ||
true | ||
}, | ||
{ | ||
BCF2Codec.ALLOWED_BCF_VERSION, | ||
new BCFVersion(0, 0), | ||
false | ||
}, | ||
{ | ||
BCF2Codec.ALLOWED_BCF_VERSION, | ||
new BCFVersion(0, BCF2Codec.ALLOWED_MAJOR_VERSION), | ||
false | ||
}, | ||
{ | ||
BCF2Codec.ALLOWED_BCF_VERSION, | ||
new BCFVersion(0, BCF2Codec.ALLOWED_MAJOR_VERSION), | ||
false | ||
}, | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "bcfVersionEqualsHashData") | ||
private final void testBCFVersionEquals(final BCFVersion v1, BCFVersion v2, boolean expected) { | ||
Assert.assertEquals(expected, v1.equals(v2)); | ||
Assert.assertEquals(expected, v2.equals(v1)); | ||
} | ||
|
||
@Test(dataProvider = "bcfVersionEqualsHashData") | ||
private final void testBCFVersionHash(final BCFVersion v1, BCFVersion v2, boolean expected) { | ||
// given the small space the test data is drawn from, assume not equals => different | ||
// hash codes just for this test | ||
Assert.assertEquals(expected,v1.hashCode() == v2.hashCode()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package htsjdk.variant.bcf2; | ||
|
||
import htsjdk.tribble.FeatureCodecHeader; | ||
import htsjdk.tribble.TribbleException; | ||
import htsjdk.tribble.readers.PositionalBufferedStream; | ||
import htsjdk.variant.VariantBaseTest; | ||
import htsjdk.variant.vcf.VCFHeader; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
|
||
public class BCFCodecTest extends VariantBaseTest { | ||
final String TEST_DATA_DIR = "src/test/resources/htsjdk/variant/"; | ||
|
||
// should reject bcf v2.2 on read, see issue https://github.com/samtools/htsjdk/issues/1323 | ||
@Test(expectedExceptions = TribbleException.class) | ||
private void testRejectBCFVersion22() throws IOException { | ||
BCF2Codec bcfCodec = new BCF2Codec(); | ||
try (final FileInputStream fis = new FileInputStream(new File(TEST_DATA_DIR, "BCFVersion22Uncompressed.bcf")); | ||
final PositionalBufferedStream pbs = new PositionalBufferedStream(fis)) { | ||
bcfCodec.readHeader(pbs); | ||
} | ||
} | ||
|
||
@Test | ||
private void testBCFCustomVersionCompatibility() throws IOException { | ||
final BCF2Codec bcfCodec = new BCF2Codec() { | ||
@Override | ||
protected void validateVersionCompatibility(final BCFVersion supportedVersion, final BCFVersion actualVersion) { | ||
return; | ||
} | ||
}; | ||
|
||
// the default BCF2Codec version compatibility policy is to reject BCF 2.2 input; but make sure we can | ||
// provide a codec that implements a more tolerant custom policy that accepts | ||
try (final FileInputStream fis = new FileInputStream(new File(TEST_DATA_DIR, "BCFVersion22Uncompressed.bcf")); | ||
final PositionalBufferedStream pbs = new PositionalBufferedStream(fis)) { | ||
final FeatureCodecHeader featureCodecHeader = (FeatureCodecHeader) bcfCodec.readHeader(pbs); | ||
final VCFHeader vcfHeader = (VCFHeader) featureCodecHeader.getHeaderValue(); | ||
Assert.assertNotEquals(vcfHeader.getMetaDataInInputOrder().size(), 0); | ||
} | ||
} | ||
} | ||
|