test(service): add integration test for findOrCreateByAlias classification
Testcontainers test verifying: SKIP returns null with no DB record, INSTITUTION/GROUP store full name in lastName with null firstName and correct personType, PERSON splits name normally. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package org.raddatz.familienarchiv.service;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.raddatz.familienarchiv.PostgresContainerConfig;
|
||||
import org.raddatz.familienarchiv.model.Person;
|
||||
import org.raddatz.familienarchiv.model.PersonType;
|
||||
import org.raddatz.familienarchiv.repository.PersonRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import software.amazon.awssdk.services.s3.S3Client;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@ActiveProfiles("test")
|
||||
@Import(PostgresContainerConfig.class)
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
class PersonServiceIntegrationTest {
|
||||
|
||||
@MockitoBean S3Client s3Client;
|
||||
@Autowired PersonService personService;
|
||||
@Autowired PersonRepository personRepository;
|
||||
|
||||
@Test
|
||||
void findOrCreateByAlias_skipReturnsNull_noRecordCreated() {
|
||||
Person result = personService.findOrCreateByAlias("Briefumschlag aus Java");
|
||||
|
||||
assertThat(result).isNull();
|
||||
assertThat(personRepository.findAll()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void findOrCreateByAlias_institutionStoresFullNameInLastName() {
|
||||
Person result = personService.findOrCreateByAlias("Arthur Collignon GmbH");
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPersonType()).isEqualTo(PersonType.INSTITUTION);
|
||||
assertThat(result.getFirstName()).isNull();
|
||||
assertThat(result.getLastName()).isEqualTo("Arthur Collignon GmbH");
|
||||
assertThat(result.getDisplayName()).isEqualTo("Arthur Collignon GmbH");
|
||||
}
|
||||
|
||||
@Test
|
||||
void findOrCreateByAlias_groupStoresFullNameInLastName() {
|
||||
Person result = personService.findOrCreateByAlias("Geschwister de Gruyter");
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPersonType()).isEqualTo(PersonType.GROUP);
|
||||
assertThat(result.getFirstName()).isNull();
|
||||
assertThat(result.getLastName()).isEqualTo("Geschwister de Gruyter");
|
||||
}
|
||||
|
||||
@Test
|
||||
void findOrCreateByAlias_personSplitsNameNormally() {
|
||||
Person result = personService.findOrCreateByAlias("Clara Cram");
|
||||
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getPersonType()).isEqualTo(PersonType.PERSON);
|
||||
assertThat(result.getFirstName()).isEqualTo("Clara");
|
||||
assertThat(result.getLastName()).isEqualTo("Cram");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user