diff options
| author | Paul-Christian Volkmer | 2026-09-03 14:35:10 +0200 |
|---|---|---|
| committer | GitHub | 2026-09-03 14:35:10 +0200 |
| commit | fb91356b7777dfa5b6088bcc3a48b43924c1c0fd (patch) | |
| tree | a3d384390e388395953865a286f15292aaa04a86 /src/test/java/dev/dnpm/oshelper/services | |
| parent | 59daf77a63bd17bb14248cf9881046dd6b331e2a (diff) | |
build: apply Spotless plugin (#293)
Diffstat (limited to 'src/test/java/dev/dnpm/oshelper/services')
14 files changed, 853 insertions, 859 deletions
diff --git a/src/test/java/dev/dnpm/oshelper/services/SettingsServiceTest.java b/src/test/java/dev/dnpm/oshelper/services/SettingsServiceTest.java index f0c53de..ce085eb 100644 --- a/src/test/java/dev/dnpm/oshelper/services/SettingsServiceTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/SettingsServiceTest.java @@ -19,6 +19,10 @@ package dev.dnpm.oshelper.services; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.doAnswer; + import de.itc.db.dnpm.Setting; import dev.dnpm.oshelper.database.SettingsRepository; import org.junit.jupiter.api.BeforeEach; @@ -27,55 +31,50 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.anyString; -import static org.mockito.Mockito.doAnswer; - @ExtendWith(MockitoExtension.class) class SettingsServiceTest { - private SettingsRepository settingsRepository; + private SettingsRepository settingsRepository; - private SettingsService service; + private SettingsService service; - @BeforeEach - void setUp( - @Mock SettingsRepository settingsRepository - ) { - this.settingsRepository = settingsRepository; - this.service = new SettingsService(settingsRepository); - } + @BeforeEach + void setUp(@Mock SettingsRepository settingsRepository) { + this.settingsRepository = settingsRepository; + this.service = new SettingsService(settingsRepository); + } - @Test - void shouldReturnSID() { - doAnswer(invocationOnMock -> { - var name = invocationOnMock.getArgument(0, String.class); - if (null != name && name.equals("SID")) { + @Test + void shouldReturnSID() { + doAnswer( + invocationOnMock -> { + var name = invocationOnMock.getArgument(0, String.class); + if (null != name && name.equals("SID")) { return new Setting(1L, "SID", "12345"); - } - return null; - }).when(settingsRepository).findByName(anyString()); + } + return null; + }) + .when(settingsRepository) + .findByName(anyString()); - var actual = service.getSID(); - assertThat(actual) - .isPresent() - .contains("12345"); - } + var actual = service.getSID(); + assertThat(actual).isPresent().contains("12345"); + } - @Test - void shouldReturnSIDByName() { - doAnswer(invocationOnMock -> { - var name = invocationOnMock.getArgument(0, String.class); - if (null != name && name.equals("SID")) { + @Test + void shouldReturnSIDByName() { + doAnswer( + invocationOnMock -> { + var name = invocationOnMock.getArgument(0, String.class); + if (null != name && name.equals("SID")) { return new Setting(1L, "SID", "12345"); - } - return null; - }).when(settingsRepository).findByName(anyString()); - - var actual = service.getSetting("SID"); - assertThat(actual) - .isPresent() - .contains("12345"); - } + } + return null; + }) + .when(settingsRepository) + .findByName(anyString()); + var actual = service.getSetting("SID"); + assertThat(actual).isPresent().contains("12345"); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/StudieTest.java b/src/test/java/dev/dnpm/oshelper/services/StudieTest.java index f8d64c2..b65760a 100644 --- a/src/test/java/dev/dnpm/oshelper/services/StudieTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/StudieTest.java @@ -19,56 +19,32 @@ package dev.dnpm.oshelper.services; +import static org.assertj.core.api.Assertions.assertThat; + import dev.dnpm.oshelper.dto.Studie; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - class StudieTest { - @Test - void shouldDetectStudieWithNctNumber() { - var studie = new Studie( - "Kat 1", - 1, - null, - "Nct-12345678", - "Teststudie 1", - "Teststudie 1", - true - ); - - assertThat(studie.getType()).isEqualTo(Studie.Type.NCT); - } + @Test + void shouldDetectStudieWithNctNumber() { + var studie = new Studie("Kat 1", 1, null, "Nct-12345678", "Teststudie 1", "Teststudie 1", true); - @Test - void shouldDetectStudieWithEudraCtNumber() { - var studie = new Studie( - "Kat 1", - 1, - null, - "2023-012345-12", - "Teststudie 1", - "Teststudie 1", - true - ); + assertThat(studie.getType()).isEqualTo(Studie.Type.NCT); + } - assertThat(studie.getType()).isEqualTo(Studie.Type.EUDRA_CT); - } + @Test + void shouldDetectStudieWithEudraCtNumber() { + var studie = + new Studie("Kat 1", 1, null, "2023-012345-12", "Teststudie 1", "Teststudie 1", true); - @Test - void shouldReturnStudieWithUnknownNumberScheme() { - var studie = new Studie( - "Kat 1", - 1, - "teststudie1", - null, - "Teststudie 1", - "Teststudie 1", - true - ); + assertThat(studie.getType()).isEqualTo(Studie.Type.EUDRA_CT); + } - assertThat(studie.getType()).isEqualTo(Studie.Type.UNKNOWN); - } + @Test + void shouldReturnStudieWithUnknownNumberScheme() { + var studie = new Studie("Kat 1", 1, "teststudie1", null, "Teststudie 1", "Teststudie 1", true); + assertThat(studie.getType()).isEqualTo(Studie.Type.UNKNOWN); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactoryTest.java b/src/test/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactoryTest.java index 57e505b..7d086de 100644 --- a/src/test/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactoryTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/consent/ConsentManagerServiceFactoryTest.java @@ -19,7 +19,13 @@ package dev.dnpm.oshelper.services.consent; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.when; + import de.itc.onkostar.api.IOnkostarApi; +import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -27,43 +33,33 @@ import org.junit.jupiter.params.provider.MethodSource; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.Map; -import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.when; - @ExtendWith(MockitoExtension.class) class ConsentManagerServiceFactoryTest { - private IOnkostarApi onkostarApi; - - private ConsentManagerServiceFactory consentManagerServiceFactory; + private IOnkostarApi onkostarApi; - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.consentManagerServiceFactory = new ConsentManagerServiceFactory(onkostarApi); - } + private ConsentManagerServiceFactory consentManagerServiceFactory; - private static Set<Map.Entry<String, Class<? extends ConsentManagerService>>> expectedMappings() { - return Map.ofEntries( - Map.entry("MR.Consent", MrConsentManagerService.class), - Map.entry("Excel-Formular", UkwConsentManagerService.class) - ).entrySet(); - } + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.consentManagerServiceFactory = new ConsentManagerServiceFactory(onkostarApi); + } - @ParameterizedTest - @MethodSource("expectedMappings") - void testShouldMapFormNameToService(Map.Entry<String, Class<?>> expectedMapping) { - when(onkostarApi.getGlobalSetting(anyString())).thenReturn(expectedMapping.getKey()); + private static Set<Map.Entry<String, Class<? extends ConsentManagerService>>> expectedMappings() { + return Map.ofEntries( + Map.entry("MR.Consent", MrConsentManagerService.class), + Map.entry("Excel-Formular", UkwConsentManagerService.class)) + .entrySet(); + } - var actual = consentManagerServiceFactory.currentUsableInstance(); + @ParameterizedTest + @MethodSource("expectedMappings") + void testShouldMapFormNameToService(Map.Entry<String, Class<?>> expectedMapping) { + when(onkostarApi.getGlobalSetting(anyString())).thenReturn(expectedMapping.getKey()); - assertThat(actual).isExactlyInstanceOf(expectedMapping.getValue()); - } + var actual = consentManagerServiceFactory.currentUsableInstance(); + assertThat(actual).isExactlyInstanceOf(expectedMapping.getValue()); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/consent/MrConsentManagerServiceTest.java b/src/test/java/dev/dnpm/oshelper/services/consent/MrConsentManagerServiceTest.java index 12b9208..b747987 100644 --- a/src/test/java/dev/dnpm/oshelper/services/consent/MrConsentManagerServiceTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/consent/MrConsentManagerServiceTest.java @@ -19,6 +19,9 @@ package dev.dnpm.oshelper.services.consent; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Procedure; import org.hibernate.SQLQuery; @@ -32,47 +35,42 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class MrConsentManagerServiceTest { - private IOnkostarApi onkostarApi; - - private MrConsentManagerService service; + private IOnkostarApi onkostarApi; - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.service = new MrConsentManagerService(onkostarApi); - } + private MrConsentManagerService service; - @Test - void testShouldCreateSqlQueriesWithRelatedEntityIds() { - var sessionFactory = mock(SessionFactory.class); - var session = mock(Session.class); - var query = mock(SQLQuery.class); + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.service = new MrConsentManagerService(onkostarApi); + } - when(onkostarApi.getSessionFactory()).thenReturn(sessionFactory); - when(sessionFactory.getCurrentSession()).thenReturn(session); - when(session.createSQLQuery(anyString())).thenReturn(query); - when(query.addScalar(anyString(), any(Type.class))).thenReturn(query); - when(query.uniqueResult()).thenReturn(""); + @Test + void testShouldCreateSqlQueriesWithRelatedEntityIds() { + var sessionFactory = mock(SessionFactory.class); + var session = mock(Session.class); + var query = mock(SQLQuery.class); - var dummyProzedur = new Procedure(this.onkostarApi); - dummyProzedur.setId(111); - dummyProzedur.setPatientId(123); + when(onkostarApi.getSessionFactory()).thenReturn(sessionFactory); + when(sessionFactory.getCurrentSession()).thenReturn(session); + when(session.createSQLQuery(anyString())).thenReturn(query); + when(query.addScalar(anyString(), any(Type.class))).thenReturn(query); + when(query.uniqueResult()).thenReturn(""); - this.service.applyConsent(dummyProzedur); + var dummyProzedur = new Procedure(this.onkostarApi); + dummyProzedur.setId(111); + dummyProzedur.setPatientId(123); - var argumentCaptor = ArgumentCaptor.forClass(String.class); - verify(session, times(2)).createSQLQuery(argumentCaptor.capture()); - assertThat(argumentCaptor.getAllValues()).hasSize(2); - assertThat(argumentCaptor.getAllValues().get(0)).contains("where entity_id = '111'"); - assertThat(argumentCaptor.getAllValues().get(1)).contains("WHERE patient_id = 123 AND geloescht = 0"); - } + this.service.applyConsent(dummyProzedur); + var argumentCaptor = ArgumentCaptor.forClass(String.class); + verify(session, times(2)).createSQLQuery(argumentCaptor.capture()); + assertThat(argumentCaptor.getAllValues()).hasSize(2); + assertThat(argumentCaptor.getAllValues().get(0)).contains("where entity_id = '111'"); + assertThat(argumentCaptor.getAllValues().get(1)) + .contains("WHERE patient_id = 123 AND geloescht = 0"); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerServiceTest.java b/src/test/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerServiceTest.java index f21492d..e28dd64 100644 --- a/src/test/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerServiceTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/consent/UkwConsentManagerServiceTest.java @@ -19,9 +19,14 @@ package dev.dnpm.oshelper.services.consent; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Item; import de.itc.onkostar.api.Procedure; +import java.sql.Date; +import java.time.Instant; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -29,129 +34,125 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.sql.Date; -import java.time.Instant; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class UkwConsentManagerServiceTest { - private IOnkostarApi onkostarApi; - - private UkwConsentManagerService service; - - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.service = new UkwConsentManagerService(onkostarApi); - } + private IOnkostarApi onkostarApi; - @Test - void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentAvailable() throws Exception { + private UkwConsentManagerService service; - var excelForm = new Procedure(this.onkostarApi); - excelForm.setId(111); - excelForm.setPatientId(123); - excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.service = new UkwConsentManagerService(onkostarApi); + } - var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); - dnpmKlinikAnamneseForm.setId(2); - dnpmKlinikAnamneseForm.setPatientId(123); + @Test + void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentAvailable() throws Exception { - when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); + var excelForm = new Procedure(this.onkostarApi); + excelForm.setId(111); + excelForm.setPatientId(123); + excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); - this.service.applyConsent(excelForm); + var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); + dnpmKlinikAnamneseForm.setId(2); + dnpmKlinikAnamneseForm.setPatientId(123); - verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); - } + when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); - @Test - void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentDateAvailable() throws Exception { + this.service.applyConsent(excelForm); - var consentSubForm = new Procedure(this.onkostarApi); - consentSubForm.setId(1); - consentSubForm.setPatientId(123); - consentSubForm.setValue("status", new Item("status", "accepted")); + verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); + } + @Test + void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentDateAvailable() + throws Exception { - var excelForm = new Procedure(this.onkostarApi); - excelForm.setId(111); - excelForm.setPatientId(123); - excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); - excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); + var consentSubForm = new Procedure(this.onkostarApi); + consentSubForm.setId(1); + consentSubForm.setPatientId(123); + consentSubForm.setValue("status", new Item("status", "accepted")); - var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); - dnpmKlinikAnamneseForm.setId(2); - dnpmKlinikAnamneseForm.setPatientId(123); + var excelForm = new Procedure(this.onkostarApi); + excelForm.setId(111); + excelForm.setPatientId(123); + excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); + excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); - when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); + var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); + dnpmKlinikAnamneseForm.setId(2); + dnpmKlinikAnamneseForm.setPatientId(123); - this.service.applyConsent(excelForm); + when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); - verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); - } + this.service.applyConsent(excelForm); - @Test - void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentValueAvailable() throws Exception { + verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); + } - var consentSubForm = new Procedure(this.onkostarApi); - consentSubForm.setId(1); - consentSubForm.setPatientId(123); - consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z"))); - consentSubForm.setValue("datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z")))); + @Test + void testShouldSkipUpdateRelatedDnpmKlinikAnamneseFormIfNoConsentValueAvailable() + throws Exception { - var excelForm = new Procedure(this.onkostarApi); - excelForm.setId(111); - excelForm.setPatientId(123); - excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); - excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); + var consentSubForm = new Procedure(this.onkostarApi); + consentSubForm.setId(1); + consentSubForm.setPatientId(123); + consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z"))); + consentSubForm.setValue( + "datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z")))); - var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); - dnpmKlinikAnamneseForm.setId(2); - dnpmKlinikAnamneseForm.setPatientId(123); + var excelForm = new Procedure(this.onkostarApi); + excelForm.setId(111); + excelForm.setPatientId(123); + excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); + excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); - when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); + var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); + dnpmKlinikAnamneseForm.setId(2); + dnpmKlinikAnamneseForm.setPatientId(123); - this.service.applyConsent(excelForm); + when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); - verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); - } + this.service.applyConsent(excelForm); - @Test - void testShouldUpdateRelatedDnpmKlinikAnamneseFormOnFormSave() throws Exception { + verify(onkostarApi, times(0)).saveProcedure(any(Procedure.class), anyBoolean()); + } - var consentSubForm = new Procedure(this.onkostarApi); - consentSubForm.setId(1); - consentSubForm.setPatientId(123); - consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z"))); - consentSubForm.setValue("datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z")))); - consentSubForm.setValue("status", new Item("status", "accepted")); + @Test + void testShouldUpdateRelatedDnpmKlinikAnamneseFormOnFormSave() throws Exception { - var excelForm = new Procedure(this.onkostarApi); - excelForm.setId(111); - excelForm.setPatientId(123); - excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); - excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); + var consentSubForm = new Procedure(this.onkostarApi); + consentSubForm.setId(1); + consentSubForm.setPatientId(123); + consentSubForm.setStartDate(Date.from(Instant.parse("2023-04-03T12:00:00Z"))); + consentSubForm.setValue( + "datum", new Item("datum", Date.from(Instant.parse("2023-04-03T12:00:00Z")))); + consentSubForm.setValue("status", new Item("status", "accepted")); - var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); - dnpmKlinikAnamneseForm.setId(2); - dnpmKlinikAnamneseForm.setPatientId(123); + var excelForm = new Procedure(this.onkostarApi); + excelForm.setId(111); + excelForm.setPatientId(123); + excelForm.setValue("refdnpmklinikanamnese", new Item("refdnpmklinikanamnese", 2)); + excelForm.addSubProcedure("ufdnpmconsent", consentSubForm); - when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); + var dnpmKlinikAnamneseForm = new Procedure(this.onkostarApi); + dnpmKlinikAnamneseForm.setId(2); + dnpmKlinikAnamneseForm.setPatientId(123); - this.service.applyConsent(excelForm); + when(onkostarApi.getProcedure(anyInt())).thenReturn(dnpmKlinikAnamneseForm); - var argumentCaptor = ArgumentCaptor.forClass(Procedure.class); - verify(onkostarApi, times(1)).saveProcedure(argumentCaptor.capture(), anyBoolean()); + this.service.applyConsent(excelForm); - var savedForm = argumentCaptor.getValue(); - assertThat(savedForm).isExactlyInstanceOf(Procedure.class); - assertThat(savedForm.getValue("ConsentStatusEinwilligungDNPM").getString()).isEqualTo("accepted"); - assertThat(savedForm.getValue("ConsentDatumEinwilligungDNPM").getDate()).isEqualTo("2023-04-03T12:00:00Z"); - } + var argumentCaptor = ArgumentCaptor.forClass(Procedure.class); + verify(onkostarApi, times(1)).saveProcedure(argumentCaptor.capture(), anyBoolean()); + var savedForm = argumentCaptor.getValue(); + assertThat(savedForm).isExactlyInstanceOf(Procedure.class); + assertThat(savedForm.getValue("ConsentStatusEinwilligungDNPM").getString()) + .isEqualTo("accepted"); + assertThat(savedForm.getValue("ConsentDatumEinwilligungDNPM").getDate()) + .isEqualTo("2023-04-03T12:00:00Z"); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/molekulargenetik/OsMolekluargenetikFormServiceTest.java b/src/test/java/dev/dnpm/oshelper/services/molekulargenetik/OsMolekluargenetikFormServiceTest.java index 61f82fa..5182160 100644 --- a/src/test/java/dev/dnpm/oshelper/services/molekulargenetik/OsMolekluargenetikFormServiceTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/molekulargenetik/OsMolekluargenetikFormServiceTest.java @@ -19,50 +19,49 @@ package dev.dnpm.oshelper.services.molekulargenetik; +import static org.assertj.core.api.Assertions.assertThat; + import de.itc.onkostar.api.Item; import de.itc.onkostar.api.Procedure; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; - class OsMolekluargenetikFormServiceTest { - private OsMolekulargenetikFormService service; - - @BeforeEach - void setup() { - this.service = new OsMolekulargenetikFormService(); - } + private OsMolekulargenetikFormService service; - @Test - void testShouldReturnVariants() { + @BeforeEach + void setup() { + this.service = new OsMolekulargenetikFormService(); + } - var procedure = new Procedure(null); - procedure.setId(123); - procedure.setFormName("OS.Molekulargenetik"); + @Test + void testShouldReturnVariants() { - var subProcedure1 = new Procedure(null); - subProcedure1.setId(1123); - subProcedure1.setFormName("OS.Molekulargenetische Untersuchung"); - subProcedure1.setValue("Ergebnis", new Item("Ergebnis", "P")); - subProcedure1.setValue("Untersucht", new Item("Untersucht", "BRAF")); - subProcedure1.setValue("ExonInt", new Item("ExonInt", 123)); - subProcedure1.setValue("Pathogenitaetsklasse", new Item("Pathogenitaetsklasse", "2")); - procedure.addSubProcedure("MolekulargenetischeUntersuchung", subProcedure1); + var procedure = new Procedure(null); + procedure.setId(123); + procedure.setFormName("OS.Molekulargenetik"); - var subProcedure2 = new Procedure(null); - subProcedure2.setId(2123); - subProcedure2.setFormName("OS.Molekulargenetische Untersuchung"); - subProcedure2.setValue("Ergebnis", new Item("Ergebnis", "CNV")); - subProcedure2.setValue("Untersucht", new Item("Untersucht", "BRAF")); - subProcedure2.setValue("ExonInt", new Item("ExonInt", 123)); - subProcedure2.setValue("Pathogenitaetsklasse", new Item("Pathogenitaetsklasse", "2")); - procedure.addSubProcedure("MolekulargenetischeUntersuchung", subProcedure2); + var subProcedure1 = new Procedure(null); + subProcedure1.setId(1123); + subProcedure1.setFormName("OS.Molekulargenetische Untersuchung"); + subProcedure1.setValue("Ergebnis", new Item("Ergebnis", "P")); + subProcedure1.setValue("Untersucht", new Item("Untersucht", "BRAF")); + subProcedure1.setValue("ExonInt", new Item("ExonInt", 123)); + subProcedure1.setValue("Pathogenitaetsklasse", new Item("Pathogenitaetsklasse", "2")); + procedure.addSubProcedure("MolekulargenetischeUntersuchung", subProcedure1); - var actual = service.getVariants(procedure); + var subProcedure2 = new Procedure(null); + subProcedure2.setId(2123); + subProcedure2.setFormName("OS.Molekulargenetische Untersuchung"); + subProcedure2.setValue("Ergebnis", new Item("Ergebnis", "CNV")); + subProcedure2.setValue("Untersucht", new Item("Untersucht", "BRAF")); + subProcedure2.setValue("ExonInt", new Item("ExonInt", 123)); + subProcedure2.setValue("Pathogenitaetsklasse", new Item("Pathogenitaetsklasse", "2")); + procedure.addSubProcedure("MolekulargenetischeUntersuchung", subProcedure2); - assertThat(actual).hasSize(2); - } + var actual = service.getVariants(procedure); + assertThat(actual).hasSize(2); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/mtb/MrMtbAnmeldungToProtocolMapperTest.java b/src/test/java/dev/dnpm/oshelper/services/mtb/MrMtbAnmeldungToProtocolMapperTest.java index 405853c..b8e43b3 100644 --- a/src/test/java/dev/dnpm/oshelper/services/mtb/MrMtbAnmeldungToProtocolMapperTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/mtb/MrMtbAnmeldungToProtocolMapperTest.java @@ -19,140 +19,141 @@ package dev.dnpm.oshelper.services.mtb; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.doAnswer; + import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Item; import de.itc.onkostar.api.Procedure; +import java.util.Set; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.util.Set; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.Mockito.doAnswer; - @ExtendWith(MockitoExtension.class) class MrMtbAnmeldungToProtocolMapperTest { - private IOnkostarApi onkostarApi; - - private MrMtbAnmeldungToProtocolMapper mapper; - - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.mapper = new MrMtbAnmeldungToProtocolMapper(onkostarApi); - } - - @Test - void testShouldMapCompletedForm() { - var anmeldung = new Procedure(onkostarApi); - anmeldung.setId(1); - anmeldung.setFormName("MR.MTB_Anmeldung"); - anmeldung.setValue("Fragestellung", new Item("Fragestellung", "Frage?")); - anmeldung.setValue("Empfehlung", new Item("Empfehlung", 2)); - - var empfehlung = new Procedure(onkostarApi); - empfehlung.setId(2); - empfehlung.setFormName("MR.MTB_Empfehlung"); - - var einzelempfehlung1 = new Procedure(onkostarApi); - einzelempfehlung1.setId(10); - einzelempfehlung1.setFormName("MR.MTB_Einzelempfehlung"); - einzelempfehlung1.setValue("Prioritaet", new Item("Empfehlungsprio", 1)); - einzelempfehlung1.setValue("Empfehlung", new Item("Empfehlung", "Empfehlung1")); - - var einzelempfehlung2 = new Procedure(onkostarApi); - einzelempfehlung2.setId(20); - einzelempfehlung2.setFormName("MR.MTB_Einzelempfehlung"); - einzelempfehlung2.setValue("Prioritaet", new Item("Empfehlungsprio", 2)); - einzelempfehlung2.setValue("Empfehlung", new Item("Empfehlung", "Empfehlung2")); - - doAnswer(invocationOnMock -> { - var procedureId = invocationOnMock.getArgument(0, Integer.class); - if (2 == procedureId) { + private IOnkostarApi onkostarApi; + + private MrMtbAnmeldungToProtocolMapper mapper; + + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.mapper = new MrMtbAnmeldungToProtocolMapper(onkostarApi); + } + + @Test + void testShouldMapCompletedForm() { + var anmeldung = new Procedure(onkostarApi); + anmeldung.setId(1); + anmeldung.setFormName("MR.MTB_Anmeldung"); + anmeldung.setValue("Fragestellung", new Item("Fragestellung", "Frage?")); + anmeldung.setValue("Empfehlung", new Item("Empfehlung", 2)); + + var empfehlung = new Procedure(onkostarApi); + empfehlung.setId(2); + empfehlung.setFormName("MR.MTB_Empfehlung"); + + var einzelempfehlung1 = new Procedure(onkostarApi); + einzelempfehlung1.setId(10); + einzelempfehlung1.setFormName("MR.MTB_Einzelempfehlung"); + einzelempfehlung1.setValue("Prioritaet", new Item("Empfehlungsprio", 1)); + einzelempfehlung1.setValue("Empfehlung", new Item("Empfehlung", "Empfehlung1")); + + var einzelempfehlung2 = new Procedure(onkostarApi); + einzelempfehlung2.setId(20); + einzelempfehlung2.setFormName("MR.MTB_Einzelempfehlung"); + einzelempfehlung2.setValue("Prioritaet", new Item("Empfehlungsprio", 2)); + einzelempfehlung2.setValue("Empfehlung", new Item("Empfehlung", "Empfehlung2")); + + doAnswer( + invocationOnMock -> { + var procedureId = invocationOnMock.getArgument(0, Integer.class); + if (2 == procedureId) { return empfehlung; - } else if (10 == procedureId) { + } else if (10 == procedureId) { return einzelempfehlung1; - } else if (20 == procedureId) { + } else if (20 == procedureId) { return einzelempfehlung2; - } - return null; - }).when(onkostarApi).getProcedure(anyInt()); - - doAnswer(invocationOnMock -> { - var procedureId = invocationOnMock.getArgument(0, Integer.class); - if (2 == procedureId) { + } + return null; + }) + .when(onkostarApi) + .getProcedure(anyInt()); + + doAnswer( + invocationOnMock -> { + var procedureId = invocationOnMock.getArgument(0, Integer.class); + if (2 == procedureId) { return Set.of(einzelempfehlung1, einzelempfehlung2); - } - return null; - }).when(onkostarApi).getSubprocedures(anyInt()); - - var actual = this.mapper.apply(anmeldung); - - assertThat(actual) - .isPresent() - .contains( - "Fragestellung:\nFrage?\n\n" - + "Empfehlung:\nEmpfehlung1\n\n" - + "Empfehlung:\nEmpfehlung2" - ); - } - - @Test - void testShouldMapFormWithMissingEinzelempfehlungen() { - var anmeldung = new Procedure(onkostarApi); - anmeldung.setId(1); - anmeldung.setFormName("MR.MTB_Anmeldung"); - anmeldung.setValue("Fragestellung", new Item("Fragestellung", "Frage?")); - anmeldung.setValue("Empfehlung", new Item("Empfehlung", 2)); - - var empfehlung = new Procedure(onkostarApi); - empfehlung.setId(2); - empfehlung.setFormName("MR.MTB_Empfehlung"); - - doAnswer(invocationOnMock -> { - var procedureId = invocationOnMock.getArgument(0, Integer.class); - if (2 == procedureId) { + } + return null; + }) + .when(onkostarApi) + .getSubprocedures(anyInt()); + + var actual = this.mapper.apply(anmeldung); + + assertThat(actual) + .isPresent() + .contains( + "Fragestellung:\nFrage?\n\n" + + "Empfehlung:\nEmpfehlung1\n\n" + + "Empfehlung:\nEmpfehlung2"); + } + + @Test + void testShouldMapFormWithMissingEinzelempfehlungen() { + var anmeldung = new Procedure(onkostarApi); + anmeldung.setId(1); + anmeldung.setFormName("MR.MTB_Anmeldung"); + anmeldung.setValue("Fragestellung", new Item("Fragestellung", "Frage?")); + anmeldung.setValue("Empfehlung", new Item("Empfehlung", 2)); + + var empfehlung = new Procedure(onkostarApi); + empfehlung.setId(2); + empfehlung.setFormName("MR.MTB_Empfehlung"); + + doAnswer( + invocationOnMock -> { + var procedureId = invocationOnMock.getArgument(0, Integer.class); + if (2 == procedureId) { return empfehlung; - } - return null; - }).when(onkostarApi).getProcedure(anyInt()); + } + return null; + }) + .when(onkostarApi) + .getProcedure(anyInt()); - var actual = this.mapper.apply(anmeldung); + var actual = this.mapper.apply(anmeldung); - assertThat(actual) - .isPresent() - .contains("Fragestellung:\nFrage?"); - } + assertThat(actual).isPresent().contains("Fragestellung:\nFrage?"); + } - @Test - void testShouldMapFormWithMissingEmpfehlung() { - var anmeldung = new Procedure(onkostarApi); - anmeldung.setId(1); - anmeldung.setFormName("MR.MTB_Anmeldung"); - anmeldung.setValue("Fragestellung", new Item("Fragestellung", "Frage?")); + @Test + void testShouldMapFormWithMissingEmpfehlung() { + var anmeldung = new Procedure(onkostarApi); + anmeldung.setId(1); + anmeldung.setFormName("MR.MTB_Anmeldung"); + anmeldung.setValue("Fragestellung", new Item("Fragestellung", "Frage?")); - var actual = this.mapper.apply(anmeldung); + var actual = this.mapper.apply(anmeldung); - assertThat(actual) - .isPresent() - .contains("Fragestellung:\nFrage?"); - } + assertThat(actual).isPresent().contains("Fragestellung:\nFrage?"); + } - @Test - void testShouldMapFormWithMissingFragestellungAndEmpfehlung() { - var anmeldung = new Procedure(onkostarApi); - anmeldung.setId(1); - anmeldung.setFormName("MR.MTB_Anmeldung"); + @Test + void testShouldMapFormWithMissingFragestellungAndEmpfehlung() { + var anmeldung = new Procedure(onkostarApi); + anmeldung.setId(1); + anmeldung.setFormName("MR.MTB_Anmeldung"); - var actual = this.mapper.apply(anmeldung); + var actual = this.mapper.apply(anmeldung); - assertThat(actual).isEmpty(); - } + assertThat(actual).isEmpty(); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/mtb/OsTumorkonferenzToProtocolMapperTest.java b/src/test/java/dev/dnpm/oshelper/services/mtb/OsTumorkonferenzToProtocolMapperTest.java index ac86bb6..7ab8ecf 100644 --- a/src/test/java/dev/dnpm/oshelper/services/mtb/OsTumorkonferenzToProtocolMapperTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/mtb/OsTumorkonferenzToProtocolMapperTest.java @@ -19,48 +19,44 @@ package dev.dnpm.oshelper.services.mtb; +import static org.assertj.core.api.Assertions.assertThat; + import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Item; import de.itc.onkostar.api.Procedure; +import java.time.Instant; +import java.util.Date; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.time.Instant; -import java.util.Date; - -import static org.assertj.core.api.Assertions.assertThat; - @ExtendWith(MockitoExtension.class) class OsTumorkonferenzToProtocolMapperTest { - private IOnkostarApi onkostarApi; - - private OsTumorkonferenzToProtocolMapper mapper; + private IOnkostarApi onkostarApi; - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.mapper = new OsTumorkonferenzToProtocolMapper(); - } + private OsTumorkonferenzToProtocolMapper mapper; - @Test - void testShouldReturnMtbProtocolForDefaultImplementation() { - var procedure = new Procedure(onkostarApi); - procedure.setFormName("OS.Tumorkonferenz"); - procedure.setStartDate(Date.from(Instant.parse("2023-01-01T00:00:00Z"))); - procedure.setValue("Fragestellung", new Item("Fragestellung", "Test ok?")); - procedure.setValue("Empfehlung", new Item("Empfehlung", "Rerun Test if not ok!")); + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.mapper = new OsTumorkonferenzToProtocolMapper(); + } - var actual = mapper.apply(procedure); + @Test + void testShouldReturnMtbProtocolForDefaultImplementation() { + var procedure = new Procedure(onkostarApi); + procedure.setFormName("OS.Tumorkonferenz"); + procedure.setStartDate(Date.from(Instant.parse("2023-01-01T00:00:00Z"))); + procedure.setValue("Fragestellung", new Item("Fragestellung", "Test ok?")); + procedure.setValue("Empfehlung", new Item("Empfehlung", "Rerun Test if not ok!")); - assertThat(actual) - .isPresent() - .contains("Fragestellung:\nTest ok?\n\nEmpfehlung:\nRerun Test if not ok!"); - } + var actual = mapper.apply(procedure); + assertThat(actual) + .isPresent() + .contains("Fragestellung:\nTest ok?\n\nEmpfehlung:\nRerun Test if not ok!"); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/mtb/OsTumorkonferenzVarianteUkwToProtocolMapperTest.java b/src/test/java/dev/dnpm/oshelper/services/mtb/OsTumorkonferenzVarianteUkwToProtocolMapperTest.java index ba606ae..0c10371 100644 --- a/src/test/java/dev/dnpm/oshelper/services/mtb/OsTumorkonferenzVarianteUkwToProtocolMapperTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/mtb/OsTumorkonferenzVarianteUkwToProtocolMapperTest.java @@ -19,48 +19,44 @@ package dev.dnpm.oshelper.services.mtb; +import static org.assertj.core.api.Assertions.assertThat; + import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Item; import de.itc.onkostar.api.Procedure; +import java.time.Instant; +import java.util.Date; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.time.Instant; -import java.util.Date; - -import static org.assertj.core.api.Assertions.assertThat; - @ExtendWith(MockitoExtension.class) class OsTumorkonferenzVarianteUkwToProtocolMapperTest { - private IOnkostarApi onkostarApi; - - private OsTumorkonferenzVarianteUkwToProtocolMapper mapper; + private IOnkostarApi onkostarApi; - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.mapper = new OsTumorkonferenzVarianteUkwToProtocolMapper(); - } + private OsTumorkonferenzVarianteUkwToProtocolMapper mapper; - @Test - void testShouldReturnMtbProtocolForDefaultImplementation() { - var procedure = new Procedure(onkostarApi); - procedure.setFormName("OS.Tumorkonferenz.VarianteUKW"); - procedure.setStartDate(Date.from(Instant.parse("2023-01-01T00:00:00Z"))); - procedure.setValue("Fragestellung", new Item("Fragestellung", "Test ok?")); - procedure.setValue("Empfehlung", new Item("Empfehlung", "Rerun Test if not ok!")); + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.mapper = new OsTumorkonferenzVarianteUkwToProtocolMapper(); + } - var actual = mapper.apply(procedure); + @Test + void testShouldReturnMtbProtocolForDefaultImplementation() { + var procedure = new Procedure(onkostarApi); + procedure.setFormName("OS.Tumorkonferenz.VarianteUKW"); + procedure.setStartDate(Date.from(Instant.parse("2023-01-01T00:00:00Z"))); + procedure.setValue("Fragestellung", new Item("Fragestellung", "Test ok?")); + procedure.setValue("Empfehlung", new Item("Empfehlung", "Rerun Test if not ok!")); - assertThat(actual) - .isPresent() - .contains("Fragestellung:\nTest ok?\n\nEmpfehlung:\nRerun Test if not ok!"); - } + var actual = mapper.apply(procedure); + assertThat(actual) + .isPresent() + .contains("Fragestellung:\nTest ok?\n\nEmpfehlung:\nRerun Test if not ok!"); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/strahlentherapie/DefaultStrahlentherapieServiceTest.java b/src/test/java/dev/dnpm/oshelper/services/strahlentherapie/DefaultStrahlentherapieServiceTest.java index 8457dea..16436bd 100644 --- a/src/test/java/dev/dnpm/oshelper/services/strahlentherapie/DefaultStrahlentherapieServiceTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/strahlentherapie/DefaultStrahlentherapieServiceTest.java @@ -19,8 +19,16 @@ package dev.dnpm.oshelper.services.strahlentherapie; -import dev.dnpm.oshelper.services.SettingsService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + import de.itc.onkostar.api.*; +import dev.dnpm.oshelper.services.SettingsService; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Optional; import org.assertj.core.util.Lists; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,95 +37,95 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class DefaultStrahlentherapieServiceTest { - private IOnkostarApi onkostarApi; - - private SettingsService settingsService; - - private DefaultStrahlentherapieService service; - - @BeforeEach - void setup(@Mock IOnkostarApi onkostarApi, @Mock SettingsService settingsService) { - this.onkostarApi = onkostarApi; - this.settingsService = settingsService; - this.service = new DefaultStrahlentherapieService(onkostarApi, settingsService); - } - - @Test - void testShouldRequestProceduresWithDefaultFormName() { - when(this.settingsService.getSetting(anyString())).thenReturn(Optional.empty()); - - doAnswer(invocationOnMock -> { - var procedure = new Procedure(onkostarApi); - procedure.setId(1); - procedure.setFormName("OS.Strahlentherapie"); - procedure.setStartDate(Date.from(Instant.parse("2023-07-01T06:00:00Z"))); - procedure.setEditState(ProcedureEditStateType.COMPLETED); - procedure.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); - return Lists.list(procedure); - }).when(this.onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString()); - - doAnswer(invocationOnMock -> { - var disease = new Disease(onkostarApi); - disease.setId(1); - disease.setPatientId(123); - return Lists.list(disease); - }).when(this.onkostarApi).getDiseasesByPatientId(anyInt()); - - var patient = new Patient(onkostarApi); - patient.setId(123); - - service.ecogStatus(patient); - - var argumentCaptor = ArgumentCaptor.forClass(String.class); - verify(onkostarApi, times(1)).getProceduresForDiseaseByForm(anyInt(), argumentCaptor.capture()); - assertThat(argumentCaptor.getValue()).isEqualTo("OS.Strahlentherapie"); - } - - @Test - void testShouldReturnListOfEcogStatusWithDate() { - doAnswer(invocationOnMock -> { - var disease = new Disease(onkostarApi); - disease.setId(1); - return List.of(disease); - }).when(this.onkostarApi).getDiseasesByPatientId(anyInt()); - - doAnswer(invocationOnMock -> { - var procedure1 = new Procedure(onkostarApi); - procedure1.setId(1); - procedure1.setFormName("OS.Strahlentherapie"); - procedure1.setStartDate(Date.from(Instant.parse("2023-07-01T06:00:00Z"))); - procedure1.setEditState(ProcedureEditStateType.COMPLETED); - procedure1.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); - - var procedure2 = new Procedure(onkostarApi); - procedure2.setId(2); - procedure2.setFormName("OS.Strahlentherapie"); - procedure2.setStartDate(Date.from(Instant.parse("2023-07-12T06:00:00Z"))); - procedure2.setEditState(ProcedureEditStateType.COMPLETED); - procedure2.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 2)); - return List.of(procedure1, procedure2); - }).when(this.onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString()); - - var patient = new Patient(onkostarApi); - patient.setId(1); - - var actual = service.ecogStatus(patient); - - assertThat(actual) - .isNotNull() - .isExactlyInstanceOf(ArrayList.class) - .hasSize(2); - } + private IOnkostarApi onkostarApi; + + private SettingsService settingsService; + + private DefaultStrahlentherapieService service; + + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi, @Mock SettingsService settingsService) { + this.onkostarApi = onkostarApi; + this.settingsService = settingsService; + this.service = new DefaultStrahlentherapieService(onkostarApi, settingsService); + } + + @Test + void testShouldRequestProceduresWithDefaultFormName() { + when(this.settingsService.getSetting(anyString())).thenReturn(Optional.empty()); + + doAnswer( + invocationOnMock -> { + var procedure = new Procedure(onkostarApi); + procedure.setId(1); + procedure.setFormName("OS.Strahlentherapie"); + procedure.setStartDate(Date.from(Instant.parse("2023-07-01T06:00:00Z"))); + procedure.setEditState(ProcedureEditStateType.COMPLETED); + procedure.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); + return Lists.list(procedure); + }) + .when(this.onkostarApi) + .getProceduresForDiseaseByForm(anyInt(), anyString()); + + doAnswer( + invocationOnMock -> { + var disease = new Disease(onkostarApi); + disease.setId(1); + disease.setPatientId(123); + return Lists.list(disease); + }) + .when(this.onkostarApi) + .getDiseasesByPatientId(anyInt()); + + var patient = new Patient(onkostarApi); + patient.setId(123); + + service.ecogStatus(patient); + + var argumentCaptor = ArgumentCaptor.forClass(String.class); + verify(onkostarApi, times(1)).getProceduresForDiseaseByForm(anyInt(), argumentCaptor.capture()); + assertThat(argumentCaptor.getValue()).isEqualTo("OS.Strahlentherapie"); + } + + @Test + void testShouldReturnListOfEcogStatusWithDate() { + doAnswer( + invocationOnMock -> { + var disease = new Disease(onkostarApi); + disease.setId(1); + return List.of(disease); + }) + .when(this.onkostarApi) + .getDiseasesByPatientId(anyInt()); + + doAnswer( + invocationOnMock -> { + var procedure1 = new Procedure(onkostarApi); + procedure1.setId(1); + procedure1.setFormName("OS.Strahlentherapie"); + procedure1.setStartDate(Date.from(Instant.parse("2023-07-01T06:00:00Z"))); + procedure1.setEditState(ProcedureEditStateType.COMPLETED); + procedure1.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); + + var procedure2 = new Procedure(onkostarApi); + procedure2.setId(2); + procedure2.setFormName("OS.Strahlentherapie"); + procedure2.setStartDate(Date.from(Instant.parse("2023-07-12T06:00:00Z"))); + procedure2.setEditState(ProcedureEditStateType.COMPLETED); + procedure2.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 2)); + return List.of(procedure1, procedure2); + }) + .when(this.onkostarApi) + .getProceduresForDiseaseByForm(anyInt(), anyString()); + + var patient = new Patient(onkostarApi); + patient.setId(1); + + var actual = service.ecogStatus(patient); + + assertThat(actual).isNotNull().isExactlyInstanceOf(ArrayList.class).hasSize(2); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/systemtherapie/DefaultSystemtherapieServiceTest.java b/src/test/java/dev/dnpm/oshelper/services/systemtherapie/DefaultSystemtherapieServiceTest.java index e8d474b..05cd535 100644 --- a/src/test/java/dev/dnpm/oshelper/services/systemtherapie/DefaultSystemtherapieServiceTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/systemtherapie/DefaultSystemtherapieServiceTest.java @@ -19,8 +19,13 @@ package dev.dnpm.oshelper.services.systemtherapie; -import dev.dnpm.oshelper.services.SettingsService; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + import de.itc.onkostar.api.*; +import dev.dnpm.oshelper.services.SettingsService; +import java.time.Instant; +import java.util.*; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -30,121 +35,126 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.time.Instant; -import java.util.*; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class DefaultSystemtherapieServiceTest { - private IOnkostarApi onkostarApi; - - private SettingsService settingsService; - - private DefaultSystemtherapieService service; - - @BeforeEach - void setup(@Mock IOnkostarApi onkostarApi, @Mock SettingsService settingsService) { - this.onkostarApi = onkostarApi; - this.settingsService = settingsService; - this.service = new DefaultSystemtherapieService(onkostarApi, settingsService); - } - - private static Set<Map.Entry<String, Class<OsSystemischeTherapieToProzedurwerteMapper>>> expectedMapperMappings() { - return Map.ofEntries(Map.entry("OS.Systemische Therapie", OsSystemischeTherapieToProzedurwerteMapper.class), Map.entry("OS.Systemische Therapie.VarianteUKW", OsSystemischeTherapieToProzedurwerteMapper.class)).entrySet(); - } - - @ParameterizedTest - @MethodSource("expectedMapperMappings") - void testShouldMapFormNameToMapper(Map.Entry<String, Class<?>> expectedMapping) { - var procedure = new Procedure(onkostarApi); - procedure.setFormName(expectedMapping.getKey()); - - var actual = service.prozedurToProzedurwerteMapper(procedure); - - assertThat(actual).isExactlyInstanceOf(expectedMapping.getValue()); - } - - private static List<String> formnameSetting() { - return List.of("OS.Systemische Therapie", "OS.Systemische Therapie.VarianteUKW"); - } - - @ParameterizedTest - @MethodSource("formnameSetting") - void testShouldRequestProceduresWithExpectedFormName(String expectedFormName) { - when(this.settingsService.getSetting(anyString())).thenReturn(Optional.of(expectedFormName)); - when(this.onkostarApi.getProceduresForDiseaseByForm(anyInt(), anyString())).thenReturn(List.of()); - - service.getSystemischeTherapienFromDiagnose(123); - - var argumentCaptor = ArgumentCaptor.forClass(String.class); - verify(onkostarApi, times(1)).getProceduresForDiseaseByForm(anyInt(), argumentCaptor.capture()); - assertThat(argumentCaptor.getValue()).isEqualTo(expectedFormName); - } - - @Test - void testShouldRequestProceduresWithDefaultFormName() { - when(this.settingsService.getSetting(anyString())).thenReturn(Optional.empty()); - when(this.onkostarApi.getProceduresForDiseaseByForm(anyInt(), anyString())).thenReturn(List.of()); - - service.getSystemischeTherapienFromDiagnose(123); - - var argumentCaptor = ArgumentCaptor.forClass(String.class); - verify(onkostarApi, times(1)).getProceduresForDiseaseByForm(anyInt(), argumentCaptor.capture()); - assertThat(argumentCaptor.getValue()).isEqualTo("OS.Systemische Therapie"); - } - - @Test - void testShouldReturnSystemischeTherapienFromDiagnose() { - doAnswer(invocationOnMock -> { - var procedure = new Procedure(onkostarApi); - procedure.setFormName("OS.Systemische Therapie"); - return List.of(procedure); - }).when(this.onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString()); - - var actual = service.getSystemischeTherapienFromDiagnose(1); - - assertThat(actual) - .isNotNull() - .isExactlyInstanceOf(ArrayList.class) - .hasSize(1); - } - - @Test - void testShouldReturnListOfEcogStatusWithDate() { - doAnswer(invocationOnMock -> { - var disease = new Disease(onkostarApi); - disease.setId(1); - return List.of(disease); - }).when(this.onkostarApi).getDiseasesByPatientId(anyInt()); - - doAnswer(invocationOnMock -> { - var procedure1 = new Procedure(onkostarApi); - procedure1.setId(1); - procedure1.setFormName("OS.Systemische Therapie"); - procedure1.setStartDate(Date.from(Instant.parse("2023-07-01T06:00:00Z"))); - procedure1.setEditState(ProcedureEditStateType.COMPLETED); - procedure1.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); - - var procedure2 = new Procedure(onkostarApi); - procedure2.setId(2); - procedure2.setFormName("OS.Systemische Therapie"); - procedure2.setStartDate(Date.from(Instant.parse("2023-07-12T06:00:00Z"))); - procedure2.setEditState(ProcedureEditStateType.COMPLETED); - procedure2.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 2)); - return List.of(procedure1, procedure2); - }).when(this.onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString()); - - var patient = new Patient(onkostarApi); - patient.setId(1); - - var actual = service.ecogStatus(patient); - - assertThat(actual) - .isNotNull() - .isExactlyInstanceOf(ArrayList.class) - .hasSize(2); - } + private IOnkostarApi onkostarApi; + + private SettingsService settingsService; + + private DefaultSystemtherapieService service; + + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi, @Mock SettingsService settingsService) { + this.onkostarApi = onkostarApi; + this.settingsService = settingsService; + this.service = new DefaultSystemtherapieService(onkostarApi, settingsService); + } + + private static Set<Map.Entry<String, Class<OsSystemischeTherapieToProzedurwerteMapper>>> + expectedMapperMappings() { + return Map.ofEntries( + Map.entry("OS.Systemische Therapie", OsSystemischeTherapieToProzedurwerteMapper.class), + Map.entry( + "OS.Systemische Therapie.VarianteUKW", + OsSystemischeTherapieToProzedurwerteMapper.class)) + .entrySet(); + } + + @ParameterizedTest + @MethodSource("expectedMapperMappings") + void testShouldMapFormNameToMapper(Map.Entry<String, Class<?>> expectedMapping) { + var procedure = new Procedure(onkostarApi); + procedure.setFormName(expectedMapping.getKey()); + + var actual = service.prozedurToProzedurwerteMapper(procedure); + + assertThat(actual).isExactlyInstanceOf(expectedMapping.getValue()); + } + + private static List<String> formnameSetting() { + return List.of("OS.Systemische Therapie", "OS.Systemische Therapie.VarianteUKW"); + } + + @ParameterizedTest + @MethodSource("formnameSetting") + void testShouldRequestProceduresWithExpectedFormName(String expectedFormName) { + when(this.settingsService.getSetting(anyString())).thenReturn(Optional.of(expectedFormName)); + when(this.onkostarApi.getProceduresForDiseaseByForm(anyInt(), anyString())) + .thenReturn(List.of()); + + service.getSystemischeTherapienFromDiagnose(123); + + var argumentCaptor = ArgumentCaptor.forClass(String.class); + verify(onkostarApi, times(1)).getProceduresForDiseaseByForm(anyInt(), argumentCaptor.capture()); + assertThat(argumentCaptor.getValue()).isEqualTo(expectedFormName); + } + + @Test + void testShouldRequestProceduresWithDefaultFormName() { + when(this.settingsService.getSetting(anyString())).thenReturn(Optional.empty()); + when(this.onkostarApi.getProceduresForDiseaseByForm(anyInt(), anyString())) + .thenReturn(List.of()); + + service.getSystemischeTherapienFromDiagnose(123); + + var argumentCaptor = ArgumentCaptor.forClass(String.class); + verify(onkostarApi, times(1)).getProceduresForDiseaseByForm(anyInt(), argumentCaptor.capture()); + assertThat(argumentCaptor.getValue()).isEqualTo("OS.Systemische Therapie"); + } + + @Test + void testShouldReturnSystemischeTherapienFromDiagnose() { + doAnswer( + invocationOnMock -> { + var procedure = new Procedure(onkostarApi); + procedure.setFormName("OS.Systemische Therapie"); + return List.of(procedure); + }) + .when(this.onkostarApi) + .getProceduresForDiseaseByForm(anyInt(), anyString()); + + var actual = service.getSystemischeTherapienFromDiagnose(1); + + assertThat(actual).isNotNull().isExactlyInstanceOf(ArrayList.class).hasSize(1); + } + + @Test + void testShouldReturnListOfEcogStatusWithDate() { + doAnswer( + invocationOnMock -> { + var disease = new Disease(onkostarApi); + disease.setId(1); + return List.of(disease); + }) + .when(this.onkostarApi) + .getDiseasesByPatientId(anyInt()); + + doAnswer( + invocationOnMock -> { + var procedure1 = new Procedure(onkostarApi); + procedure1.setId(1); + procedure1.setFormName("OS.Systemische Therapie"); + procedure1.setStartDate(Date.from(Instant.parse("2023-07-01T06:00:00Z"))); + procedure1.setEditState(ProcedureEditStateType.COMPLETED); + procedure1.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 1)); + + var procedure2 = new Procedure(onkostarApi); + procedure2.setId(2); + procedure2.setFormName("OS.Systemische Therapie"); + procedure2.setStartDate(Date.from(Instant.parse("2023-07-12T06:00:00Z"))); + procedure2.setEditState(ProcedureEditStateType.COMPLETED); + procedure2.setValue("ECOGvorTherapie", new Item("ECOGvorTherapie", 2)); + return List.of(procedure1, procedure2); + }) + .when(this.onkostarApi) + .getProceduresForDiseaseByForm(anyInt(), anyString()); + + var patient = new Patient(onkostarApi); + patient.setId(1); + + var actual = service.ecogStatus(patient); + + assertThat(actual).isNotNull().isExactlyInstanceOf(ArrayList.class).hasSize(2); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/systemtherapie/ProzedurToProzedurwerteMapperTest.java b/src/test/java/dev/dnpm/oshelper/services/systemtherapie/ProzedurToProzedurwerteMapperTest.java index 6c7c532..085834f 100644 --- a/src/test/java/dev/dnpm/oshelper/services/systemtherapie/ProzedurToProzedurwerteMapperTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/systemtherapie/ProzedurToProzedurwerteMapperTest.java @@ -19,72 +19,72 @@ package dev.dnpm.oshelper.services.systemtherapie; +import static org.assertj.core.api.Assertions.assertThat; + import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Item; import de.itc.onkostar.api.Procedure; +import java.sql.Date; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.sql.Date; -import java.time.Instant; -import java.util.ArrayList; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - @ExtendWith(MockitoExtension.class) class ProzedurToProzedurwerteMapperTest { - private IOnkostarApi onkostarApi; - - private OsSystemischeTherapieToProzedurwerteMapper mapper; + private IOnkostarApi onkostarApi; - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi - ) { - this.onkostarApi = onkostarApi; - this.mapper = new OsSystemischeTherapieToProzedurwerteMapper(); - } + private OsSystemischeTherapieToProzedurwerteMapper mapper; - @Test - void testShouldReturnSystemischeTherapienFromDiagnose() { - var procedure = new Procedure(onkostarApi); - procedure.setFormName("OS.Systemische Therapie"); - procedure.setValue("Beginn", new Item("Beginn", Date.from(Instant.parse("2023-01-01T00:00:00Z")))); - procedure.setValue("Ende", new Item("Ende", Date.from(Instant.parse("2023-01-31T00:00:00Z")))); - procedure.setValue("Beendigung", new Item("Beendigungsstatus", "E")); - procedure.setValue("Ergebnis", new Item("Ergebnis", "T")); + @BeforeEach + void setup(@Mock IOnkostarApi onkostarApi) { + this.onkostarApi = onkostarApi; + this.mapper = new OsSystemischeTherapieToProzedurwerteMapper(); + } - var substanzen = new ArrayList<>(); - substanzen.add(Map.of( - "Substanz", "Testsubstanz", - "Substanz_shortDescription", "Testsubstanz" - )); - substanzen.add(Map.of( - "Substanz", "L01AA01", - "Substanz_shortDescription", "cyclophosphamide" - )); - procedure.setValue("SubstanzenList", new Item("SubstanzenList", substanzen)); + @Test + void testShouldReturnSystemischeTherapienFromDiagnose() { + var procedure = new Procedure(onkostarApi); + procedure.setFormName("OS.Systemische Therapie"); + procedure.setValue( + "Beginn", new Item("Beginn", Date.from(Instant.parse("2023-01-01T00:00:00Z")))); + procedure.setValue("Ende", new Item("Ende", Date.from(Instant.parse("2023-01-31T00:00:00Z")))); + procedure.setValue("Beendigung", new Item("Beendigungsstatus", "E")); + procedure.setValue("Ergebnis", new Item("Ergebnis", "T")); - var actual = mapper.apply(procedure); + var substanzen = new ArrayList<>(); + substanzen.add( + Map.of( + "Substanz", "Testsubstanz", + "Substanz_shortDescription", "Testsubstanz")); + substanzen.add( + Map.of( + "Substanz", "L01AA01", + "Substanz_shortDescription", "cyclophosphamide")); + procedure.setValue("SubstanzenList", new Item("SubstanzenList", substanzen)); - assertThat(actual).isPresent(); + var actual = mapper.apply(procedure); - assertThat(actual.get()).containsEntry("Beginn", Date.from(Instant.parse("2023-01-01T00:00:00Z")).toString()); - assertThat(actual.get()).containsEntry("Ende", Date.from(Instant.parse("2023-01-31T00:00:00Z")).toString()); - assertThat(actual.get()).containsEntry("Beendigung", "E"); - assertThat(actual.get()).containsEntry("Ergebnis", "T"); - assertThat(actual.get()).containsEntry("Wirkstoffe", "Testsubstanz, cyclophosphamide"); - assertThat(actual.get()).containsEntry("WirkstoffCodes", - "[" + - "{\"system\":\"other\",\"code\":\"Testsubstanz\",\"substance\":\"Testsubstanz\"}," + - "{\"system\":\"ATC\",\"code\":\"L01AA01\",\"substance\":\"cyclophosphamide\"}" + - "]" - ); - } + assertThat(actual).isPresent(); + assertThat(actual.get()) + .containsEntry("Beginn", Date.from(Instant.parse("2023-01-01T00:00:00Z")).toString()); + assertThat(actual.get()) + .containsEntry("Ende", Date.from(Instant.parse("2023-01-31T00:00:00Z")).toString()); + assertThat(actual.get()).containsEntry("Beendigung", "E"); + assertThat(actual.get()).containsEntry("Ergebnis", "T"); + assertThat(actual.get()).containsEntry("Wirkstoffe", "Testsubstanz, cyclophosphamide"); + assertThat(actual.get()) + .containsEntry( + "WirkstoffCodes", + "[" + + "{\"system\":\"other\",\"code\":\"Testsubstanz\",\"substance\":\"Testsubstanz\"}," + + "{\"system\":\"ATC\",\"code\":\"L01AA01\",\"substance\":\"cyclophosphamide\"}" + + "]"); + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/therapieplan/DefaultTherapieplanServiceTest.java b/src/test/java/dev/dnpm/oshelper/services/therapieplan/DefaultTherapieplanServiceTest.java index 18865a8..1d68e08 100644 --- a/src/test/java/dev/dnpm/oshelper/services/therapieplan/DefaultTherapieplanServiceTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/therapieplan/DefaultTherapieplanServiceTest.java @@ -19,11 +19,17 @@ package dev.dnpm.oshelper.services.therapieplan; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + import de.itc.onkostar.api.IOnkostarApi; import de.itc.onkostar.api.Item; import de.itc.onkostar.api.Procedure; import de.itc.onkostar.api.constants.JaNeinUnbekannt; import dev.dnpm.oshelper.services.FormService; +import java.time.Instant; +import java.util.Date; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -31,158 +37,166 @@ import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import java.time.Instant; -import java.util.Date; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.*; - @ExtendWith(MockitoExtension.class) class DefaultTherapieplanServiceTest { - private IOnkostarApi onkostarApi; - - private TherapieplanService service; - - @BeforeEach - void setUp( - @Mock IOnkostarApi onkostarApi, - @Mock FormService formService - ) { - this.onkostarApi = onkostarApi; - this.service = new DefaultTherapieplanService(onkostarApi, formService); - } - - @Test - void shouldNotUpdateSubformsOrSectionsIfMultipleMtbConfiguration() throws Exception { - this.service.updateRequiredMtbEntries(new Procedure(onkostarApi)); - verify(onkostarApi, never()).saveProcedure(any(Procedure.class), anyBoolean()); - } - - @Test - void shouldNotUpdateSectionsIfSectionsNotEnabled() throws Exception { - var testProcedure = baseProcedure(onkostarApi); - - // Keine humangenetische Beratung und keine Reevaluation empfohlen - testProcedure.setValue("humangenberatung", new Item("humangen_beratung", JaNeinUnbekannt.NEIN.getCode())); - testProcedure.setValue("reevaluation", new Item("reevaluation", JaNeinUnbekannt.NEIN.getCode())); - - this.service.updateRequiredMtbEntries(testProcedure); - - verify(onkostarApi, never()).saveProcedure(any(Procedure.class), anyBoolean()); - } - - @Test - void shouldUpdateSectionsIfNoReevaluation() throws Exception { - var testProcedure = baseProcedure(onkostarApi); - - // Humangenetische Beratung aber keine Reevaluation - testProcedure.setValue("humangenberatung", new Item("humangen_beratung", JaNeinUnbekannt.JA.getCode())); - testProcedure.setValue("humangenberbegruendung", new Item("humangen_ber_begruendung", "Das ist die Begründung")); - testProcedure.setValue("reevaluation", new Item("reevaluation", JaNeinUnbekannt.NEIN.getCode())); - - this.service.updateRequiredMtbEntries(testProcedure); - - var captor = ArgumentCaptor.forClass(Procedure.class); - verify(onkostarApi, times(1)).saveProcedure(captor.capture(), anyBoolean()); - - var capturedProcedure = captor.getValue(); - - assertThat(capturedProcedure.getValue("reftkreevaluation")).isNull(); - assertThat(capturedProcedure.getValue("datumtkreevaluation")).isNull(); - - assertThat(capturedProcedure.getValue("reftkhumangenber")).isNotNull(); - assertThat(capturedProcedure.getValue("reftkhumangenber").getInt()).isEqualTo(procedureId); - assertThat(capturedProcedure.getValue("datumtkhumangenber")).isNotNull(); - assertThat(capturedProcedure.getValue("datumtkhumangenber").getDate()).isEqualTo(testDate); - } - - @Test - void shouldUpdateSectionsIfNoHumanGenConsultation() throws Exception { - var testProcedure = baseProcedure(onkostarApi); - - // Humangenetische Beratung aber keine Reevaluation - testProcedure.setValue("humangenberatung", new Item("humangen_beratung", JaNeinUnbekannt.NEIN.getCode())); - testProcedure.setValue("reevaluation", new Item("reevaluation", JaNeinUnbekannt.JA.getCode())); - - this.service.updateRequiredMtbEntries(testProcedure); - - var captor = ArgumentCaptor.forClass(Procedure.class); - verify(onkostarApi, times(1)).saveProcedure(captor.capture(), anyBoolean()); - - var capturedProcedure = captor.getValue(); - - assertThat(capturedProcedure.getValue("reftkhumangenber")).isNull(); - assertThat(capturedProcedure.getValue("datumtkhumangenber")).isNull(); - - assertThat(capturedProcedure.getValue("reftkreevaluation")).isNotNull(); - assertThat(capturedProcedure.getValue("reftkreevaluation").getInt()).isEqualTo(procedureId); - assertThat(capturedProcedure.getValue("datumtkreevaluation")).isNotNull(); - assertThat(capturedProcedure.getValue("datumtkreevaluation").getDate()).isEqualTo(testDate); - } - - @Test - void shouldFindFollowUps() { - doAnswer(invocationOnMock -> { - var testProcedure = baseProcedure(onkostarApi); - testProcedure.setId(procedureId); - testProcedure.setFormName("DNPM UF Einzelempfehlung"); - testProcedure.addDiseaseId(123); - return testProcedure; - }).when(onkostarApi).getProcedure(anyInt()); - - doAnswer(invocationOnMock -> { - var diseaseId = invocationOnMock.getArgument(0, Integer.class); - var formName = invocationOnMock.getArgument(1, String.class); - var procedure = baseProcedure(onkostarApi); - procedure.addDiseaseId(diseaseId); - procedure.setFormName(formName); - procedure.setValue("LinkTherapieempfehlung", new Item("LinkTherapieempfehlung", procedureId)); - return List.of(procedure); - }).when(onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString()); - - var followUps = this.service.findReferencedFollowUpsForSubform(1); - - assertThat(followUps).hasSize(1) - .allSatisfy(procedure -> assertThat(procedure.getFormName()).isEqualTo("DNPM FollowUp")); - } - - @Test - void shouldFindFollowUpsById() { - var testProcedure = baseProcedure(onkostarApi); - testProcedure.setId(procedureId); - testProcedure.setFormName("DNPM UF Einzelempfehlung"); - testProcedure.addDiseaseId(123); - - doAnswer(invocationOnMock -> { - var diseaseId = invocationOnMock.getArgument(0, Integer.class); - var formName = invocationOnMock.getArgument(1, String.class); - var procedure = baseProcedure(onkostarApi); - procedure.addDiseaseId(diseaseId); - procedure.setFormName(formName); - procedure.setValue("LinkTherapieempfehlung", new Item("LinkTherapieempfehlung", procedureId)); - return List.of(procedure); - }).when(onkostarApi).getProceduresForDiseaseByForm(anyInt(), anyString()); - - var followUps = this.service.findReferencedFollowUpsForSubform(testProcedure); - - assertThat(followUps).hasSize(1) - .allSatisfy(procedure -> assertThat(procedure.getFormName()).isEqualTo("DNPM FollowUp")); - } - - private static final int procedureId = 1234; - private static final Date testDate = Date.from(Instant.parse("2023-03-15T09:43:00Z")); - - private Procedure baseProcedure(final IOnkostarApi onkostarApi) { - var testProcedure = new Procedure(onkostarApi); - testProcedure.setId(1000); - - // Setzen MTB Referenz und Datum MTB - testProcedure.setValue("referstemtb", new Item("ref_tumorkonferenz", procedureId)); - testProcedure.setValue("datum", new Item("datum", testDate)); - - return testProcedure; - } - + private IOnkostarApi onkostarApi; + + private TherapieplanService service; + + @BeforeEach + void setUp(@Mock IOnkostarApi onkostarApi, @Mock FormService formService) { + this.onkostarApi = onkostarApi; + this.service = new DefaultTherapieplanService(onkostarApi, formService); + } + + @Test + void shouldNotUpdateSubformsOrSectionsIfMultipleMtbConfiguration() throws Exception { + this.service.updateRequiredMtbEntries(new Procedure(onkostarApi)); + verify(onkostarApi, never()).saveProcedure(any(Procedure.class), anyBoolean()); + } + + @Test + void shouldNotUpdateSectionsIfSectionsNotEnabled() throws Exception { + var testProcedure = baseProcedure(onkostarApi); + + // Keine humangenetische Beratung und keine Reevaluation empfohlen + testProcedure.setValue( + "humangenberatung", new Item("humangen_beratung", JaNeinUnbekannt.NEIN.getCode())); + testProcedure.setValue( + "reevaluation", new Item("reevaluation", JaNeinUnbekannt.NEIN.getCode())); + + this.service.updateRequiredMtbEntries(testProcedure); + + verify(onkostarApi, never()).saveProcedure(any(Procedure.class), anyBoolean()); + } + + @Test + void shouldUpdateSectionsIfNoReevaluation() throws Exception { + var testProcedure = baseProcedure(onkostarApi); + + // Humangenetische Beratung aber keine Reevaluation + testProcedure.setValue( + "humangenberatung", new Item("humangen_beratung", JaNeinUnbekannt.JA.getCode())); + testProcedure.setValue( + "humangenberbegruendung", new Item("humangen_ber_begruendung", "Das ist die Begründung")); + testProcedure.setValue( + "reevaluation", new Item("reevaluation", JaNeinUnbekannt.NEIN.getCode())); + + this.service.updateRequiredMtbEntries(testProcedure); + + var captor = ArgumentCaptor.forClass(Procedure.class); + verify(onkostarApi, times(1)).saveProcedure(captor.capture(), anyBoolean()); + + var capturedProcedure = captor.getValue(); + + assertThat(capturedProcedure.getValue("reftkreevaluation")).isNull(); + assertThat(capturedProcedure.getValue("datumtkreevaluation")).isNull(); + + assertThat(capturedProcedure.getValue("reftkhumangenber")).isNotNull(); + assertThat(capturedProcedure.getValue("reftkhumangenber").getInt()).isEqualTo(procedureId); + assertThat(capturedProcedure.getValue("datumtkhumangenber")).isNotNull(); + assertThat(capturedProcedure.getValue("datumtkhumangenber").getDate()).isEqualTo(testDate); + } + + @Test + void shouldUpdateSectionsIfNoHumanGenConsultation() throws Exception { + var testProcedure = baseProcedure(onkostarApi); + + // Humangenetische Beratung aber keine Reevaluation + testProcedure.setValue( + "humangenberatung", new Item("humangen_beratung", JaNeinUnbekannt.NEIN.getCode())); + testProcedure.setValue("reevaluation", new Item("reevaluation", JaNeinUnbekannt.JA.getCode())); + + this.service.updateRequiredMtbEntries(testProcedure); + + var captor = ArgumentCaptor.forClass(Procedure.class); + verify(onkostarApi, times(1)).saveProcedure(captor.capture(), anyBoolean()); + + var capturedProcedure = captor.getValue(); + + assertThat(capturedProcedure.getValue("reftkhumangenber")).isNull(); + assertThat(capturedProcedure.getValue("datumtkhumangenber")).isNull(); + + assertThat(capturedProcedure.getValue("reftkreevaluation")).isNotNull(); + assertThat(capturedProcedure.getValue("reftkreevaluation").getInt()).isEqualTo(procedureId); + assertThat(capturedProcedure.getValue("datumtkreevaluation")).isNotNull(); + assertThat(capturedProcedure.getValue("datumtkreevaluation").getDate()).isEqualTo(testDate); + } + + @Test + void shouldFindFollowUps() { + doAnswer( + invocationOnMock -> { + var testProcedure = baseProcedure(onkostarApi); + testProcedure.setId(procedureId); + testProcedure.setFormName("DNPM UF Einzelempfehlung"); + testProcedure.addDiseaseId(123); + return testProcedure; + }) + .when(onkostarApi) + .getProcedure(anyInt()); + + doAnswer( + invocationOnMock -> { + var diseaseId = invocationOnMock.getArgument(0, Integer.class); + var formName = invocationOnMock.getArgument(1, String.class); + var procedure = baseProcedure(onkostarApi); + procedure.addDiseaseId(diseaseId); + procedure.setFormName(formName); + procedure.setValue( + "LinkTherapieempfehlung", new Item("LinkTherapieempfehlung", procedureId)); + return List.of(procedure); + }) + .when(onkostarApi) + .getProceduresForDiseaseByForm(anyInt(), anyString()); + + var followUps = this.service.findReferencedFollowUpsForSubform(1); + + assertThat(followUps) + .hasSize(1) + .allSatisfy(procedure -> assertThat(procedure.getFormName()).isEqualTo("DNPM FollowUp")); + } + + @Test + void shouldFindFollowUpsById() { + var testProcedure = baseProcedure(onkostarApi); + testProcedure.setId(procedureId); + testProcedure.setFormName("DNPM UF Einzelempfehlung"); + testProcedure.addDiseaseId(123); + + doAnswer( + invocationOnMock -> { + var diseaseId = invocationOnMock.getArgument(0, Integer.class); + var formName = invocationOnMock.getArgument(1, String.class); + var procedure = baseProcedure(onkostarApi); + procedure.addDiseaseId(diseaseId); + procedure.setFormName(formName); + procedure.setValue( + "LinkTherapieempfehlung", new Item("LinkTherapieempfehlung", procedureId)); + return List.of(procedure); + }) + .when(onkostarApi) + .getProceduresForDiseaseByForm(anyInt(), anyString()); + + var followUps = this.service.findReferencedFollowUpsForSubform(testProcedure); + + assertThat(followUps) + .hasSize(1) + .allSatisfy(procedure -> assertThat(procedure.getFormName()).isEqualTo("DNPM FollowUp")); + } + + private static final int procedureId = 1234; + private static final Date testDate = Date.from(Instant.parse("2023-03-15T09:43:00Z")); + + private Procedure baseProcedure(final IOnkostarApi onkostarApi) { + var testProcedure = new Procedure(onkostarApi); + testProcedure.setId(1000); + + // Setzen MTB Referenz und Datum MTB + testProcedure.setValue("referstemtb", new Item("ref_tumorkonferenz", procedureId)); + testProcedure.setValue("datum", new Item("datum", testDate)); + + return testProcedure; + } } diff --git a/src/test/java/dev/dnpm/oshelper/services/therapieplan/TherapieplanServiceFactoryTest.java b/src/test/java/dev/dnpm/oshelper/services/therapieplan/TherapieplanServiceFactoryTest.java index 7c176bb..c6db22a 100644 --- a/src/test/java/dev/dnpm/oshelper/services/therapieplan/TherapieplanServiceFactoryTest.java +++ b/src/test/java/dev/dnpm/oshelper/services/therapieplan/TherapieplanServiceFactoryTest.java @@ -19,6 +19,8 @@ package dev.dnpm.oshelper.services.therapieplan; +import static org.assertj.core.api.Assertions.assertThat; + import de.itc.onkostar.api.IOnkostarApi; import dev.dnpm.oshelper.services.FormService; import dev.dnpm.oshelper.services.SettingsService; @@ -28,28 +30,26 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.assertj.core.api.Assertions.assertThat; - @ExtendWith(MockitoExtension.class) class TherapieplanServiceFactoryTest { - private SettingsService settingsService; - - private TherapieplanServiceFactory therapieplanServiceFactory; - - @BeforeEach - void setup( - @Mock IOnkostarApi onkostarApi, - @Mock SettingsService settingsService, - @Mock FormService formService - ) { - this.settingsService = settingsService; - this.therapieplanServiceFactory = new TherapieplanServiceFactory(onkostarApi, settingsService, formService); - } - - @Test - void testShouldAlwaysReturnDefaultTherapieplanService() { - var actual = this.therapieplanServiceFactory.currentUsableInstance(); - assertThat(actual).isInstanceOf(DefaultTherapieplanService.class); - } + private SettingsService settingsService; + + private TherapieplanServiceFactory therapieplanServiceFactory; + + @BeforeEach + void setup( + @Mock IOnkostarApi onkostarApi, + @Mock SettingsService settingsService, + @Mock FormService formService) { + this.settingsService = settingsService; + this.therapieplanServiceFactory = + new TherapieplanServiceFactory(onkostarApi, settingsService, formService); + } + + @Test + void testShouldAlwaysReturnDefaultTherapieplanService() { + var actual = this.therapieplanServiceFactory.currentUsableInstance(); + assertThat(actual).isInstanceOf(DefaultTherapieplanService.class); + } } |
