Skip to content

Commit

Permalink
ISSUE: MCZ Redmine 866 tdwg/bdq#130 tdwg/bdq#147 PURPOSE: Updating te…
Browse files Browse the repository at this point in the history
…sts 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.
  • Loading branch information
chicoreus committed Mar 11, 2022
1 parent 550e9ee commit 5247e6a
Show file tree
Hide file tree
Showing 3 changed files with 170 additions and 39 deletions.
77 changes: 57 additions & 20 deletions src/main/java/org/filteredpush/qc/date/DwCEventDQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,11 @@ public static DQResponse<AmendmentValue> 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
*
Expand All @@ -691,14 +692,13 @@ public static DQResponse<ComplianceValue> validationDayNotstandard(@ActedUpon("d
DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>();

// 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());
Expand Down Expand Up @@ -978,20 +978,52 @@ public static final DQResponse<AmendmentValue> 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<ComplianceValue> startDayOfYearInRangeForYear(@ActedUpon(value="dwc:startDayOfYear") String startDay, @Consulted(value="dwc:year")String year) {
@Provides("85803c7e-2a5a-42e1-b8d3-299a44cafc46")
public static final DQResponse<ComplianceValue> validationStartdayofyearOutofrange(
@ActedUpon(value="dwc:startDayOfYear") String startDay,
@Consulted(value="dwc:eventDate")String eventDate) {
DQResponse<ComplianceValue> result = new DQResponse<ComplianceValue>();

// 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.");
Expand All @@ -1005,7 +1037,11 @@ public static final DQResponse<ComplianceValue> 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)) {
Expand All @@ -1028,7 +1064,8 @@ public static final DQResponse<ComplianceValue> 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.");
}
}
Expand All @@ -1055,15 +1092,15 @@ public static final DQResponse<ComplianceValue> 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
// be interpreted to find a single year or an end year in a
// 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<ComplianceValue> result = new DQResponse<ComplianceValue>();

Expand Down
108 changes: 101 additions & 7 deletions src/test/java/org/filteredpush/qc/date/DwCEventDQTestDefinitions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComplianceValue> 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());

}

/**
Expand Down Expand Up @@ -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<ComplianceValue> result = DwCEventDQ.validationDayNotstandard(day);
Expand All @@ -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");
}

}
24 changes: 12 additions & 12 deletions src/test/java/org/filteredpush/qc/date/DwcEventDQTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());

Expand All @@ -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());

Expand All @@ -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());

Expand All @@ -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());

Expand All @@ -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());

Expand Down

0 comments on commit 5247e6a

Please sign in to comment.