-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fix/expunge historical version exception message #6880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
746518f
9fe2b4d
c63e5dc
b7de5b6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ | |||||||
import ca.uhn.fhir.jpa.dao.data.IResourceHistoryTableDao; | ||||||||
import ca.uhn.fhir.jpa.dao.data.IResourceTableDao; | ||||||||
import ca.uhn.fhir.jpa.model.dao.JpaPid; | ||||||||
import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTablePk; | ||||||||
import ca.uhn.fhir.jpa.model.entity.ResourceTable; | ||||||||
import ca.uhn.fhir.model.primitive.IdDt; | ||||||||
import ca.uhn.fhir.rest.api.server.RequestDetails; | ||||||||
|
@@ -16,9 +17,13 @@ | |||||||
import org.mockito.junit.jupiter.MockitoExtension; | ||||||||
import org.slf4j.LoggerFactory; | ||||||||
|
||||||||
import java.lang.reflect.Field; | ||||||||
import java.util.Collections; | ||||||||
import java.util.Optional; | ||||||||
import java.util.concurrent.atomic.AtomicInteger; | ||||||||
|
||||||||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||||||||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||||||||
import static org.mockito.ArgumentMatchers.any; | ||||||||
import static org.mockito.Mockito.never; | ||||||||
import static org.mockito.Mockito.spy; | ||||||||
|
@@ -56,4 +61,32 @@ public void testExpungeDoesNotDeleteAllSearchParams() { | |||||||
myService.expungeCurrentVersionOfResource(myRequestDetails, JpaPid.fromId(1L), new AtomicInteger(1)); | ||||||||
verify(myService, never()).deleteAllSearchParams(any()); | ||||||||
} | ||||||||
|
||||||||
|
||||||||
@Test | ||||||||
public void testExpungeHistoricalVersions_missingEntry_throwsWithContextualMessage() throws NoSuchFieldException, IllegalAccessException { | ||||||||
// given a primary key with no existing history | ||||||||
ResourceHistoryTablePk pk = new ResourceHistoryTablePk(); | ||||||||
pk.setPartitionIdValue(42); | ||||||||
// set versionId via reflection to avoid null in message | ||||||||
Field versionIdField = ResourceHistoryTablePk.class.getDeclaredField("myVersionId"); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO we could just add a setter to this field so the test has better type safety... No harm in adding it, it's just not there 'cause it wasn't needed before |
||||||||
versionIdField.setAccessible(true); | ||||||||
versionIdField.set(pk, 123L); | ||||||||
|
||||||||
when(myResourceHistoryTableDao.findById(pk)).thenReturn(Optional.empty()); | ||||||||
|
||||||||
AtomicInteger remaining = new AtomicInteger(1); | ||||||||
IllegalArgumentException ex = assertThrows( | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: This is fine, but @fil512 just pointed out to me how much nicer the assertThatThrownBy syntax can be for this kind of assertion the other day: hapi-fhir/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/executor/InterceptorServiceTest.java Lines 698 to 700 in 75162c5
|
||||||||
IllegalArgumentException.class, | ||||||||
() -> myService.expungeHistoricalVersions(myRequestDetails, Collections.singletonList(pk), remaining) | ||||||||
); | ||||||||
|
||||||||
String msg = ex.getMessage(); | ||||||||
assertTrue(msg.contains("No historical version found"), | ||||||||
"Expected exception message to contain 'No historical version found'"); | ||||||||
assertTrue(msg.contains("ResourceHistoryTablePk: 123"), | ||||||||
"Expected message to include 'ResourceHistoryTablePk: 123'"); | ||||||||
assertTrue(msg.contains("partition 42"), | ||||||||
"Expected message to include partition id '42'"); | ||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we should probably include an error code here - We try to include them on all newly thrown exception messages that might end up visible to an end user. (FYI we use this page to reserve them)