Merge pull request #2776 from hapifhir/2775_address_interceptor
Address interceptor bug
This commit is contained in:
commit
3bafdd7de1
|
@ -165,6 +165,8 @@ public class AddressValidatingInterceptor {
|
|||
}
|
||||
|
||||
protected boolean validateAddress(IBase theAddress, FhirContext theFhirContext) {
|
||||
ExtensionUtil.clearExtensionsByUrl(theAddress, getExtensionUrl());
|
||||
|
||||
try {
|
||||
AddressValidationResult validationResult = getAddressValidator().isValid(theAddress, theFhirContext);
|
||||
ourLog.debug("Validated address {}", validationResult);
|
||||
|
|
|
@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
|||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.reset;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -235,6 +236,33 @@ class AddressValidatingInterceptorTest {
|
|||
assertValidationErrorValue(person.getAddress().get(1), "true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateOnValidInvalid() {
|
||||
Address address = new Address();
|
||||
address.addLine("Line");
|
||||
address.setCity("City");
|
||||
|
||||
Person person = new Person();
|
||||
person.addAddress(address);
|
||||
|
||||
AddressValidationResult validationResult = new AddressValidationResult();
|
||||
validationResult.setValid(true);
|
||||
when(myValidator.isValid(eq(address), any())).thenReturn(validationResult);
|
||||
myInterceptor.resourcePreUpdate(myRequestDetails, null, person);
|
||||
|
||||
assertValidationErrorValue(person.getAddress().get(0), "false");
|
||||
|
||||
when(myValidator.isValid(eq(address), any())).thenThrow(new RuntimeException());
|
||||
|
||||
myInterceptor.resourcePreUpdate(myRequestDetails, null, person);
|
||||
|
||||
Extension ext = assertValidationErrorExtension(address);
|
||||
assertNotNull(ext);
|
||||
assertNull(ext.getValue());
|
||||
assertTrue(ext.hasExtension());
|
||||
|
||||
}
|
||||
|
||||
public static class TestAddressValidator implements IAddressValidator {
|
||||
@Override
|
||||
public AddressValidationResult isValid(IBase theAddress, FhirContext theFhirContext) throws AddressValidationException {
|
||||
|
|
Loading…
Reference in New Issue