Merge pull request #2776 from hapifhir/2775_address_interceptor

Address interceptor bug
This commit is contained in:
Nick Goupinets 2021-07-03 11:19:38 -04:00 committed by GitHub
commit 3bafdd7de1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -165,6 +165,8 @@ public class AddressValidatingInterceptor {
} }
protected boolean validateAddress(IBase theAddress, FhirContext theFhirContext) { protected boolean validateAddress(IBase theAddress, FhirContext theFhirContext) {
ExtensionUtil.clearExtensionsByUrl(theAddress, getExtensionUrl());
try { try {
AddressValidationResult validationResult = getAddressValidator().isValid(theAddress, theFhirContext); AddressValidationResult validationResult = getAddressValidator().isValid(theAddress, theFhirContext);
ourLog.debug("Validated address {}", validationResult); ourLog.debug("Validated address {}", validationResult);

View File

@ -33,6 +33,7 @@ import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -235,6 +236,33 @@ class AddressValidatingInterceptorTest {
assertValidationErrorValue(person.getAddress().get(1), "true"); 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 { public static class TestAddressValidator implements IAddressValidator {
@Override @Override
public AddressValidationResult isValid(IBase theAddress, FhirContext theFhirContext) throws AddressValidationException { public AddressValidationResult isValid(IBase theAddress, FhirContext theFhirContext) throws AddressValidationException {