diff --git a/src/main/java/gov/nasa/pds/tools/validate/ProblemType.java b/src/main/java/gov/nasa/pds/tools/validate/ProblemType.java index f33429b71..2855fa91c 100644 --- a/src/main/java/gov/nasa/pds/tools/validate/ProblemType.java +++ b/src/main/java/gov/nasa/pds/tools/validate/ProblemType.java @@ -144,7 +144,7 @@ public enum ProblemType { FIELD_VALUE_OUT_OF_MIN_MAX_RANGE("error.table.field_value_out_of_min_max_range"), FIELD_VALUE_OUT_OF_SPECIAL_CONSTANT_MIN_MAX_RANGE("warning.table.field_value_out_of_special_constant_min_max_range"), - FIELD_VALUE_TOO_LONG("error.table.field_value_too_long"), + FIELD_VALID_TOO_LONG("error.table.field_value_too_long"), FIELD_VALUE_DATA_TYPE_MISMATCH("error.table.field_value_data_type_mismatch"), @@ -154,13 +154,13 @@ public enum ProblemType { FIELD_VALUE_NOT_A_NUMBER("error.table.field_value_not_a_number"), - FIELD_VALUE_NOT_RIGHT_JUSTIFIED("error.table.field_value_not_right_justified"), + FIELD_VALID_NOT_RIGHT_JUSTIFIED("error.table.field_value_not_right_justified"), - FIELD_VALUE_NOT_LEFT_JUSTIFIED("error.table.field_value_not_left_justified"), + FIELD_VALID_NOT_LEFT_JUSTIFIED("error.table.field_value_not_left_justified"), - FIELD_VALUE_FORMAT_SPECIFIER_MISMATCH("error.table.field_value_format_specifier_mismatch"), + FIELD_VALID_FORMAT_SPECIFIER_MISMATCH("error.table.field_value_format_specifier_mismatch"), - FIELD_VALUE_FORMAT_PRECISION_MISMATCH("error.table.field_value_format_precision_mismatch"), + FIELD_VALID_FORMAT_PRECISION_MISMATCH("error.table.field_value_format_precision_mismatch"), LOCAL_IDENTIFIER_NOT_FOUND("error.label.local_identifier_not_found"), @@ -170,6 +170,15 @@ public enum ProblemType { // Warning message types + FIELD_VALUE_TOO_LONG("warning.table.field_value_too_long"), + FIELD_VALUE_NOT_RIGHT_JUSTIFIED("warning.table.field_value_not_right_justified"), + + FIELD_VALUE_NOT_LEFT_JUSTIFIED("warning.table.field_value_not_left_justified"), + + FIELD_VALUE_FORMAT_SPECIFIER_MISMATCH("warning.table.field_value_format_specifier_mismatch"), + + FIELD_VALUE_FORMAT_PRECISION_MISMATCH("warning.table.field_value_format_precision_mismatch"), + DATA_OBJECTS_OUT_OF_ORDER("warning.data_objects.out_of_order"), SCHEMA_WARNING("warning.label.schema"), diff --git a/src/main/java/gov/nasa/pds/tools/validate/content/table/FieldValueValidator.java b/src/main/java/gov/nasa/pds/tools/validate/content/table/FieldValueValidator.java index b032733d9..3ce2b0e2a 100644 --- a/src/main/java/gov/nasa/pds/tools/validate/content/table/FieldValueValidator.java +++ b/src/main/java/gov/nasa/pds/tools/validate/content/table/FieldValueValidator.java @@ -256,7 +256,7 @@ public void validate(TableRecord record, FieldDescription[] fields, boolean chec String message = "The length of the value '" + value.trim() + "' exceeds the defined max field length (expected max " + fields[i].getMaxLength() + ", got " + value.trim().length() + ")"; - addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_TOO_LONG, message, + addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALID_TOO_LONG, message, record.getLocation(), (i + 1)); } } @@ -361,14 +361,17 @@ public void validate(TableRecord record, FieldDescription[] fields, boolean chec // Due to CCB-214, the tool should validate against the // validation_format field for Character Tables. if (record instanceof FixedTableRecord && (!fields[i].getValidationFormat().isEmpty() || !fields[i].getFieldFormat().isEmpty())) { + boolean asError = true; String format = fields[i].getValidationFormat(); - if (format.isEmpty()) + if (format.isEmpty()) { + asError = false; format = fields[i].getFieldFormat(); + } - checkFormat(value, format, i + 1, record.getLocation()); + checkFormat(value, format, i + 1, record.getLocation(), asError); } if (record instanceof DelimitedTableRecord && !fields[i].getFieldFormat().isEmpty()) { - checkFormat(value, fields[i].getFieldFormat(), i + 1, record.getLocation()); + checkFormat(value, fields[i].getFieldFormat(), i + 1, record.getLocation(), false); } } // Check that the field value is within the defined min/max values @@ -768,8 +771,7 @@ private void checkType(String value, FieldType type) throws InvalidTableExceptio * @param fieldIndex Where the field value is located. * @param recordLocation The record location where the field is located. */ - private void checkFormat(String value, String format, int fieldIndex, - RecordLocation recordLocation) { + private void checkFormat(String value, String format, int fieldIndex, RecordLocation recordLocation, boolean asError) { Matcher matcher = formatPattern.matcher(format); int precision = -1; boolean isValid = true; @@ -784,13 +786,15 @@ private void checkFormat(String value, String format, int fieldIndex, if ("+".equals(justified)) { // check if there is trailing whitespace if (trailingWhiteSpacePattern.matcher(value).matches()) { - addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_NOT_RIGHT_JUSTIFIED, + addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING, + asError ? ProblemType.FIELD_VALID_NOT_RIGHT_JUSTIFIED : ProblemType.FIELD_VALUE_NOT_RIGHT_JUSTIFIED, "The value '" + value + "' is not right-justified.", recordLocation, fieldIndex); isValid = false; } } else if ("-".equals(justified)) { if (leadingWhiteSpacePattern.matcher(value).matches()) { - addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_NOT_LEFT_JUSTIFIED, + addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING, + asError ? ProblemType.FIELD_VALID_NOT_LEFT_JUSTIFIED : ProblemType.FIELD_VALUE_NOT_LEFT_JUSTIFIED, "The value '" + value + "' is not left-justified.", recordLocation, fieldIndex); isValid = false; } @@ -823,13 +827,15 @@ private void checkFormat(String value, String format, int fieldIndex, } } } catch (NumberFormatException e) { - addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_FORMAT_SPECIFIER_MISMATCH, + addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING, + asError ? ProblemType.FIELD_VALID_FORMAT_SPECIFIER_MISMATCH : ProblemType.FIELD_VALUE_FORMAT_SPECIFIER_MISMATCH, "The value '" + value.trim() + "' does not match the " + "defined field format specifier '" + specifier + "': " + e.getMessage(), recordLocation, fieldIndex); } if (value.trim().length() > width) { - addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_TOO_LONG, + addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING, + asError ? ProblemType.FIELD_VALID_TOO_LONG : ProblemType.FIELD_VALUE_TOO_LONG, "The length of the value '" + value.trim() + "' exceeds the max " + "width set in the defined field format " + "(max " + width + ", got " + value.trim().length() + ").", @@ -849,9 +855,10 @@ private void checkFormat(String value, String format, int fieldIndex, } if (actual_precision > precision) { isValid = false; - addTableProblem(ExceptionType.ERROR, ProblemType.FIELD_VALUE_FORMAT_PRECISION_MISMATCH, + addTableProblem(asError ? ExceptionType.ERROR : ExceptionType.WARNING, + asError ? ProblemType.FIELD_VALID_FORMAT_PRECISION_MISMATCH : ProblemType.FIELD_VALUE_FORMAT_PRECISION_MISMATCH, "The number of digits to the right of the decimal point " + "in the value '" - + value.trim() + "' must be <= the precision set in the defined field format '" + + value.trim() + "' should be <= the precision set in the defined field format '" + format+ "' (Expected: <=" + precision + ", Actual: " + actual_precision + ").", recordLocation, fieldIndex); } diff --git a/src/test/java/cucumber/StepDefs.java b/src/test/java/cucumber/StepDefs.java index b0cb85384..220d5e25d 100644 --- a/src/test/java/cucumber/StepDefs.java +++ b/src/test/java/cucumber/StepDefs.java @@ -278,25 +278,25 @@ public void execute_a_validate_command() { } } - @Then("produced output from validate command should be similiar to reference {string} or no error reported.") - public void produced_output_from_validate_command_should_be_similiar_to_reference_ref_output_value_or_no_error_reported( + @Then("produced output from validate command should be similar to reference {string} or no error reported.") + public void produced_output_from_validate_command_should_be_similar_to_reference_ref_output_value_or_no_error_reported( String refOutputValue) { this.refOutputValue = refOutputValue; - // System.out.println("produced_output_from_validate_command_should_be_similiar_to_reference_ref_output_value_or_no_error_reported:this.testName + // System.out.println("produced_output_from_validate_command_should_be_similar_to_reference_ref_output_value_or_no_error_reported:this.testName // = " + this.testName); - // System.out.println("produced_output_from_validate_command_should_be_similiar_to_reference_ref_output_value_or_no_error_reported:this.testDir + // System.out.println("produced_output_from_validate_command_should_be_similar_to_reference_ref_output_value_or_no_error_reported:this.testDir // = " + this.testDir); - // System.out.println("produced_output_from_validate_command_should_be_similiar_to_reference_ref_output_value_or_no_error_reported:this.commandArgs + // System.out.println("produced_output_from_validate_command_should_be_similar_to_reference_ref_output_value_or_no_error_reported:this.commandArgs // = " + this.commandArgs); StepDefs.LOG.info( - "produced_output_from_validate_command_should_be_similiar_to_reference_ref_output_value_or_no_error_reported:this.refOutputValue = " + "produced_output_from_validate_command_should_be_similar_to_reference_ref_output_value_or_no_error_reported:this.refOutputValue = " + this.refOutputValue); try { Gson gson = new Gson(); File report = new File(this.reportDir + File.separator + this.refOutputValue); StepDefs.LOG.info( - "produced_output_from_validate_command_should_be_similiar_to_reference_ref_output_value_or_no_error_reported:report = [" + "produced_output_from_validate_command_should_be_similar_to_reference_ref_output_value_or_no_error_reported:report = [" + report.getName() + "]"); JsonObject reportJson = gson.fromJson(new FileReader(report), JsonObject.class); @@ -305,16 +305,16 @@ public void produced_output_from_validate_command_should_be_similiar_to_referenc int count = this.getMessageCountBasedOnProblemType(this.problemEnum, reportJson); StepDefs.LOG.debug( - "produced_output_from_validate_command_should_be_similiar_to_reference_ref_output_value_or_no_error_reported:testName,problemEnum,count,refOutputValue: " + "produced_output_from_validate_command_should_be_similar_to_reference_ref_output_value_or_no_error_reported:testName,problemEnum,count,refOutputValue: " + this.testName + " " + problemEnum + " " + Integer.toString(count) + " " + this.refOutputValue); // Compare the count from this test with the this.messageCount from test table. assertEquals(count, this.messageCount, this.messageText + " " + reportJson.toString()); - // System.out.println("produced_output_from_validate_command_should_be_similiar_to_reference_ref_output_value_or_no_error_reported() + // System.out.println("produced_output_from_validate_command_should_be_similar_to_reference_ref_output_value_or_no_error_reported() // count = [" + count + "]"); - // System.out.println("produced_output_from_validate_command_should_be_similiar_to_reference_ref_output_value_or_no_error_reported() + // System.out.println("produced_output_from_validate_command_should_be_similar_to_reference_ref_output_value_or_no_error_reported() // reportJson.toString() = [" + reportJson.toString() + "]"); } catch (ExitException e) { assertEquals(0, e.status, "Exit status"); diff --git a/src/test/resources/features/developer.feature b/src/test/resources/features/developer.feature index d5c613744..d0cdf6fbd 100644 --- a/src/test/resources/features/developer.feature +++ b/src/test/resources/features/developer.feature @@ -4,7 +4,7 @@ Scenario Outline: Execute validate command for tests below. Given a test at dir at resource sending report to with as arguments When with test property count text problem reference When execute a validate command - Then produced output from validate command should be similiar to reference or no error reported. + Then produced output from validate command should be similar to reference or no error reported. Examples: | testName | testDir | messageCount | messageText | problemEnum | resourceDir | reportDir | commandArgs | refOutputValue | @@ -24,6 +24,9 @@ Scenario Outline: Execute validate command for tests below. # Validate#823 |"NASA-PDS/validate#823 Success process problematic floats" | "github823" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github823.json -s json --skip-context-validation -t {resourceDir}/github823/mvn_swi_l2_onboardsvymom_20230827_v02_r01.xml" | "report_github823.json" | +# Validate#817 +|"NASA-PDS/validate#817 Failure of ASCII table invalid precision" | "github681" | 1 | "1 error expected" | "FIELD_VALID_FORMAT_PRECISION_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github817_1.json -s json -t {resourceDir}/github681/ff_char_fail.xml" | "report_github817_1.json" | + # Validate#785 |"NASA-PDS/validate#785 Success detecting out of range values" | "github785" | 6 | "6 warnings expected" | "FIELD_VALUE_OUT_OF_SPECIAL_CONSTANT_MIN_MAX_RANGE" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github785.json -s json --skip-context-validation -t {resourceDir}/github785/00038_FGM_RTN.xml" | "report_github785.json" | @@ -42,14 +45,6 @@ Scenario Outline: Execute validate command for tests below. # Validate#690 |"NASA-PDS/validate#690 Success new constant expression" | "github690" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github690.json -s json --skip-context-validation -t {resourceDir}/github690/rs_20160518_014000_udsc64_l3_e_v10.xml" | "report_github690.json" | -# Validate#681 -|"NASA-PDS/validate#681 Success ASCII table with extra whitespace, valid precision" | "github681" | 0 | "0 errors expected" | "FIELD_VALUE_FORMAT_PRECISION_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github681_1.json -s json -t {resourceDir}/github681/ff_char.xml {resourceDir}/github681/ff_del.xml" | "report_github681_1.json" | -|"NASA-PDS/validate#681 Failure of ASCII table invalid precision" | "github681" | 2 | "2 errors expected" | "FIELD_VALUE_FORMAT_PRECISION_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github681_2.json -s json -t {resourceDir}/github681/ff_char_fail.xml {resourceDir}/github681/ff_del_fail.xml" | "report_github681_2.json" | - -# Validate#680 -|"NASA-PDS/validate#680 Success char table correct length" | "github680" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github680.1.json -s json --skip-context-validation -t {resourceDir}/github680/ORB12_EUR_EPHIO_reclen96.xml" | "report_github680.1.json" | -|"NASA-PDS/validate#680 Failure char table bad length" | "github680" | 1 | "1 errors expected" | "RECORD_LENGTH_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github680.2.json -s json --skip-context-validation -t {resourceDir}/github680/ORB12_EUR_EPHIO_reclen95.xml" | "report_github680.2.json" | - # Validate#684 |"NASA-PDS/validate#684 Success without filesize" | "github684" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github684_1.json -s json --skip-context-validation -t {resourceDir}/github684/example_params_noFileSize.xml" | "report_github684_1.json" | |"NASA-PDS/validate#684 Success with filesize" | "github684" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github684_2.json -s json --skip-context-validation -t {resourceDir}/github684/example_params_wFileSize.xml" | "report_github684_2.json" | @@ -57,6 +52,15 @@ Scenario Outline: Execute validate command for tests below. # Validate#683 |"NASA-PDS/validate#683 Success warn out of order offsets" | "github614" | 1 | "1 warnings expected" | "DATA_OBJECTS_OUT_OF_ORDER" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github683.json -s json -t {resourceDir}/github614/ss__0505_0711794861_465rmo__0261222srlc10000w0__cgnj02.xml" | "report_github683.json" | +# Validate#681 +|"NASA-PDS/validate#681 Success ASCII table with extra whitespace, valid precision" | "github681" | 0 | "0 errors expected" | "FIELD_VALUE_FORMAT_PRECISION_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github681_1.json -s json -t {resourceDir}/github681/ff_char.xml {resourceDir}/github681/ff_del.xml" | "report_github681_1.json" | +|"NASA-PDS/validate#681 Failure of ASCII table invalid precision" | "github681" | 1 | "1 errors expected" | "FIELD_VALID_FORMAT_PRECISION_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github681_2.json -s json -t {resourceDir}/github681/ff_char_fail.xml" | "report_github681_2.json" | +|"NASA-PDS/validate#681 Warning ASCII tables" | "github681" | 2 | "2 warnings expected" | "FIELD_VALUE_FORMAT_PRECISION_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github681_3.json -s json -t {resourceDir}/github681/ff_char_warn.xml {resourceDir}/github681/ff_del_warn.xml" | "report_github681_3.json" | + +# Validate#680 +|"NASA-PDS/validate#680 Success char table correct length" | "github680" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github680.1.json -s json --skip-context-validation -t {resourceDir}/github680/ORB12_EUR_EPHIO_reclen96.xml" | "report_github680.1.json" | +|"NASA-PDS/validate#680 Failure char table bad length" | "github680" | 1 | "1 errors expected" | "RECORD_LENGTH_MISMATCH" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github680.2.json -s json --skip-context-validation -t {resourceDir}/github680/ORB12_EUR_EPHIO_reclen95.xml" | "report_github680.2.json" | + # Validate#671 |"NASA-PDS/validate#671 Success processing of bundle" | "github671" | 0 | "0 errors expected" | "totalErrors" | "src/test/resources" | "target/test" | "-r {reportDir}/report_github671.json -s json --skip-context-validation -t {resourceDir}/github671 -R pds4.bundle" | "report_github671.json" | diff --git a/src/test/resources/features/integration.feature b/src/test/resources/features/integration.feature index 7f67e4e3d..f35a76a2f 100644 --- a/src/test/resources/features/integration.feature +++ b/src/test/resources/features/integration.feature @@ -4,7 +4,7 @@ Scenario Outline: Execute validate command for tests below. Given a test at dir at resource sending report to with as arguments When with test property count text problem reference When execute a validate command - Then produced output from validate command should be similiar to reference or no error reported. + Then produced output from validate command should be similar to reference or no error reported. Examples: | testName | testDir | messageCount | messageText | problemEnum | resourceDir | reportDir | commandArgs | refOutputValue | diff --git a/src/test/resources/features/sanity.py b/src/test/resources/features/sanity.py new file mode 100755 index 000000000..505a52b59 --- /dev/null +++ b/src/test/resources/features/sanity.py @@ -0,0 +1,22 @@ +#! /usr/bin/env python3 + +import sys + +for fn in sys.argv[1:]: + print (fn) + with open(fn,'rt') as file: lines = file.readlines() + for index,line in enumerate(lines): + line = line.strip() + line_test = [line.startswith('|'), line.endswith('|')] + if line.startswith ('#'): continue + if any(line_test): + if not all(line_test): + print (f'{fn}:{index}: does not start or end with "|"', line) + if line.count('|') != 10: + print (f'{fn}:{index}: has wrong number of "|"', line) + if line.count('"') & 1: + print (f'{fn}:{index}: contains an odd number of quotes', line) + for seg in line.split('|'): + if seg.count('"') & 1: + print (f'{fn}:{index}: segement not properly quoted', line) + break diff --git a/src/test/resources/github681/ff_char_fail.xml b/src/test/resources/github681/ff_char_fail.xml index 3854b0bfd..e021f1490 100644 --- a/src/test/resources/github681/ff_char_fail.xml +++ b/src/test/resources/github681/ff_char_fail.xml @@ -59,6 +59,7 @@ ASCII_Real 4 %4.2f + %4.2f field 3 diff --git a/src/test/resources/github681/ff_char_warn.xml b/src/test/resources/github681/ff_char_warn.xml new file mode 100644 index 000000000..3854b0bfd --- /dev/null +++ b/src/test/resources/github681/ff_char_warn.xml @@ -0,0 +1,74 @@ + + + + + urn:nasa:pds:bundle:collection:ff_char_test + 1.0 + Field Format Character Test + 1.20.0.0 + Product_Observational + + + + 2023Z + 2023Z + + + None + Other Investigation + + urn:nasa:pds:context:investigation:individual.none + data_to_investigation + + + + + telescope + Instrument + + + + target + Comet + + + + + ff_test_fail.csv + + + 0 + 3 + Carriage-Return Line-Feed + + 3 + 0 + 22 + + field 1 + 1 + 1 + ASCII_Real + 6 + %6.2f + + + field 2 + 2 + 8 + ASCII_Real + 4 + %4.2f + + + field 3 + 3 + 13 + ASCII_Real + 8 + %8.3e + + + + + diff --git a/src/test/resources/github681/ff_del_fail.xml b/src/test/resources/github681/ff_del_warn.xml similarity index 100% rename from src/test/resources/github681/ff_del_fail.xml rename to src/test/resources/github681/ff_del_warn.xml