@Test public void test_should_throw_exception_when_date_format_is_invalid() { final DateAttributeValidator validator = new DateAttributeValidator(); final ServiceRequest serviceRequest = mock(ServiceRequest.class); when(serviceRequest.getAttributeWithKey("date1")) .thenReturn(new AttributeEntry("date1", "07-30-2017")); final AttributeDefinition attributeDefinition = AttributeDefinition.builder() .dataType(AttributeDataType.DATE) .code("date1") .build(); final ServiceDefinition serviceDefinition = ServiceDefinition.builder() .attributes(Collections.singletonList(attributeDefinition)) .build(); try { validator.validate(serviceRequest, serviceDefinition, ServiceStatus.CITIZEN_SERVICE_APPROVED); Assert.fail("Expected exception to be thrown"); } catch (InvalidDateAttributeEntryException ex) { assertEquals("date1", ex.getAttributeCode()); } }
@Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> nonComputedDateAttributes = serviceDefinition.getNonComputedDateAttributes(); if (CollectionUtils.isEmpty(nonComputedDateAttributes)) { return; } nonComputedDateAttributes.forEach(attributeDefinition -> { final AttributeEntry matchingDateAttributeEntry = serviceRequest .getAttributeWithKey(attributeDefinition.getCode()); if(matchingDateAttributeEntry == null || isEmpty(matchingDateAttributeEntry.getCode())) { return; } validateDateFormat(matchingDateAttributeEntry); }); }
DateAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> nonComputedDateAttributes = serviceDefinition.getNonComputedDateAttributes(); if (CollectionUtils.isEmpty(nonComputedDateAttributes)) { return; } nonComputedDateAttributes.forEach(attributeDefinition -> { final AttributeEntry matchingDateAttributeEntry = serviceRequest .getAttributeWithKey(attributeDefinition.getCode()); if(matchingDateAttributeEntry == null || isEmpty(matchingDateAttributeEntry.getCode())) { return; } validateDateFormat(matchingDateAttributeEntry); }); } }
DateAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> nonComputedDateAttributes = serviceDefinition.getNonComputedDateAttributes(); if (CollectionUtils.isEmpty(nonComputedDateAttributes)) { return; } nonComputedDateAttributes.forEach(attributeDefinition -> { final AttributeEntry matchingDateAttributeEntry = serviceRequest .getAttributeWithKey(attributeDefinition.getCode()); if(matchingDateAttributeEntry == null || isEmpty(matchingDateAttributeEntry.getCode())) { return; } validateDateFormat(matchingDateAttributeEntry); }); }  }
DateAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> nonComputedDateAttributes = serviceDefinition.getNonComputedDateAttributes(); if (CollectionUtils.isEmpty(nonComputedDateAttributes)) { return; } nonComputedDateAttributes.forEach(attributeDefinition -> { final AttributeEntry matchingDateAttributeEntry = serviceRequest .getAttributeWithKey(attributeDefinition.getCode()); if(matchingDateAttributeEntry == null || isEmpty(matchingDateAttributeEntry.getCode())) { return; } validateDateFormat(matchingDateAttributeEntry); }); }  @Override void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action); }
DateAttributeValidator implements AttributeValueValidator { @Override public void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action) { final List<AttributeDefinition> nonComputedDateAttributes = serviceDefinition.getNonComputedDateAttributes(); if (CollectionUtils.isEmpty(nonComputedDateAttributes)) { return; } nonComputedDateAttributes.forEach(attributeDefinition -> { final AttributeEntry matchingDateAttributeEntry = serviceRequest .getAttributeWithKey(attributeDefinition.getCode()); if(matchingDateAttributeEntry == null || isEmpty(matchingDateAttributeEntry.getCode())) { return; } validateDateFormat(matchingDateAttributeEntry); }); }  @Override void validate(ServiceRequest serviceRequest, ServiceDefinition serviceDefinition, ServiceStatus action);  }