From 5247e6a4bb2ceb4d648e7606a51bef3185c548f8 Mon Sep 17 00:00:00 2001 From: chicoreus Date: Fri, 11 Mar 2022 16:52:40 -0500 Subject: [PATCH] ISSUE: MCZ Redmine 866 tdwg/bdq#130 tdwg/bdq#147 PURPOSE: Updating tests to current specifications. DESCRIPTION: Updating implementation of VALIDATION_STARTDAYOFYEAR_OUTOFRANGE to updated (2022-03-10) specification, adding and fixing unit tests to confirm with current specification. Removing instead of deprecating and using as wrapper previous startDayOfYearInRangeForYear() method, as it takes year instead of eventDate and can't conform to the current standard. Updating implementation and fixing unit tests for VALIDATION_DAY_NOTSTANDARD to conform with current specification. --- .../org/filteredpush/qc/date/DwCEventDQ.java | 77 +++++++++---- .../qc/date/DwCEventDQTestDefinitions.java | 108 ++++++++++++++++-- .../filteredpush/qc/date/DwcEventDQTest.java | 24 ++-- 3 files changed, 170 insertions(+), 39 deletions(-) diff --git a/src/main/java/org/filteredpush/qc/date/DwCEventDQ.java b/src/main/java/org/filteredpush/qc/date/DwCEventDQ.java index d599a9a..c667253 100644 --- a/src/main/java/org/filteredpush/qc/date/DwCEventDQ.java +++ b/src/main/java/org/filteredpush/qc/date/DwCEventDQ.java @@ -673,10 +673,11 @@ public static DQResponse correctEventDateFormat(@ActedUpon(value } /** - * #147 Validation SingleRecord Conformance: day notstandard * * Test to see whether a provided day is an integer in the range of values that can be * a day of a month. + * + * #147 Validation SingleRecord Conformance: day notstandard * * Provides: VALIDATION_DAY_NOTSTANDARD * @@ -691,14 +692,13 @@ public static DQResponse validationDayNotstandard(@ActedUpon("d DQResponse result = new DQResponse(); // Specification - // INTERNAL_PREREQUISITES_NOT_MET if dwc:day is EMPTY; COMPLIANT - // if the value of the field dwc:day is an integer between - // 1 and 31 inclusive; otherwise NOT_COMPLIANT. + // INTERNAL_PREREQUISITES_NOT_MET if dwc:day is EMPTY; COMPLIANT + // if the value of the field dwc:day is an integer between + // 1 and 31 inclusive; otherwise NOT_COMPLIANT. if (DateUtils.isEmpty(day)) { result.addComment("No value provided for day."); - result.setValue(ComplianceValue.NOT_COMPLIANT); - result.setResultState(ResultState.RUN_HAS_RESULT); + result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); } else { try { int numericDay = Integer.parseInt(day.trim()); @@ -978,20 +978,52 @@ public static final DQResponse dayMonthTransposition(@ActedUpon( } /** - * Given a year and an start day of a date range in days of the year, test whether or not - * the value for startDayOfYear is in range for the days in that year (1-365, or 366 in leap year). + * #130 Validation SingleRecord Conformance: startdayofyear outofrange + * + * Given an eventDate and an start day of a date range in days of the year, test whether or not + * the value for startDayOfYear is in range for the days in the end year of the eventDate + * (day is 1-365, or 366 in leap year). * - * TG2-VALIDATION_STARTDAYOFYEAR_OUTOFRANGE + * Provides: VALIDATION_STARTDAYOFYEAR_OUTOFRANGE * - * @param startDay startDayOfYearto check - * @param year to check for leap year - * @return an DQValidationResponse object describing whether the date year-startDayOfYear exists. + * @param startDayOfYear the provided dwc:startDayOfYear to evaluate + * @param eventDate the provided dwc:eventDate to evaluate + * @return DQResponse the response of type ComplianceValue to return */ - @Provides(value="urn:uuid:85803c7e-2a5a-42e1-b8d3-299a44cafc46") - @Validation( label = "VALIDATION_STARTDAYOFYEAR_OUTOFRANGE", description="The value of dwc:startDayOfYear is a valid day given the year.") - @Specification(value="The value of dwc:startDayOfYear is a valid day given the year. The value of dwc:startDayOfYear is a number. If present dwc:year must be an integer. This test should be run after the test TG2-AMENDMENT_EVENT_FROM_EVENTDATE (#52)") - public static final DQResponse startDayOfYearInRangeForYear(@ActedUpon(value="dwc:startDayOfYear") String startDay, @Consulted(value="dwc:year")String year) { + @Provides("85803c7e-2a5a-42e1-b8d3-299a44cafc46") + public static final DQResponse validationStartdayofyearOutofrange( + @ActedUpon(value="dwc:startDayOfYear") String startDay, + @Consulted(value="dwc:eventDate")String eventDate) { DQResponse result = new DQResponse(); + + // Specification + // INTERNAL_PREREQUISITES_NOT_MET if dwc:startDayOfYear is + // EMPTY or if the value of dwc:startDayOfYear is equal to + // 366 and (dwc:eventDate is EMPTY or the value of dwc:eventDate + // can not be interpreted to find single year or a start year + // in a range); COMPLIANT if the value of dwc:startDayOfYear + // is an integer between 1 and 365, inclusive, or if the value + // of dwc:startDayOfYear is 366 and the start year interpreted + // from dwc:eventDate is a leap year; otherwise NOT_COMPLIANT + // + + String year = ""; + + boolean eventDateParseFailure = false; + if (!DateUtils.isEmpty(eventDate)) { + try { + Integer startYearInt = new LocalDateInterval(eventDate).getStartDate().getYear(); + year = Integer.toString(startYearInt); + } catch (DateTimeParseException | EmptyDateException e1) { + logger.debug(e1.getMessage()); + eventDateParseFailure = true; + } + } + + logger.debug(startDay); + logger.debug(eventDate); + logger.debug(year); + if (DateUtils.isEmpty(startDay)) { result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); result.addComment("startDayOfYear was not provided."); @@ -1005,7 +1037,11 @@ public static final DQResponse startDayOfYearInRangeForYear(@Ac } else if (numericStartDay==366) { if (DateUtils.isEmpty(year)) { result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); - result.addComment("year was not provided and day is 366, could be valid in a leap year."); + if (eventDateParseFailure) { + result.addComment("unable to extract year from provided eventDate and day is 366, could be valid in a leap year."); + } else { + result.addComment("year was not provided and day is 366, could be valid in a leap year."); + } } else { String potentialDay = DateUtils.createEventDateFromParts("", startDay, "", year, "", ""); if (DateUtils.isEmpty(potentialDay)) { @@ -1028,7 +1064,8 @@ public static final DQResponse startDayOfYearInRangeForYear(@Ac result.addComment("startDayOfYear [" + startDay + "] is out of range for days in the year."); } } catch (NumberFormatException e) { - result.setResultState(ResultState.INTERNAL_PREREQUISITES_NOT_MET); + result.setResultState(ResultState.RUN_HAS_RESULT); + result.setValue(ComplianceValue.NOT_COMPLIANT); result.addComment("startDayOfYear [" + startDay + "] is not a number."); } } @@ -1055,7 +1092,7 @@ public static final DQResponse validationEnddayofyearOutofrange @ActedUpon(value="dwc:endDayOfYear") String endDay, @Consulted(value="dwc:eventDate")String eventDate) { - //TODO: Implement specification + // Specification // INTERNAL_PREREQUISITES_NOT_MET if dwc:endDayOfYear is EMPTY // or if the value of dwc:endDayOfYear is equal to 366 and // (dwc:eventDate is EMPTY or the value of dwc:eventDate cannot @@ -1063,7 +1100,7 @@ public static final DQResponse validationEnddayofyearOutofrange // range); COMPLIANT if the value of dwc:endDayOfYear is an // integer between 1 and 365 inclusive, or if the value of // dwc:endDayOfYear is 366 and the end year interpreted from - //dwc:eventDate is a leap year; otherwise NOT_COMPLIANT + // dwc:eventDate is a leap year; otherwise NOT_COMPLIANT DQResponse result = new DQResponse(); diff --git a/src/test/java/org/filteredpush/qc/date/DwCEventDQTestDefinitions.java b/src/test/java/org/filteredpush/qc/date/DwCEventDQTestDefinitions.java index d51f4f2..a5d621d 100644 --- a/src/test/java/org/filteredpush/qc/date/DwCEventDQTestDefinitions.java +++ b/src/test/java/org/filteredpush/qc/date/DwCEventDQTestDefinitions.java @@ -369,7 +369,103 @@ public void testAmendmentMonthStandardized() { */ @Test public void testValidationStartdayofyearOutofrange() { - fail("Not yet implemented"); + + // Specification + // INTERNAL_PREREQUISITES_NOT_MET if dwc:startDayOfYear is + // EMPTY or if the value of dwc:startDayOfYear is equal to + // 366 and (dwc:eventDate is EMPTY or the value of dwc:eventDate + // can not be interpreted to find single year or a start year + // in a range); COMPLIANT if the value of dwc:startDayOfYear + // is an integer between 1 and 365, inclusive, or if the value + // of dwc:startDayOfYear is 366 and the start year interpreted + // from dwc:eventDate is a leap year; otherwise NOT_COMPLIANT + // + + + String startDayOfYear = null; + String eventDate = null; + DQResponse response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET.getLabel(), response.getResultState().getLabel()); + assertNull(response.getValue()); + logger.debug(response.getComment()); + + startDayOfYear = "366"; + eventDate = null; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET.getLabel(), response.getResultState().getLabel()); + assertNull(response.getValue()); + logger.debug(response.getComment()); + + startDayOfYear = "366"; + eventDate = "Foo"; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET.getLabel(), response.getResultState().getLabel()); + assertNull(response.getValue()); + logger.debug(response.getComment()); + + startDayOfYear = "365"; + eventDate = "Foo"; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), response.getResultState().getLabel()); + assertEquals(ComplianceValue.COMPLIANT.getLabel(), response.getValue().getLabel()); + logger.debug(response.getComment()); + + startDayOfYear = "365"; + eventDate = ""; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), response.getResultState().getLabel()); + assertEquals(ComplianceValue.COMPLIANT.getLabel(), response.getValue().getLabel()); + logger.debug(response.getComment()); + + startDayOfYear = "365"; + eventDate = "1980"; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), response.getResultState().getLabel()); + assertEquals(ComplianceValue.COMPLIANT.getLabel(), response.getValue().getLabel()); + logger.debug(response.getComment()); + + startDayOfYear = "365"; + eventDate = "1981"; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), response.getResultState().getLabel()); + assertEquals(ComplianceValue.COMPLIANT.getLabel(), response.getValue().getLabel()); + logger.debug(response.getComment()); + + startDayOfYear = "366"; + eventDate = "1980"; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), response.getResultState().getLabel()); + assertEquals(ComplianceValue.COMPLIANT.getLabel(), response.getValue().getLabel()); + logger.debug(response.getComment()); + + startDayOfYear = "366"; + eventDate = "1981"; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), response.getResultState().getLabel()); + assertEquals(ComplianceValue.NOT_COMPLIANT.getLabel(), response.getValue().getLabel()); + logger.debug(response.getComment()); + + startDayOfYear = "366"; + eventDate = "1979-01-01/1980-01-10"; // only start year is examined, not other parts of date for this test. + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), response.getResultState().getLabel()); + assertEquals(ComplianceValue.NOT_COMPLIANT.getLabel(), response.getValue().getLabel()); + logger.debug(response.getComment()); + + startDayOfYear = "366"; + eventDate = "1980-12-31/1981-12-31"; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), response.getResultState().getLabel()); + assertEquals(ComplianceValue.COMPLIANT.getLabel(), response.getValue().getLabel()); + logger.debug(response.getComment()); + + startDayOfYear = "foo"; + eventDate = "1980-12-31/1981-12-31"; + response = DwCEventDQ.validationStartdayofyearOutofrange(startDayOfYear, eventDate); + assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), response.getResultState().getLabel()); + assertEquals(ComplianceValue.NOT_COMPLIANT.getLabel(), response.getValue().getLabel()); + logger.debug(response.getComment()); + } /** @@ -637,10 +733,10 @@ public void testMeasureEventdatePrecisioninseconds() { @Test public void testValidationDayNotstandard() { - //TODO: Implement specification - // INTERNAL_PREREQUISITES_NOT_MET if dwc:day is EMPTY; COMPLIANT - // if the value of the field dwc:day is an integer between - //1 and 31 inclusive; otherwise NOT_COMPLIANT. + // Specification + // INTERNAL_PREREQUISITES_NOT_MET if dwc:day is EMPTY; COMPLIANT + // if the value of the field dwc:day is an integer between + // 1 and 31 inclusive; otherwise NOT_COMPLIANT. String day = "1"; DQResponse result = DwCEventDQ.validationDayNotstandard(day); @@ -659,9 +755,7 @@ public void testValidationDayNotstandard() { logger.debug(result.getComment()); assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET.getLabel(), result.getResultState().getLabel()); assertNull(result.getValue()); - assertEquals(ComplianceValue.COMPLIANT.getLabel(), result.getValue().getLabel()); - fail("Not yet implemented"); } } diff --git a/src/test/java/org/filteredpush/qc/date/DwcEventDQTest.java b/src/test/java/org/filteredpush/qc/date/DwcEventDQTest.java index 5a20134..2219460 100644 --- a/src/test/java/org/filteredpush/qc/date/DwcEventDQTest.java +++ b/src/test/java/org/filteredpush/qc/date/DwcEventDQTest.java @@ -150,16 +150,16 @@ public void testIsDayInRange() { assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); result = DwCEventDQ.validationDayNotstandard(null); - assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); - assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); + assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET, result.getResultState()); + assertNull(result.getValue()); result = DwCEventDQ.validationDayNotstandard(""); - assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); - assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); + assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET, result.getResultState()); + assertNull(result.getValue()); result = DwCEventDQ.validationDayNotstandard(" "); - assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); - assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); + assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET, result.getResultState()); + assertNull(result.getValue()); result = DwCEventDQ.validationDayNotstandard("A"); assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); @@ -714,7 +714,7 @@ public void testIsStartEndDayPossibleForYear() { assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); assertEquals(ComplianceValue.COMPLIANT, result.getValue()); - result = DwCEventDQ.startDayOfYearInRangeForYear(Integer.toString(day), Integer.toString(year)); + result = DwCEventDQ.validationStartdayofyearOutofrange(Integer.toString(day), Integer.toString(year)); assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); assertEquals(ComplianceValue.COMPLIANT, result.getValue()); } @@ -726,7 +726,7 @@ public void testIsStartEndDayPossibleForYear() { result = DwCEventDQ.validationEnddayofyearOutofrange(Integer.toString(day), Integer.toString(year)); assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel()); assertEquals(ComplianceValue.COMPLIANT, result.getValue()); - result = DwCEventDQ.startDayOfYearInRangeForYear(Integer.toString(day), Integer.toString(year)); + result = DwCEventDQ.validationStartdayofyearOutofrange(Integer.toString(day), Integer.toString(year)); assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); assertEquals(ComplianceValue.COMPLIANT, result.getValue()); @@ -736,7 +736,7 @@ public void testIsStartEndDayPossibleForYear() { result = DwCEventDQ.validationEnddayofyearOutofrange(Integer.toString(day), Integer.toString(year)); assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); - result = DwCEventDQ.startDayOfYearInRangeForYear(Integer.toString(day), Integer.toString(year)); + result = DwCEventDQ.validationStartdayofyearOutofrange(Integer.toString(day), Integer.toString(year)); assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); @@ -745,7 +745,7 @@ public void testIsStartEndDayPossibleForYear() { result = DwCEventDQ.validationEnddayofyearOutofrange(Integer.toString(day), Integer.toString(year)); assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); - result = DwCEventDQ.startDayOfYearInRangeForYear(Integer.toString(day), Integer.toString(year)); + result = DwCEventDQ.validationStartdayofyearOutofrange(Integer.toString(day), Integer.toString(year)); assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); @@ -754,7 +754,7 @@ public void testIsStartEndDayPossibleForYear() { result = DwCEventDQ.validationEnddayofyearOutofrange(Integer.toString(day), Integer.toString(year)); assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); - result = DwCEventDQ.startDayOfYearInRangeForYear(Integer.toString(day), Integer.toString(year)); + result = DwCEventDQ.validationStartdayofyearOutofrange(Integer.toString(day), Integer.toString(year)); assertEquals(ResultState.RUN_HAS_RESULT, result.getResultState()); assertEquals(ComplianceValue.NOT_COMPLIANT, result.getValue()); @@ -764,7 +764,7 @@ public void testIsStartEndDayPossibleForYear() { assertEquals(ResultState.INTERNAL_PREREQUISITES_NOT_MET, result.getResultState()); day = -1; - result = DwCEventDQ.startDayOfYearInRangeForYear(Integer.toString(day),""); + result = DwCEventDQ.validationStartdayofyearOutofrange(Integer.toString(day),""); assertEquals(ResultState.RUN_HAS_RESULT.getLabel(), result.getResultState().getLabel()); assertEquals(ComplianceValue.NOT_COMPLIANT.getLabel(), result.getValue().getLabel());