Skip to content

Commit

Permalink
Merge pull request #2423 from hmcts/CCD-5480
Browse files Browse the repository at this point in the history
CCD-5480 Fix Document validation error - upload_timestamp regex
  • Loading branch information
RebeccaBaker authored Jun 4, 2024
2 parents 05e1a56 + aa185ab commit 6af16e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import uk.gov.hmcts.ccd.data.definition.CachedCaseDefinitionRepository;
import uk.gov.hmcts.ccd.data.definition.CaseDefinitionRepository;
import uk.gov.hmcts.ccd.domain.model.definition.CaseFieldDefinition;
import uk.gov.hmcts.ccd.domain.model.definition.FieldTypeDefinition;

import javax.inject.Named;
import javax.inject.Singleton;
Expand Down Expand Up @@ -104,7 +105,7 @@ public List<ValidationResult> validate(final String dataFieldId,

if (dataValue.has(UPLOAD_TIMESTAMP)) {
final JsonNode uploadTimeStamp = dataValue.get(UPLOAD_TIMESTAMP);
validationResults = validateUploadTimeStamp(dataFieldId,uploadTimeStamp,caseFieldDefinition);
validationResults = validateUploadTimeStamp(dataFieldId, uploadTimeStamp);
if (!validationResults.isEmpty()) {
return validationResults;
}
Expand Down Expand Up @@ -154,16 +155,18 @@ private List<ValidationResult> validateCategoryId(final String dataFieldId,
}

private List<ValidationResult> validateUploadTimeStamp(final String dataFieldId,
final JsonNode uploadTimeStamp,
final CaseFieldDefinition caseFieldDefinition) {
final JsonNode uploadTimeStamp) {

if (isNullOrEmpty(uploadTimeStamp)) {
LOG.debug("{}{}",UPLOAD_TIMESTAMP,NOT_TEXT_OR_NULL);
return Collections.emptyList();
}

CaseFieldDefinition emptyCaseFieldDefinition = new CaseFieldDefinition();
emptyCaseFieldDefinition.setFieldTypeDefinition(new FieldTypeDefinition());

List<ValidationResult> validationResults =
dateTimeValidator.validate(dataFieldId, uploadTimeStamp, caseFieldDefinition);
dateTimeValidator.validate(dataFieldId, uploadTimeStamp, emptyCaseFieldDefinition);
if (!validationResults.isEmpty()) {
return validationResult(UPLOAD_TIMESTAMP,validationResults);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,23 @@ void setUp() {
@Nested
@DisplayName("when valid datetime")
class WhenValidDateTime {

@Test
@DisplayName("should validate date time: 2012-04-21T00:00:00.000000000 even with empty caseFieldDefinition")
void emptyCaseFieldDefinition() {
CaseFieldDefinition caseFieldDefinition = new CaseFieldDefinition();
caseFieldDefinition.setFieldTypeDefinition(new FieldTypeDefinition());

assertEquals(0, validator.validate(FIELD_ID, NODE_FACTORY.textNode("2012-04-21T00:00:00.000000000"),
caseFieldDefinition).size());
}

@Test
@DisplayName("should validate date time: 2012-04-21T00:00:00.000")
void shouldValidateDateTimeWithoutTimeZone() {
final List<ValidationResult> results = validator.validate(FIELD_ID,
NODE_FACTORY.textNode("2012-04-21T00:00:00.000"),
caseFieldDefinition);
NODE_FACTORY.textNode("2012-04-21T00:00:00.000"),
caseFieldDefinition);
assertThat(results, hasSize(0));
}

Expand Down Expand Up @@ -104,6 +115,18 @@ void shouldValidateDateTimeLeapYear() {
@Nested
@DisplayName("when invalid datetime")
class WhenInvalidDateTime {

@Test
@DisplayName("should not validate date time: 3321M1 1AA even with empty caseFieldDefinition")
void emptyCaseFieldDefinition() {
CaseFieldDefinition caseFieldDefinition = new CaseFieldDefinition();
caseFieldDefinition.setFieldTypeDefinition(new FieldTypeDefinition());

assertEquals(1, validator.validate(FIELD_ID, NODE_FACTORY.textNode("3321M1 1AA"),
caseFieldDefinition).size());
}


@Test
@DisplayName("should not validate date time: 3321M1 1AA")
void shouldNotValidateNotDateTime() {
Expand Down Expand Up @@ -283,7 +306,6 @@ void invalidBaseTypeRegEx() {
assertEquals(FIELD_ID, result.get(0).getFieldId());
}


@Test
void validRegEx() {
final String validDateTime = "2001-12-10T00:00:00";
Expand Down

0 comments on commit 6af16e7

Please sign in to comment.