mirror of
https://github.com/pcvolkmer/onkostar-plugin-dnpm.git
synced 2025-07-04 10:02:55 +00:00
Issue #20: Detailimplementierungen für Consent Management
This commit is contained in:
@ -1,20 +1,15 @@
|
||||
package DNPM;
|
||||
|
||||
import DNPM.services.consent.ConsentManagerServiceFactory;
|
||||
import DNPM.services.consent.MrConsentManagerService;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
import org.hibernate.SQLQuery;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.type.Type;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
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.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
@ -22,39 +17,30 @@ class ConsentManagerTest {
|
||||
|
||||
private IOnkostarApi onkostarApi;
|
||||
|
||||
private ConsentManagerServiceFactory consentManagerServiceFactory;
|
||||
|
||||
private ConsentManager consentManager;
|
||||
|
||||
@BeforeEach
|
||||
void setup(
|
||||
@Mock IOnkostarApi onkostarApi
|
||||
@Mock IOnkostarApi onkostarApi,
|
||||
@Mock ConsentManagerServiceFactory consentManagerServiceFactory
|
||||
) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.consentManager = new ConsentManager(onkostarApi);
|
||||
this.consentManagerServiceFactory = consentManagerServiceFactory;
|
||||
this.consentManager = new ConsentManager(onkostarApi, consentManagerServiceFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldCreateSqlQueriesWithRelatedEntityIds() {
|
||||
var sessionFactory = mock(SessionFactory.class);
|
||||
var session = mock(Session.class);
|
||||
var query = mock(SQLQuery.class);
|
||||
void shouldRunServiceMethodsOnAnalyzeCalled() {
|
||||
var consentManagerServiceMock = mock(MrConsentManagerService.class);
|
||||
|
||||
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("");
|
||||
when(this.consentManagerServiceFactory.currentUsableInstance())
|
||||
.thenReturn(consentManagerServiceMock);
|
||||
|
||||
var dummyProzedur = new Procedure(this.onkostarApi);
|
||||
dummyProzedur.setId(111);
|
||||
dummyProzedur.setPatientId(123);
|
||||
this.consentManager.analyze(new Procedure(onkostarApi), null);
|
||||
|
||||
consentManager.analyze(dummyProzedur, null);
|
||||
|
||||
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");
|
||||
verify(consentManagerServiceMock, times(1)).applyConsent(any(Procedure.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
package DNPM.config;
|
||||
|
||||
import DNPM.services.consent.ConsentManagerServiceFactory;
|
||||
import DNPM.services.consent.MrConsentManagerService;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
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;
|
||||
|
||||
@BeforeEach
|
||||
void setup(
|
||||
@Mock IOnkostarApi onkostarApi
|
||||
) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.consentManagerServiceFactory = new ConsentManagerServiceFactory(onkostarApi);
|
||||
}
|
||||
|
||||
private static Set<Map.Entry<String, Class<MrConsentManagerService>>> expectedMappings() {
|
||||
return Map.ofEntries(
|
||||
Map.entry("MR.Consent", MrConsentManagerService.class)
|
||||
).entrySet();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("expectedMappings")
|
||||
void testShouldMapFormNameToService(Map.Entry<String, Class<?>> expectedMapping) {
|
||||
when(onkostarApi.getGlobalSetting(anyString())).thenReturn(expectedMapping.getKey());
|
||||
|
||||
var actual = consentManagerServiceFactory.currentUsableInstance();
|
||||
|
||||
assertThat(actual).isExactlyInstanceOf(expectedMapping.getValue());
|
||||
}
|
||||
|
||||
}
|
@ -3,6 +3,7 @@ package DNPM.config;
|
||||
import DNPM.services.FormService;
|
||||
import DNPM.services.SettingsService;
|
||||
import DNPM.services.TherapieplanServiceFactory;
|
||||
import DNPM.services.consent.ConsentManagerServiceFactory;
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@ -31,6 +32,12 @@ class PluginConfigurationTest {
|
||||
this.configuration = new PluginConfiguration();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldReturnConsentManagerServiceFactory() {
|
||||
var actual = this.configuration.consentManagerServiceFactory(onkostarApi);
|
||||
assertThat(actual).isInstanceOf(ConsentManagerServiceFactory.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldReturnTherapieplanServiceFactory() {
|
||||
var actual = this.configuration.therapieplanServiceFactory(onkostarApi, settingsService, formService);
|
||||
|
@ -0,0 +1,61 @@
|
||||
package DNPM.services.consent;
|
||||
|
||||
import de.itc.onkostar.api.IOnkostarApi;
|
||||
import de.itc.onkostar.api.Procedure;
|
||||
import org.hibernate.SQLQuery;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.type.Type;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
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.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MrConsentManagerServiceTest {
|
||||
|
||||
private IOnkostarApi onkostarApi;
|
||||
|
||||
private MrConsentManagerService service;
|
||||
|
||||
@BeforeEach
|
||||
void setup(
|
||||
@Mock IOnkostarApi onkostarApi
|
||||
) {
|
||||
this.onkostarApi = onkostarApi;
|
||||
this.service = new MrConsentManagerService(onkostarApi);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShouldCreateSqlQueriesWithRelatedEntityIds() {
|
||||
var sessionFactory = mock(SessionFactory.class);
|
||||
var session = mock(Session.class);
|
||||
var query = mock(SQLQuery.class);
|
||||
|
||||
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("");
|
||||
|
||||
var dummyProzedur = new Procedure(this.onkostarApi);
|
||||
dummyProzedur.setId(111);
|
||||
dummyProzedur.setPatientId(123);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user