From 5a4a9a8e443f727bfc00b9219a111d2b99e902b9 Mon Sep 17 00:00:00 2001 From: Chris Norman Date: Mon, 28 Feb 2022 10:06:41 -0500 Subject: [PATCH] Versioned header line validation framework. --- .../htsjdk/variant/vcf/VCFAltHeaderLine.java | 6 +- .../variant/vcf/VCFCompoundHeaderLine.java | 6 +- .../variant/vcf/VCFContigHeaderLine.java | 6 +- .../variant/vcf/VCFFilterHeaderLine.java | 2 +- .../variant/vcf/VCFFormatHeaderLine.java | 2 +- .../java/htsjdk/variant/vcf/VCFHeader.java | 6 +- .../htsjdk/variant/vcf/VCFHeaderLine.java | 78 +++++++++++-------- .../htsjdk/variant/vcf/VCFInfoHeaderLine.java | 2 +- .../htsjdk/variant/vcf/VCFMetaDataLines.java | 6 +- .../htsjdk/variant/vcf/VCFMetaHeaderLine.java | 6 +- .../variant/vcf/VCFPedigreeHeaderLine.java | 6 +- .../variant/vcf/VCFSampleHeaderLine.java | 6 +- .../variant/vcf/VCFSimpleHeaderLine.java | 36 ++++----- .../variant/vcf/VCFHeaderLineUnitTest.java | 8 +- .../vcf/VCFInfoHeaderLineUnitTest.java | 2 +- 15 files changed, 92 insertions(+), 86 deletions(-) diff --git a/src/main/java/htsjdk/variant/vcf/VCFAltHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFAltHeaderLine.java index 37ac9874e9..d195dca6d8 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFAltHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFAltHeaderLine.java @@ -22,7 +22,7 @@ public VCFAltHeaderLine(final String line, final VCFHeaderVersion version) { // Honor the requested version to choose the parser, and let validateForVersion figure out // whether that version is valid for this line (for example, if this is called with a pre-4.0 version) super(VCFConstants.ALT_HEADER_KEY, VCFHeaderLineTranslator.parseLine(version, line, expectedTags)); - validateForVersion(version); + validateForVersionOrThrow(version); } public VCFAltHeaderLine(final String id, final String description) { @@ -35,7 +35,7 @@ public VCFAltHeaderLine(final String id, final String description) { } @Override - public Optional> getValidationFailure(final VCFHeaderVersion vcfTargetVersion) { + public Optional> validateForVersion(final VCFHeaderVersion vcfTargetVersion) { //TODO: Should we validate/constrain these to match the 4.3 spec constraints ? if (!vcfTargetVersion.isAtLeastAsRecentAs(VCFHeaderVersion.VCF4_0)) { final VCFValidationFailure validationFailure = new VCFValidationFailure<>( @@ -49,6 +49,6 @@ public Optional> getValidationFailure(final } } - return super.getValidationFailure(vcfTargetVersion); + return super.validateForVersion(vcfTargetVersion); } } diff --git a/src/main/java/htsjdk/variant/vcf/VCFCompoundHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFCompoundHeaderLine.java index 7f0f255883..c970dd7da5 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFCompoundHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFCompoundHeaderLine.java @@ -126,7 +126,7 @@ protected VCFCompoundHeaderLine(final String key, final Map mapp final String countString = getGenericFieldValue(NUMBER_ATTRIBUTE); this.countType = decodeCountType(countString, vcfVersion); this.count = decodeCount(countString, this.countType); - validateForVersion(vcfVersion); + validateForVersionOrThrow(vcfVersion); } /** @@ -174,7 +174,7 @@ public String getVersion() { } @Override - public Optional> getValidationFailure(final VCFHeaderVersion vcfTargetVersion) { + public Optional> validateForVersion(final VCFHeaderVersion vcfTargetVersion) { // The VCF 4.3 spec does not phrase this restriction as one on the form of the ID value of // INFO/FORMAT lines but instead on the INFO/FORMAT fixed field key values (c.f. section 1.6.1). // However, the key values correspond to INFO/FORMAT header lines defining the attribute and its type, @@ -194,7 +194,7 @@ public Optional> getValidationFailure(final } } - return super.getValidationFailure(vcfTargetVersion); + return super.validateForVersion(vcfTargetVersion); } /** diff --git a/src/main/java/htsjdk/variant/vcf/VCFContigHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFContigHeaderLine.java index d8a19e2fa5..01794bd51e 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFContigHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFContigHeaderLine.java @@ -97,7 +97,7 @@ public VCFContigHeaderLine(final String line, final VCFHeaderVersion version, fi if (contigIndex < 0) { throw new TribbleException(String.format("The contig index (%d) is less than zero.", contigIndex)); } - validateForVersion(version); + validateForVersionOrThrow(version); } public VCFContigHeaderLine(final Map mapping, final int contigIndex) { @@ -186,7 +186,7 @@ public SAMSequenceRecord getSAMSequenceRecord() { } @Override - public Optional> getValidationFailure(final VCFHeaderVersion vcfTargetVersion) { + public Optional> validateForVersion(final VCFHeaderVersion vcfTargetVersion) { if (vcfTargetVersion.isAtLeastAsRecentAs(VCFHeaderVersion.VCF4_3)) { if (!VALID_CONTIG_ID_PATTERN.matcher(getID()).matches()) { return Optional.of(new VCFValidationFailure<>( @@ -196,7 +196,7 @@ public Optional> getValidationFailure(final } } - return super.getValidationFailure(vcfTargetVersion); + return super.validateForVersion(vcfTargetVersion); } public Integer getContigIndex() { diff --git a/src/main/java/htsjdk/variant/vcf/VCFFilterHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFFilterHeaderLine.java index 1b890db1b1..f0a601b10f 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFFilterHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFFilterHeaderLine.java @@ -78,7 +78,7 @@ public VCFFilterHeaderLine(final String name) { public VCFFilterHeaderLine(final String line, final VCFHeaderVersion version) { super(VCFConstants.FILTER_HEADER_KEY, VCFHeaderLineTranslator.parseLine(version, line, requiredTagOrder)); validate(); - validateForVersion(version); + validateForVersionOrThrow(version); } private void validate() { diff --git a/src/main/java/htsjdk/variant/vcf/VCFFormatHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFFormatHeaderLine.java index fc75ee5291..6d25b0c6e4 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFFormatHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFFormatHeaderLine.java @@ -57,7 +57,7 @@ public VCFFormatHeaderLine(String line, VCFHeaderVersion version) { VCFHeaderLineTranslator.parseLine(version, line, expectedTagOrder), version); validate(); - validateForVersion(version); + validateForVersionOrThrow(version); } /** diff --git a/src/main/java/htsjdk/variant/vcf/VCFHeader.java b/src/main/java/htsjdk/variant/vcf/VCFHeader.java index 0c60e92fd9..520cc0497c 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFHeader.java +++ b/src/main/java/htsjdk/variant/vcf/VCFHeader.java @@ -161,7 +161,7 @@ public VCFHeader(final Set metaData, final List genotypeS // and the header version will be established using the last version line encountered mMetaData.addMetaDataLines(metaData); final VCFHeaderVersion vcfHeaderVersion = initializeHeaderVersion(); - mMetaData.validateMetaDataLines(vcfHeaderVersion); + mMetaData.validateMetaDataLinesOrThrow(vcfHeaderVersion); checkForDeprecatedGenotypeLikelihoodsKey(); if ( genotypeSampleNames.size() != new HashSet<>(genotypeSampleNames).size() ) @@ -625,9 +625,9 @@ private void validateVersionTransition( // the version moved forward, so validate ALL of the existing lines in the list to ensure // that the transition is valid - mMetaData.validateMetaDataLines(newVersion); + mMetaData.validateMetaDataLinesOrThrow(newVersion); } else { - newHeaderLine.validateForVersion(newVersion); + newHeaderLine.validateForVersionOrThrow(newVersion); } } diff --git a/src/main/java/htsjdk/variant/vcf/VCFHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFHeaderLine.java index 94a3a0849e..3e3e03e990 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFHeaderLine.java @@ -50,10 +50,13 @@ public class VCFHeaderLine implements Comparable, Serializable { * @param key the key for this header line * @param value the value for this header line */ - public VCFHeaderLine(String key, String value) { + public VCFHeaderLine(final String key, final String value) { + final Optional validationFailure = validateAttributeName(key, "header line key"); + if (validationFailure.isPresent()) { + throw new TribbleException(validationFailure.get()); + } mKey = key; mValue = value; - validate(); } /** @@ -86,15 +89,20 @@ public String getValue() { public String getID() { return null; } /** - * Validates this header line against {@code vcfTargetVersion}. - * Subclasses can override this to provide line type-specific version validation, and the - * overrides should also call super.getValidationFailure to allow each class in the class hierarchy - * to do class-level validation. + * Validates this header line against {@code vcfTargetVersion} and returns a {@link VCFValidationFailure} + * describing the reaon for the failure, if one exists. This method is used to report the reason for a + * version upgrade failure. + * + * Subclasses can override this to provide line type-specific version validation. Overrides should + * call super.validateForVersion to allow each class in the hierarchy to do class-level validation. * + * @param vcfTargetVersion * @return Optional containing a {@link VCFValidationFailure} describing validation failure if this * line fails validation, otherwise Optional.empty(). */ - public Optional> getValidationFailure(final VCFHeaderVersion vcfTargetVersion) { + public Optional> validateForVersion(final VCFHeaderVersion vcfTargetVersion) { + ValidationUtils.nonNull(vcfTargetVersion); + // If this header line is itself a fileformat/version line, // make sure it doesn't clash with the requested vcfTargetVersion. if (VCFHeaderVersion.isFormatString(getKey())) { @@ -124,33 +132,42 @@ public Optional> getValidationFailure(final } /** - * Validate that the header line conforms to {@code vcfTargetVersion. - * @param vcfTargetVersion + * Validate that the header line conforms to {@code vcfTargetVersion. throws if the line fails to + * validate for the target version. + * + * @param vcfTargetVersion the version agint which to validate the line * @throws {@link TribbleException.VersionValidationFailure} if this header line fails to conform */ - public void validateForVersion(final VCFHeaderVersion vcfTargetVersion) { - final Optional> error = getValidationFailure(vcfTargetVersion); - if (error.isPresent()) { - throw new TribbleException.VersionValidationFailure(error.get().getSourceMessage()); + public void validateForVersionOrThrow(final VCFHeaderVersion vcfTargetVersion) { + ValidationUtils.nonNull(vcfTargetVersion); + final Optional> versionValidationFailure = validateForVersion(vcfTargetVersion); + if (versionValidationFailure.isPresent()) { + throw new TribbleException.VersionValidationFailure(versionValidationFailure.get().getSourceMessage()); } } /** - * Validate a string that is to be used as a unique id or key field. + * Validate a string that is to be used as a unique id or key field, and return an Optional String describing + * the validation failure. + * + * @param targetString the string to validate + * @param targetContext the context for which the {@code targetString} is used. Used when reporting validation + * failures. May not be null. + * @return an Optional String containing an error message */ - protected static void validateKeyOrID(final String keyString, final String sourceName) { - ValidationUtils.nonNull(sourceName); - if (keyString == null) { - throw new TribbleException( - String.format("VCFHeaderLine: %s cannot be null or empty", sourceName)); - } - if ( keyString.contains("<") || keyString.contains(">") ) { - throw new TribbleException( - String.format("VCFHeaderLine: %s cannot contain angle brackets", sourceName)); - } - if ( keyString.contains("=") ) { - throw new TribbleException( - String.format("VCFHeaderLine: %s cannot contain an equals sign", sourceName)); + protected static Optional validateAttributeName(final String targetString, final String targetContext) { + ValidationUtils.nonNull(targetContext); + + if (targetString == null) { + return Optional.of(String.format("VCFHeaderLine: %s is null", targetContext)); + } else if (targetString.length() < 1) { + return Optional.of(String.format("VCFHeaderLine: %s has zero length", targetContext)); + } else if ( targetString.contains("<") || targetString.contains(">") ) { + return Optional.of(String.format("VCFHeaderLine: angle brackets not allowed in \"%s\" value", targetContext)); + } else if ( targetString.contains("=") ) { + return Optional.of(String.format("VCFHeaderLine: equals sign not allowed in %s value \"%s\"", targetContext, targetString)); + } else { + return Optional.empty(); } } @@ -239,13 +256,6 @@ public static String toStringEncoding(Map keyValues) { return builder.toString(); } - /** - * Validate the state of this header line. Require the key be valid as an "id". - */ - private void validate() { - validateKeyOrID(mKey, "key"); - } - private static String escapeQuotes(final String value) { // java escaping in a string literal makes this harder to read than it should be // without string literal escaping and quoting the regex would be: replaceAll( ([^\])" , $1\" ) diff --git a/src/main/java/htsjdk/variant/vcf/VCFInfoHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFInfoHeaderLine.java index 12a29a1f6c..6bb2264ecf 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFInfoHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFInfoHeaderLine.java @@ -67,7 +67,7 @@ public VCFInfoHeaderLine(String line, VCFHeaderVersion version) { VCFHeaderLineTranslator.parseLine(version, line, expectedTagOrder), version ); - validateForVersion(version); + validateForVersionOrThrow(version); } /** diff --git a/src/main/java/htsjdk/variant/vcf/VCFMetaDataLines.java b/src/main/java/htsjdk/variant/vcf/VCFMetaDataLines.java index e88acf274e..3a811f84c4 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFMetaDataLines.java +++ b/src/main/java/htsjdk/variant/vcf/VCFMetaDataLines.java @@ -171,10 +171,10 @@ public VCFHeaderLine findEquivalentHeaderLine(final VCFHeaderLine queryLine) { */ //TODO: we need to tell users how to resolve the case where this fails due to version validation //i.e, use a custom upgrade tool - public void validateMetaDataLines(final VCFHeaderVersion targetVersion) { + public void validateMetaDataLinesOrThrow(final VCFHeaderVersion targetVersion) { mMetaData.values().forEach(headerLine -> { if (!VCFHeaderVersion.isFormatString(headerLine.getKey())) { - headerLine.validateForVersion(targetVersion); + headerLine.validateForVersionOrThrow(targetVersion); } }); } @@ -190,7 +190,7 @@ public void validateMetaDataLines(final VCFHeaderVersion targetVersion) { public Collection getValidationErrors(final VCFHeaderVersion targetVersion) { return mMetaData.values().stream() .filter(line -> !VCFHeaderVersion.isFormatString(line.getKey())) - .map(l -> l.getValidationFailure(targetVersion)) + .map(l -> l.validateForVersion(targetVersion)) .filter(o -> o.isPresent()) .map(o -> o.get()) .collect(Collectors.toList()); diff --git a/src/main/java/htsjdk/variant/vcf/VCFMetaHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFMetaHeaderLine.java index d8cd83b8bb..019ab27c1f 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFMetaHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFMetaHeaderLine.java @@ -15,7 +15,7 @@ public VCFMetaHeaderLine(final String line, final VCFHeaderVersion version) { // other tags. So let validateForVersion detect any version incompatibility, ie., if this is ever // called with a V3 version. super(VCFConstants.META_HEADER_KEY, new VCF4Parser().parseLine(line, expectedTagOrder)); - validateForVersion(version); + validateForVersionOrThrow(version); } public VCFMetaHeaderLine(final Map mapping) { @@ -23,7 +23,7 @@ public VCFMetaHeaderLine(final Map mapping) { } @Override - public Optional> getValidationFailure(final VCFHeaderVersion vcfTargetVersion) { + public Optional> validateForVersion(final VCFHeaderVersion vcfTargetVersion) { if (!vcfTargetVersion.isAtLeastAsRecentAs(VCFHeaderVersion.VCF4_3)) { return Optional.of( new VCFValidationFailure<>( @@ -35,7 +35,7 @@ public Optional> getValidationFailure(final ))); } - return super.getValidationFailure(vcfTargetVersion); + return super.validateForVersion(vcfTargetVersion); } } diff --git a/src/main/java/htsjdk/variant/vcf/VCFPedigreeHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFPedigreeHeaderLine.java index f5bd71c474..5e3b1c1748 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFPedigreeHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFPedigreeHeaderLine.java @@ -21,7 +21,7 @@ public VCFPedigreeHeaderLine(String line, VCFHeaderVersion version) { // other tags. So let validateForVersion detect any version incompatibility, ie., if this is ever // called with a V3 version. super(VCFConstants.PEDIGREE_HEADER_KEY, new VCF4Parser().parseLine(line, expectedTagOrder)); - validateForVersion(version); + validateForVersionOrThrow(version); } public VCFPedigreeHeaderLine(final Map mapping) { @@ -29,7 +29,7 @@ public VCFPedigreeHeaderLine(final Map mapping) { } @Override - public Optional> getValidationFailure(final VCFHeaderVersion vcfTargetVersion) { + public Optional> validateForVersion(final VCFHeaderVersion vcfTargetVersion) { if (!vcfTargetVersion.isAtLeastAsRecentAs(VCFHeaderVersion.VCF4_3)) { // previous to VCFv4.3, the PEDIGREE line did not have an ID. Such lines are not modeled by this // class (since it is derived from VCFSimpleHeaderLine). Therefore instances of this class always @@ -45,7 +45,7 @@ public Optional> getValidationFailure(final } } - return super.getValidationFailure(vcfTargetVersion); + return super.validateForVersion(vcfTargetVersion); } } diff --git a/src/main/java/htsjdk/variant/vcf/VCFSampleHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFSampleHeaderLine.java index 7c45e9a1b2..81c032b8ed 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFSampleHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFSampleHeaderLine.java @@ -15,7 +15,7 @@ public VCFSampleHeaderLine(String line, VCFHeaderVersion version) { // other tags. So let validateForVersion detect any version incompatibility, ie., if this is ever // called with a V3 version. super(VCFConstants.SAMPLE_HEADER_KEY, new VCF4Parser().parseLine(line, expectedTagOrder)); - validateForVersion(version); + validateForVersionOrThrow(version); } public VCFSampleHeaderLine(final Map mapping) { @@ -23,7 +23,7 @@ public VCFSampleHeaderLine(final Map mapping) { } @Override - public Optional> getValidationFailure(final VCFHeaderVersion vcfTargetVersion) { + public Optional> validateForVersion(final VCFHeaderVersion vcfTargetVersion) { if (!vcfTargetVersion.isAtLeastAsRecentAs(VCFHeaderVersion.VCF4_0)) { final String message = String.format("%s header lines are not allowed in VCF version %s headers", getKey(), @@ -36,7 +36,7 @@ public Optional> getValidationFailure(final } } - return super.getValidationFailure(vcfTargetVersion); + return super.validateForVersion(vcfTargetVersion); } } diff --git a/src/main/java/htsjdk/variant/vcf/VCFSimpleHeaderLine.java b/src/main/java/htsjdk/variant/vcf/VCFSimpleHeaderLine.java index c0a3abce5c..e40a544a66 100644 --- a/src/main/java/htsjdk/variant/vcf/VCFSimpleHeaderLine.java +++ b/src/main/java/htsjdk/variant/vcf/VCFSimpleHeaderLine.java @@ -29,11 +29,7 @@ import htsjdk.tribble.TribbleException; import htsjdk.utils.ValidationUtils; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -75,8 +71,7 @@ public class VCFSimpleHeaderLine extends VCFHeaderLine implements VCFIDHeaderLin */ public VCFSimpleHeaderLine(final String key, final String line, final VCFHeaderVersion version) { this(key, VCFHeaderLineTranslator.parseLine(version, line, expectedTagOrder)); - validate(); - validateForVersion(version); + validateForVersionOrThrow(version); } /** @@ -87,10 +82,10 @@ public VCFSimpleHeaderLine(final String key, final String line, final VCFHeaderV * @param description string that will be added as a "Description" tag to this line */ public VCFSimpleHeaderLine(final String key, final String id, final String description) { - super(key, ""); - genericFields.put(ID_ATTRIBUTE, id); - genericFields.put(DESCRIPTION_ATTRIBUTE, description); - validate(); + this(key, new LinkedHashMap() {{ + put(ID_ATTRIBUTE, id); + put(DESCRIPTION_ATTRIBUTE, description); + }}); } /** @@ -105,9 +100,18 @@ public VCFSimpleHeaderLine(final String key, final String id, final String descr */ public VCFSimpleHeaderLine(final String key, final Map attributeMapping) { super(key, ""); + ValidationUtils.nonNull(attributeMapping, "An attribute map is required for structured header lines"); genericFields.putAll(attributeMapping); - validate(); + + if ( genericFields.isEmpty() || !genericFields.keySet().stream().findFirst().get().equals(ID_ATTRIBUTE)) { + throw new TribbleException( + String.format("The required ID tag is missing or not the first attribute: key=%s", super.getKey())); + } + final Optional validationFailure = validateAttributeName(getGenericFieldValue(ID_ATTRIBUTE), "ID"); + if (validationFailure.isPresent()) { + throw new TribbleException(validationFailure.get()); + } } /** @@ -201,14 +205,6 @@ protected boolean getIsQuotableAttribute(final String attributeName) { attributeName.equals(VERSION_ATTRIBUTE); } - private void validate() { - if ( genericFields.isEmpty() || !genericFields.keySet().stream().findFirst().get().equals(ID_ATTRIBUTE)) { - throw new TribbleException( - String.format("The required ID tag is missing or not the first attribute: key=%s", super.getKey())); - } - validateKeyOrID(getGenericFieldValue(ID_ATTRIBUTE), "ID"); - } - // Add quotes around any attribute value that contains a space or comma, or is supposed to be quoted by // definition per the spec (i.e., Description, Source, Version for INFO lines). private String quoteAttributeValueForSerialization(final String attribute, final String originalValue) { diff --git a/src/test/java/htsjdk/variant/vcf/VCFHeaderLineUnitTest.java b/src/test/java/htsjdk/variant/vcf/VCFHeaderLineUnitTest.java index d5d7e47ec9..6cc0eb6443 100644 --- a/src/test/java/htsjdk/variant/vcf/VCFHeaderLineUnitTest.java +++ b/src/test/java/htsjdk/variant/vcf/VCFHeaderLineUnitTest.java @@ -100,9 +100,9 @@ public void testInvalidKeys(final String testKey) { new VCFHeaderLine(testKey, ""); } - @Test(dataProvider = "invalidHeaderLineKeys", expectedExceptions=TribbleException.class) + @Test(dataProvider = "invalidHeaderLineKeys") public void testValidateAsIdInvalid(final String testKey) { - VCFHeaderLine.validateKeyOrID(testKey, "test"); + Assert.assertTrue(VCFHeaderLine.validateAttributeName(testKey, "test").isPresent()); } @DataProvider(name = "vcfVersions") @@ -120,7 +120,7 @@ public Object[][] vcfVersions() { @Test(dataProvider = "vcfVersions") public void testValidateForVersion(final VCFHeaderVersion vcfVersion) { VCFHeaderLine headerLine = new VCFHeaderLine(vcfVersion.getFormatString(), vcfVersion.getVersionString()); - headerLine.validateForVersion(vcfVersion); + headerLine.validateForVersionOrThrow(vcfVersion); } @DataProvider(name = "incompatibleVersions") @@ -139,7 +139,7 @@ public Object[][] incompatibleVersionPairs() { @Test(dataProvider="incompatibleVersions", expectedExceptions= TribbleException.VersionValidationFailure.class) public void testValidateForVersionFails(final VCFHeaderVersion vcfVersion, final VCFHeaderVersion incompatibleVersion) { VCFHeaderLine headerLine = new VCFHeaderLine(vcfVersion.getFormatString(), vcfVersion.getVersionString()); - headerLine.validateForVersion(incompatibleVersion); + headerLine.validateForVersionOrThrow(incompatibleVersion); } @Test(expectedExceptions = { TribbleException.InvalidHeader.class }, expectedExceptionsMessageRegExp = ".*For fixed count, the count number must be 1 or higher.") diff --git a/src/test/java/htsjdk/variant/vcf/VCFInfoHeaderLineUnitTest.java b/src/test/java/htsjdk/variant/vcf/VCFInfoHeaderLineUnitTest.java index 9e2a82f15a..dc556a2315 100644 --- a/src/test/java/htsjdk/variant/vcf/VCFInfoHeaderLineUnitTest.java +++ b/src/test/java/htsjdk/variant/vcf/VCFInfoHeaderLineUnitTest.java @@ -70,7 +70,7 @@ public void testAllow1000GKey() { ); // TODO change to VCFHeader.DEFAULT_VCF_VERSION - Assert.assertFalse(line.getValidationFailure(VCFHeaderVersion.VCF4_3).isPresent()); + Assert.assertFalse(line.validateForVersion(VCFHeaderVersion.VCF4_3).isPresent()); } @Test(dataProvider = "mergeIncompatibleInfoLines", expectedExceptions= TribbleException.class)