Skip to content
Snippets Groups Projects
Commit 0381668f authored by OZGCloud's avatar OZGCloud
Browse files

Merge branch 'release'

# Conflicts:
#	archive-manager-interface/pom.xml
#	archive-manager-server/pom.xml
#	pom.xml
parents 148e63ea 05b8f8d1
Branches
Tags
No related merge requests found
Showing
with 89 additions and 72 deletions
...@@ -71,7 +71,7 @@ public class ExportBescheidService { ...@@ -71,7 +71,7 @@ public class ExportBescheidService {
} }
String getFullName(Bescheid bescheid) { String getFullName(Bescheid bescheid) {
return userService.getById(bescheid.getSentInfo().getSentBy()).getFullName(); return userService.getFullNameById(bescheid.getSentInfo().getSentBy());
} }
} }
package de.ozgcloud.archive.common.user; package de.ozgcloud.archive.common.user;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -12,14 +14,25 @@ import lombok.RequiredArgsConstructor; ...@@ -12,14 +14,25 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public class UserService { public class UserService {
private static final String SYSTEM_USER_ID_PREFIX = "system_";
@Qualifier(ArchiveManagerConfiguration.OZGCLOUD_USER_PROFILE_SERVICE_NAME) // NOSONAR @Qualifier(ArchiveManagerConfiguration.OZGCLOUD_USER_PROFILE_SERVICE_NAME) // NOSONAR
private final OzgCloudUserProfileService grpcOzgCloudUserProfileService; private final OzgCloudUserProfileService grpcOzgCloudUserProfileService;
@Qualifier(ArchiveManagerConfiguration.USER_PROFILE_MAPPER_NAME) // NOSONAR @Qualifier(ArchiveManagerConfiguration.USER_PROFILE_MAPPER_NAME) // NOSONAR
private final UserProfileMapper mapper; private final UserProfileMapper mapper;
public UserProfile getById(String sentBy) { public String getFullNameById(String userId) {
return mapper.fromOzgUserProfile(grpcOzgCloudUserProfileService.getById(OzgCloudUserId.from(sentBy))); // TODO (Story offen) es soll der Name des Systems geliefert werden, wenn kein
// Mensch die Aktion ausgeführt hat
return getById(userId).map(UserProfile::getFullName).orElse("automatisch");
}
public Optional<UserProfile> getById(String userId) {
return Optional.of(userId).filter(id -> !id.startsWith(SYSTEM_USER_ID_PREFIX))
.map(OzgCloudUserId::from)
.map(grpcOzgCloudUserProfileService::getById)
.map(mapper::fromOzgUserProfile);
} }
} }
...@@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils; ...@@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils;
import de.ozgcloud.archive.common.command.ArchiveManagerCommand; import de.ozgcloud.archive.common.command.ArchiveManagerCommand;
import de.ozgcloud.archive.common.command.CommandWithPrevious; import de.ozgcloud.archive.common.command.CommandWithPrevious;
import de.ozgcloud.archive.common.user.UserProfile;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
...@@ -51,6 +52,6 @@ class AssignedUserChangeHistoryBuilder extends ChangeHistoryBuilder<AssignedUser ...@@ -51,6 +52,6 @@ class AssignedUserChangeHistoryBuilder extends ChangeHistoryBuilder<AssignedUser
String getAssignedUserFullNameFromCommand(ArchiveManagerCommand command) { String getAssignedUserFullNameFromCommand(ArchiveManagerCommand command) {
var assignedUserId = getValueFromCommandBody(BODY_PROPERTY_ASSIGNED_USER, command); var assignedUserId = getValueFromCommandBody(BODY_PROPERTY_ASSIGNED_USER, command);
return userProfileCache.getUserProfile(assignedUserId).getFullName(); return userProfileCache.getUserProfile(assignedUserId).map(UserProfile::getFullName).orElse("automatisch");
} }
} }
...@@ -2,6 +2,7 @@ package de.ozgcloud.archive.historie; ...@@ -2,6 +2,7 @@ package de.ozgcloud.archive.historie;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import de.ozgcloud.archive.common.user.UserProfile; import de.ozgcloud.archive.common.user.UserProfile;
...@@ -9,18 +10,19 @@ import de.ozgcloud.common.errorhandling.TechnicalException; ...@@ -9,18 +10,19 @@ import de.ozgcloud.common.errorhandling.TechnicalException;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
//TODO OZG-7379 remove this cache
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
class UserProfileCache { class UserProfileCache {
private final Function<String, UserProfile> findUserProfileForUserId; private final Function<String, Optional<UserProfile>> findUserProfileForUserId;
private final Map<String, UserProfile> cache = new HashMap<>(); private final Map<String, Optional<UserProfile>> cache = new HashMap<>();
public static UserProfileCache create(Function<String, UserProfile> findUserProfileForUserId) { public static UserProfileCache create(Function<String, Optional<UserProfile>> findUserProfileForUserId) {
return new UserProfileCache(findUserProfileForUserId); return new UserProfileCache(findUserProfileForUserId);
} }
public UserProfile getUserProfile(String userId) { public Optional<UserProfile> getUserProfile(String userId) {
if (!cache.containsKey(userId)) { if (!cache.containsKey(userId)) {
findAndAddToCache(userId); findAndAddToCache(userId);
} }
......
...@@ -56,7 +56,7 @@ public class ExportKommentarService { ...@@ -56,7 +56,7 @@ public class ExportKommentarService {
} }
String getAuthorFullName(Kommentar kommentar) { String getAuthorFullName(Kommentar kommentar) {
return userService.getById(kommentar.getCreatedBy()).getFullName(); return userService.getFullNameById(kommentar.getCreatedBy());
} }
Stream<Kommentar> getKommentare(VorgangWithEingang vorgang) { Stream<Kommentar> getKommentare(VorgangWithEingang vorgang) {
......
...@@ -61,6 +61,6 @@ public class ExportNachrichtService { ...@@ -61,6 +61,6 @@ public class ExportNachrichtService {
} }
Optional<UserProfile> getUserProfile(PostfachMail postfachMail) { Optional<UserProfile> getUserProfile(PostfachMail postfachMail) {
return Optional.ofNullable(postfachMail.getCreatedBy()).map(userService::getById); return Optional.ofNullable(postfachMail.getCreatedBy()).flatMap(userService::getById);
} }
} }
package de.ozgcloud.archive.bescheid; package de.ozgcloud.archive.bescheid;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.List; import java.util.List;
...@@ -17,7 +18,6 @@ import org.mockito.Spy; ...@@ -17,7 +18,6 @@ import org.mockito.Spy;
import de.ozgcloud.archive.bescheid.BescheidExportData.BescheidExportDataBuilder; import de.ozgcloud.archive.bescheid.BescheidExportData.BescheidExportDataBuilder;
import de.ozgcloud.archive.common.binaryfile.BinaryFileService; import de.ozgcloud.archive.common.binaryfile.BinaryFileService;
import de.ozgcloud.archive.common.user.UserProfile;
import de.ozgcloud.archive.common.user.UserProfileTestFactory; import de.ozgcloud.archive.common.user.UserProfileTestFactory;
import de.ozgcloud.archive.common.user.UserService; import de.ozgcloud.archive.common.user.UserService;
import de.ozgcloud.archive.export.DokumentTypeTestFactory; import de.ozgcloud.archive.export.DokumentTypeTestFactory;
...@@ -388,31 +388,25 @@ class ExportBescheidServiceTest { ...@@ -388,31 +388,25 @@ class ExportBescheidServiceTest {
@Nested @Nested
class TestGetFullName { class TestGetFullName {
private final Bescheid bescheid = BescheidTestFactory.create();
private final UserProfile userProfile = UserProfileTestFactory.create();
private final String expectedFullName = UserProfileTestFactory.FULLNAME;
@BeforeEach
void mockUserService() {
when(userService.getById(SentInfoTestFactory.SENT_BY)).thenReturn(userProfile);
}
@Test @Test
void shouldCallUserServiceGetbyId() { void shouldCallUserServiceGetbyId() {
callService(); callService();
verify(userService).getById(SentInfoTestFactory.SENT_BY); verify(userService).getFullNameById(SentInfoTestFactory.SENT_BY);
} }
@Test @Test
void shouldReturnOptionalOfUserProfile() { void shouldReturnOptionalOfUserProfile() {
when(userService.getFullNameById(any())).thenReturn(UserProfileTestFactory.FULLNAME);
var fullName = callService(); var fullName = callService();
assertThat(fullName).isEqualTo(expectedFullName); assertThat(fullName).isEqualTo(UserProfileTestFactory.FULLNAME);
} }
private String callService() { private String callService() {
return service.getFullName(bescheid); return service.getFullName(BescheidTestFactory.create());
} }
} }
} }
package de.ozgcloud.archive.common.user; package de.ozgcloud.archive.common.user;
import java.util.UUID;
import com.thedeanda.lorem.LoremIpsum; import com.thedeanda.lorem.LoremIpsum;
public class UserProfileTestFactory { public class UserProfileTestFactory {
public static final String USER_ID = UUID.randomUUID().toString();
public static final String FIRSTNAME = LoremIpsum.getInstance().getName(); public static final String FIRSTNAME = LoremIpsum.getInstance().getName();
public static final String LASTNAME = LoremIpsum.getInstance().getName(); public static final String LASTNAME = LoremIpsum.getInstance().getName();
public static final String FULLNAME = String.format("%s %s", FIRSTNAME, LASTNAME); public static final String FULLNAME = String.format("%s %s", FIRSTNAME, LASTNAME);
......
package de.ozgcloud.archive.common.user; package de.ozgcloud.archive.common.user;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.UUID;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
...@@ -21,7 +20,7 @@ class UserServiceTest { ...@@ -21,7 +20,7 @@ class UserServiceTest {
private UserService service; private UserService service;
@Mock @Mock
private GrpcOzgCloudUserProfileService grpcOzgCloudUserProfileService; private GrpcOzgCloudUserProfileService grpcService;
@Mock @Mock
private UserProfileMapper mapper; private UserProfileMapper mapper;
...@@ -29,21 +28,20 @@ class UserServiceTest { ...@@ -29,21 +28,20 @@ class UserServiceTest {
@Nested @Nested
class TestGetById { class TestGetById {
private final String userId = UUID.randomUUID().toString();
private final OzgCloudUserProfile ozgCloudUserProfile = OzgCloudUserProfileTestFactory.create(); private final OzgCloudUserProfile ozgCloudUserProfile = OzgCloudUserProfileTestFactory.create();
@Test @Test
void shouldCallGrpcOzgCloudUserProfileService() { void shouldCallUserProfileService() {
callService(); service.getById(UserProfileTestFactory.USER_ID);
verify(grpcOzgCloudUserProfileService).getById(OzgCloudUserId.from(userId)); verify(grpcService).getById(OzgCloudUserId.from(UserProfileTestFactory.USER_ID));
} }
@Test @Test
void shouldMap() { void shouldMap() {
when(grpcOzgCloudUserProfileService.getById(OzgCloudUserId.from(userId))).thenReturn(ozgCloudUserProfile); when(grpcService.getById(OzgCloudUserId.from(UserProfileTestFactory.USER_ID))).thenReturn(ozgCloudUserProfile);
callService(); service.getById(UserProfileTestFactory.USER_ID);
verify(mapper).fromOzgUserProfile(ozgCloudUserProfile); verify(mapper).fromOzgUserProfile(ozgCloudUserProfile);
} }
...@@ -51,16 +49,27 @@ class UserServiceTest { ...@@ -51,16 +49,27 @@ class UserServiceTest {
@Test @Test
void shouldRetrunMappedUserProfile() { void shouldRetrunMappedUserProfile() {
var mappedUserProfile = UserProfileTestFactory.create(); var mappedUserProfile = UserProfileTestFactory.create();
when(grpcOzgCloudUserProfileService.getById(OzgCloudUserId.from(userId))).thenReturn(ozgCloudUserProfile); when(grpcService.getById(any())).thenReturn(ozgCloudUserProfile);
when(mapper.fromOzgUserProfile(ozgCloudUserProfile)).thenReturn(mappedUserProfile); when(mapper.fromOzgUserProfile(ozgCloudUserProfile)).thenReturn(mappedUserProfile);
var userProfile = callService(); var userProfile = service.getById(UserProfileTestFactory.USER_ID);
assertThat(userProfile).contains(mappedUserProfile);
}
@Test
void shouldReturnEmptyForSystemId() {
var result = service.getById("system_test");
assertThat(userProfile).isEqualTo(mappedUserProfile); assertThat(result).isEmpty();
} }
private UserProfile callService() { @Test
return service.getById(userId); void shoultNOTCallRemoteServiceForSystemId() {
service.getById("system_test");
verify(grpcService, never()).getById(any());
} }
} }
} }
...@@ -11,6 +11,7 @@ import java.io.IOException; ...@@ -11,6 +11,7 @@ import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Iterator; import java.util.Iterator;
import java.util.Optional;
import java.util.stream.Stream; import java.util.stream.Stream;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
...@@ -149,7 +150,7 @@ class ExportGrpcServiceITCase { ...@@ -149,7 +150,7 @@ class ExportGrpcServiceITCase {
return null; return null;
}).when(exportFileService).writeOzgFile(any(), any()); }).when(exportFileService).writeOzgFile(any(), any());
when(userService.getById(KommentarTestFactory.CREATED_BY)).thenReturn(UserProfileTestFactory.create()); when(userService.getById(KommentarTestFactory.CREATED_BY)).thenReturn(Optional.of(UserProfileTestFactory.create()));
} }
@Test @Test
......
package de.ozgcloud.archive.export; package de.ozgcloud.archive.export;
import static de.ozgcloud.archive.common.XDomeaTestUtils.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*; import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -27,9 +27,7 @@ import de.ozgcloud.archive.historie.ExportHistorieService; ...@@ -27,9 +27,7 @@ import de.ozgcloud.archive.historie.ExportHistorieService;
import de.ozgcloud.archive.kommentar.ExportKommentarService; import de.ozgcloud.archive.kommentar.ExportKommentarService;
import de.ozgcloud.archive.kommentar.KommentarsExportDataTestFactory; import de.ozgcloud.archive.kommentar.KommentarsExportDataTestFactory;
import de.ozgcloud.archive.postfach.ExportNachrichtService; import de.ozgcloud.archive.postfach.ExportNachrichtService;
import de.ozgcloud.archive.postfach.PostfachMail;
import de.ozgcloud.archive.postfach.PostfachMailExportDataTestFactory; import de.ozgcloud.archive.postfach.PostfachMailExportDataTestFactory;
import de.ozgcloud.archive.postfach.PostfachMailTestFactory;
import de.ozgcloud.archive.vorgang.VorgangService; import de.ozgcloud.archive.vorgang.VorgangService;
import de.ozgcloud.archive.vorgang.VorgangWithEingang; import de.ozgcloud.archive.vorgang.VorgangWithEingang;
import de.ozgcloud.archive.vorgang.VorgangWithEingangTestFactory; import de.ozgcloud.archive.vorgang.VorgangWithEingangTestFactory;
...@@ -61,16 +59,15 @@ class ExportServiceITCase { ...@@ -61,16 +59,15 @@ class ExportServiceITCase {
class TestWriteExport { class TestWriteExport {
private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create(); private final VorgangWithEingang vorgang = VorgangWithEingangTestFactory.create();
private final PostfachMail postfachMail = PostfachMailTestFactory.createBuilder().id(createMongoDbObjectId()).build();
private final String userId = UUID.randomUUID().toString(); private final String userId = UUID.randomUUID().toString();
@BeforeEach @BeforeEach
void setup() { void setup() {
doReturn(vorgang).when(vorgangService).getVorgang(VorgangWithEingangTestFactory.ID); doReturn(vorgang).when(vorgangService).getVorgang(VorgangWithEingangTestFactory.ID);
doReturn(Stream.of(OzgFileTestFactory.createWithUniqueId())).when(exportFileService).getRepresentations(vorgang); doReturn(Stream.of(OzgFileTestFactory.createWithUniqueId())).when(exportFileService).getRepresentations(any());
doReturn(Stream.of(OzgFileTestFactory.createWithUniqueId())).when(exportFileService).getAttachments(vorgang); doReturn(Stream.of(OzgFileTestFactory.createWithUniqueId())).when(exportFileService).getAttachments(any());
doReturn(Stream.of(OzgFileTestFactory.createWithUniqueId())).when(binaryFileService).getFiles(postfachMail.getAttachments()); doReturn(Stream.of(OzgFileTestFactory.createWithUniqueId())).when(binaryFileService).getFiles(any());
doReturn(UserProfileTestFactory.create()).when(userService).getById(userId); doReturn(Optional.of(UserProfileTestFactory.create())).when(userService).getById(any());
doNothing().when(exportFileService).writeOzgFile(any(), any()); doNothing().when(exportFileService).writeOzgFile(any(), any());
when(exportHistorieService.createHistorienProtokollInformationTypes(vorgang)).thenReturn(Stream.empty()); when(exportHistorieService.createHistorienProtokollInformationTypes(vorgang)).thenReturn(Stream.empty());
when(exportKommentarService.createExportData(vorgang)).thenReturn(KommentarsExportDataTestFactory.create()); when(exportKommentarService.createExportData(vorgang)).thenReturn(KommentarsExportDataTestFactory.create());
......
...@@ -3,10 +3,12 @@ package de.ozgcloud.archive.historie; ...@@ -3,10 +3,12 @@ package de.ozgcloud.archive.historie;
import static de.ozgcloud.archive.historie.AssignedUserChangeHistoryBuilder.*; import static de.ozgcloud.archive.historie.AssignedUserChangeHistoryBuilder.*;
import static de.ozgcloud.archive.historie.ChangeHistoryBuilderTest.*; import static de.ozgcloud.archive.historie.ChangeHistoryBuilderTest.*;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
...@@ -22,7 +24,6 @@ import de.ozgcloud.archive.common.command.ArchiveManagerCommand; ...@@ -22,7 +24,6 @@ import de.ozgcloud.archive.common.command.ArchiveManagerCommand;
import de.ozgcloud.archive.common.command.CommandTestFactory; import de.ozgcloud.archive.common.command.CommandTestFactory;
import de.ozgcloud.archive.common.command.CommandWithPrevious; import de.ozgcloud.archive.common.command.CommandWithPrevious;
import de.ozgcloud.archive.common.command.CommandWithPreviousTestFactory; import de.ozgcloud.archive.common.command.CommandWithPreviousTestFactory;
import de.ozgcloud.archive.common.user.UserProfile;
import de.ozgcloud.archive.common.user.UserProfileTestFactory; import de.ozgcloud.archive.common.user.UserProfileTestFactory;
public class AssignedUserChangeHistoryBuilderTest { public class AssignedUserChangeHistoryBuilderTest {
...@@ -191,28 +192,24 @@ public class AssignedUserChangeHistoryBuilderTest { ...@@ -191,28 +192,24 @@ public class AssignedUserChangeHistoryBuilderTest {
@Nested @Nested
class TestGetAssignedUserFullNameFromCommand { class TestGetAssignedUserFullNameFromCommand {
private static final String USER_ID = UUID.randomUUID().toString();
private static final UserProfile USER_PROFILE = UserProfileTestFactory.create();
private final ArchiveManagerCommand command = previousCommand;
@BeforeEach @BeforeEach
void init() { void init() {
when(builder.getValueFromCommandBody(BODY_PROPERTY_ASSIGNED_USER, previousCommand)).thenReturn(USER_ID.toString()); doReturn(UserProfileTestFactory.USER_ID).when(builder).getValueFromCommandBody(any(), any());
when(userProfileCache.getUserProfile(USER_ID)).thenReturn(USER_PROFILE); doReturn(Optional.of(UserProfileTestFactory.create())).when(userProfileCache).getUserProfile(any());
} }
@Test @Test
void shouldGetUserIdFromCommand() { void shouldGetUserIdFromCommand() {
callBuilder(); callBuilder();
verify(builder).getValueFromCommandBody(BODY_PROPERTY_ASSIGNED_USER, command); verify(builder).getValueFromCommandBody(BODY_PROPERTY_ASSIGNED_USER, previousCommand);
} }
@Test @Test
void shouldGetUserProfileForUserId() { void shouldGetUserProfileForUserId() {
callBuilder(); callBuilder();
verify(userProfileCache).getUserProfile(USER_ID); verify(userProfileCache).getUserProfile(UserProfileTestFactory.USER_ID);
} }
@Test @Test
...@@ -223,7 +220,7 @@ public class AssignedUserChangeHistoryBuilderTest { ...@@ -223,7 +220,7 @@ public class AssignedUserChangeHistoryBuilderTest {
} }
private String callBuilder() { private String callBuilder() {
return builder.getAssignedUserFullNameFromCommand(command); return builder.getAssignedUserFullNameFromCommand(previousCommand);
} }
} }
} }
...@@ -6,6 +6,7 @@ import static org.mockito.Mockito.*; ...@@ -6,6 +6,7 @@ import static org.mockito.Mockito.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.function.Function; import java.util.function.Function;
...@@ -24,7 +25,7 @@ class UserProfileCacheTest { ...@@ -24,7 +25,7 @@ class UserProfileCacheTest {
private static final UserProfile EXPECTED_USER_PROFILE = UserProfileTestFactory.create(); private static final UserProfile EXPECTED_USER_PROFILE = UserProfileTestFactory.create();
@Mock @Mock
private Function<String, UserProfile> findUserProfileForUserId; private Function<String, Optional<UserProfile>> findUserProfileForUserId;
@InjectMocks @InjectMocks
private UserProfileCache cache; private UserProfileCache cache;
...@@ -43,7 +44,7 @@ class UserProfileCacheTest { ...@@ -43,7 +44,7 @@ class UserProfileCacheTest {
var userProfile = cache.getUserProfile(USER_ID); var userProfile = cache.getUserProfile(USER_ID);
assertThat(userProfile).isEqualTo(EXPECTED_USER_PROFILE); assertThat(userProfile).contains(EXPECTED_USER_PROFILE);
} }
@Test @Test
...@@ -52,7 +53,7 @@ class UserProfileCacheTest { ...@@ -52,7 +53,7 @@ class UserProfileCacheTest {
cache.getUserProfile(USER_ID); cache.getUserProfile(USER_ID);
assertThat(getUserProfileFromCache()).isEqualTo(EXPECTED_USER_PROFILE); assertThat(getUserProfileFromCache()).contains(EXPECTED_USER_PROFILE);
} }
@Test @Test
...@@ -70,7 +71,7 @@ class UserProfileCacheTest { ...@@ -70,7 +71,7 @@ class UserProfileCacheTest {
var userProfile = cache.getUserProfile(USER_ID); var userProfile = cache.getUserProfile(USER_ID);
assertThat(userProfile).isEqualTo(EXPECTED_USER_PROFILE); assertThat(userProfile).contains(EXPECTED_USER_PROFILE);
} }
@Test @Test
...@@ -82,17 +83,17 @@ class UserProfileCacheTest { ...@@ -82,17 +83,17 @@ class UserProfileCacheTest {
} }
private void givenFindUserProfileForUserIdReturnsUserProfile() { private void givenFindUserProfileForUserIdReturnsUserProfile() {
when(findUserProfileForUserId.apply(USER_ID)).thenReturn(EXPECTED_USER_PROFILE); when(findUserProfileForUserId.apply(USER_ID)).thenReturn(Optional.of(EXPECTED_USER_PROFILE));
} }
private void givenUserProfileIsInCache() { private void givenUserProfileIsInCache() {
var cache = new HashMap<String, UserProfile>(); var cache = new HashMap<String, Optional<UserProfile>>();
cache.put(USER_ID, EXPECTED_USER_PROFILE); cache.put(USER_ID, Optional.of(EXPECTED_USER_PROFILE));
ReflectionTestUtils.setField(this.cache, "cache", cache); ReflectionTestUtils.setField(this.cache, "cache", cache);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private UserProfile getUserProfileFromCache() { private Optional<UserProfile> getUserProfileFromCache() {
return ((Map<String, UserProfile>) Objects.requireNonNull(ReflectionTestUtils.getField(cache, "cache"))).get(USER_ID); return ((Map<String, Optional<UserProfile>>) Objects.requireNonNull(ReflectionTestUtils.getField(cache, "cache"))).get(USER_ID);
} }
} }
...@@ -7,6 +7,7 @@ import static org.mockito.Mockito.*; ...@@ -7,6 +7,7 @@ import static org.mockito.Mockito.*;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
...@@ -225,7 +226,7 @@ public class VorgangChangeHistoryServiceTest { ...@@ -225,7 +226,7 @@ public class VorgangChangeHistoryServiceTest {
private MockedStatic<UserProfileCache> staticUserProfileCache; private MockedStatic<UserProfileCache> staticUserProfileCache;
@Captor @Captor
private ArgumentCaptor<Function<String, UserProfile>> userProfileCacheArgCaptor; private ArgumentCaptor<Function<String, Optional<UserProfile>>> userProfileCacheArgCaptor;
@Mock @Mock
private AssignedUserChangeHistoryBuilder builder; private AssignedUserChangeHistoryBuilder builder;
......
package de.ozgcloud.archive.kommentar; package de.ozgcloud.archive.kommentar;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import java.util.List; import java.util.List;
...@@ -211,20 +212,17 @@ class ExportKommentarServiceTest { ...@@ -211,20 +212,17 @@ class ExportKommentarServiceTest {
@Nested @Nested
class TestGetAuthorFullName { class TestGetAuthorFullName {
@BeforeEach
void init() {
when(userService.getById(KommentarTestFactory.CREATED_BY)).thenReturn(UserProfileTestFactory.create());
}
@Test @Test
void shouldGetUser() { void shouldGetUser() {
service.getAuthorFullName(KommentarTestFactory.create()); service.getAuthorFullName(KommentarTestFactory.create());
verify(userService).getById(KommentarTestFactory.CREATED_BY); verify(userService).getFullNameById(KommentarTestFactory.CREATED_BY);
} }
@Test @Test
void shouldReturnAuthorsFullName() { void shouldReturnAuthorsFullName() {
when(userService.getFullNameById(any())).thenReturn(UserProfileTestFactory.FULLNAME);
var authorFullName = service.getAuthorFullName(KommentarTestFactory.create()); var authorFullName = service.getAuthorFullName(KommentarTestFactory.create());
assertThat(authorFullName).isEqualTo(UserProfileTestFactory.FULLNAME); assertThat(authorFullName).isEqualTo(UserProfileTestFactory.FULLNAME);
......
...@@ -314,7 +314,7 @@ class ExportNachrichtServiceTest { ...@@ -314,7 +314,7 @@ class ExportNachrichtServiceTest {
@BeforeEach @BeforeEach
void mockUserService() { void mockUserService() {
when(userService.getById(postfachMail.getCreatedBy())).thenReturn(expectedUserProfile); when(userService.getById(postfachMail.getCreatedBy())).thenReturn(Optional.of(expectedUserProfile));
} }
@Test @Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment