Fixed bug

This commit is contained in:
Nick Goupinets 2021-07-02 18:18:10 -04:00
parent 4bb495e9d7
commit 7d4c39b953
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) {
ExtensionUtil.clearExtensionsByUrl(theAddress, getExtensionUrl());
try {
AddressValidationResult validationResult = getAddressValidator().isValid(theAddress, theFhirContext);
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.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 {