test(ocr): add service-level tests for triggerManualSenderTraining
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,10 +7,12 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.raddatz.familienarchiv.model.OcrTrainingRun;
|
||||
import org.raddatz.familienarchiv.model.SenderModel;
|
||||
import org.raddatz.familienarchiv.model.TrainingStatus;
|
||||
import org.raddatz.familienarchiv.exception.DomainException;
|
||||
import org.raddatz.familienarchiv.exception.ErrorCode;
|
||||
import org.raddatz.familienarchiv.model.Person;
|
||||
import org.raddatz.familienarchiv.repository.OcrTrainingRunRepository;
|
||||
import org.raddatz.familienarchiv.repository.SenderModelRepository;
|
||||
import org.raddatz.familienarchiv.repository.TranscriptionBlockRepository;
|
||||
import org.raddatz.familienarchiv.model.Person;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
@@ -262,6 +264,57 @@ class SenderModelServiceTest {
|
||||
|
||||
// ─── triggerSenderTraining — queue promotion ──────────────────────────────
|
||||
|
||||
// ─── triggerManualSenderTraining ──────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
void triggerManualSenderTraining_returnsRunningRun_whenIdle() {
|
||||
when(personService.getById(personId)).thenReturn(Person.builder().id(personId).build());
|
||||
when(blockRepository.countManualKurrentBlocksByPerson(personId)).thenReturn(0L);
|
||||
when(trainingRunRepository.existsByPersonIdAndStatus(personId, TrainingStatus.QUEUED)).thenReturn(false);
|
||||
when(trainingRunRepository.findFirstByStatus(TrainingStatus.RUNNING)).thenReturn(Optional.empty());
|
||||
OcrTrainingRun runningRun = OcrTrainingRun.builder()
|
||||
.id(UUID.randomUUID()).status(TrainingStatus.RUNNING)
|
||||
.personId(personId).blockCount(0).documentCount(0).modelName("sender_" + personId).build();
|
||||
when(trainingRunRepository.save(any())).thenReturn(runningRun);
|
||||
when(trainingRunRepository.findFirstByPersonIdAndStatus(personId, TrainingStatus.RUNNING))
|
||||
.thenReturn(Optional.of(runningRun));
|
||||
|
||||
OcrTrainingRun result = service.triggerManualSenderTraining(personId);
|
||||
|
||||
assertThat(result.getStatus()).isEqualTo(TrainingStatus.RUNNING);
|
||||
assertThat(result.getPersonId()).isEqualTo(personId);
|
||||
}
|
||||
|
||||
@Test
|
||||
void triggerManualSenderTraining_returnsQueuedRun_whenAnotherRunning() {
|
||||
when(personService.getById(personId)).thenReturn(Person.builder().id(personId).build());
|
||||
when(blockRepository.countManualKurrentBlocksByPerson(personId)).thenReturn(0L);
|
||||
when(trainingRunRepository.existsByPersonIdAndStatus(personId, TrainingStatus.QUEUED)).thenReturn(false);
|
||||
when(trainingRunRepository.findFirstByStatus(TrainingStatus.RUNNING)).thenReturn(
|
||||
Optional.of(OcrTrainingRun.builder().id(UUID.randomUUID()).status(TrainingStatus.RUNNING)
|
||||
.blockCount(1).documentCount(0).modelName("german_kurrent").build()));
|
||||
OcrTrainingRun queuedRun = OcrTrainingRun.builder()
|
||||
.id(UUID.randomUUID()).status(TrainingStatus.QUEUED)
|
||||
.personId(personId).blockCount(0).documentCount(0).modelName("sender_" + personId).build();
|
||||
when(trainingRunRepository.save(any())).thenReturn(queuedRun);
|
||||
when(trainingRunRepository.findFirstByPersonIdAndStatus(personId, TrainingStatus.QUEUED))
|
||||
.thenReturn(Optional.of(queuedRun));
|
||||
|
||||
OcrTrainingRun result = service.triggerManualSenderTraining(personId);
|
||||
|
||||
assertThat(result.getStatus()).isEqualTo(TrainingStatus.QUEUED);
|
||||
}
|
||||
|
||||
@Test
|
||||
void triggerManualSenderTraining_throws404_whenPersonNotFound() {
|
||||
when(personService.getById(personId))
|
||||
.thenThrow(DomainException.notFound(ErrorCode.PERSON_NOT_FOUND, "Person not found"));
|
||||
|
||||
org.assertj.core.api.Assertions.assertThatThrownBy(
|
||||
() -> service.triggerManualSenderTraining(personId))
|
||||
.isInstanceOf(DomainException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void triggerSenderTraining_promotesNextQueued_afterCompletion() throws Exception {
|
||||
UUID nextPersonId = UUID.randomUUID();
|
||||
|
||||
Reference in New Issue
Block a user