Commit 8f890512 authored by Enriko Käsper's avatar Enriko Käsper
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/auth-service!16
parents 2246ffc3 b795bce2
theGroup=ee.sm.ti.teis
theVersion=0.4.0
commonsVersion=1.0.0
commonApiGatewayVersion=0.25.0
schedulerVersion=0.5.0
theVersion=1.0.0
commonsVersion=1.1.0
commonApiGatewayVersion=1.0.0
schedulerVersion=1.0.0
pluginVersion=1.0.0
mapstructVersion=1.3.0.Final
......@@ -57,8 +57,8 @@ public class OfficialUsersSyncService {
if (!keycloakUser.getFirstName().trim().equals(currentOfficialUser.getFirstName().trim()) ||
!keycloakUser.getLastName().trim().equals(currentOfficialUser.getLastName().trim())) {
// update existing user name
currentOfficialUser.setFirstName(currentOfficialUser.getFirstName().trim());
currentOfficialUser.setLastName(currentOfficialUser.getLastName().trim());
currentOfficialUser.setFirstName(keycloakUser.getFirstName().trim());
currentOfficialUser.setLastName(keycloakUser.getLastName().trim());
officialUsersService.updateOfficialUser(currentOfficialUser, requestMetaDTO);
updatedUsers++;
}
......
......@@ -7,6 +7,8 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.keycloak.representations.idm.UserRepresentation;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
......@@ -23,7 +25,9 @@ import static java.util.Collections.emptySet;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ExtendWith(MockitoExtension.class)
public class OfficialUsersSyncServiceTest {
......@@ -35,6 +39,8 @@ public class OfficialUsersSyncServiceTest {
@InjectMocks
private OfficialUsersSyncService officialUsersSyncService;
private RequestMetaDTO requestMetaDTO;
@Captor
ArgumentCaptor<OfficialUser> captor;
@BeforeEach
void setUp() {
......@@ -59,7 +65,10 @@ public class OfficialUsersSyncServiceTest {
String result = officialUsersSyncService.syncOfficialUsers(requestMetaDTO);
assertThat(result).contains("created=3");
verify(officialUsersService, times(3)).createOfficialUser(any(), any());
verify(officialUsersService, times(3)).createOfficialUser(captor.capture(), any());
assertThat("firstName1").isEqualTo(captor.getAllValues().get(0).getFirstName());
assertThat("lastName1").isEqualTo(captor.getAllValues().get(0).getLastName());
verify(officialUsersService, times(0)).updateOfficialUser(any(), any());
verify(officialUsersService, times(0)).deleteOfficialUser(any(), any());
}
......@@ -74,8 +83,14 @@ public class OfficialUsersSyncServiceTest {
assertThat(result).contains("updated=1");
assertThat(result).contains("deleted=0");
verify(officialUsersService, times(1)).createOfficialUser(any(), any());
verify(officialUsersService, times(1)).updateOfficialUser(any(), any());
verify(officialUsersService, times(1)).createOfficialUser(captor.capture(), any());
assertThat("firstName3").isEqualTo(captor.getValue().getFirstName());
assertThat("lastName3").isEqualTo(captor.getValue().getLastName());
verify(officialUsersService, times(1)).updateOfficialUser(captor.capture(), any());
assertThat("firstName2-NEW").isEqualTo(captor.getValue().getFirstName());
assertThat("lastName2-NEW").isEqualTo(captor.getValue().getLastName());
verify(officialUsersService, times(0)).deleteOfficialUser(any(), any());
}
......@@ -91,7 +106,9 @@ public class OfficialUsersSyncServiceTest {
verify(officialUsersService, times(2)).createOfficialUser(any(), any());
verify(officialUsersService, times(0)).updateOfficialUser(any(), any());
verify(officialUsersService, times(1)).deleteOfficialUser(any(), any());
verify(officialUsersService, times(1)).deleteOfficialUser(captor.capture(), any());
assertThat("firstName5").isEqualTo(captor.getValue().getFirstName());
assertThat("lastName5").isEqualTo(captor.getValue().getLastName());
}
Set<UserRepresentation> getNewKeycloakUsers() {
......@@ -103,8 +120,8 @@ public class OfficialUsersSyncServiceTest {
newUsers.add(user1);
UserRepresentation user2 = new UserRepresentation();
user2.setFirstName("firstName2");
user2.setLastName("lastName2");
user2.setFirstName("firstName2-NEW");
user2.setLastName("lastName2-NEW");
user2.setUsername("22222");
newUsers.add(user2);
......@@ -123,7 +140,7 @@ public class OfficialUsersSyncServiceTest {
OfficialUser user1 = OfficialUser.builder().firstName("firstName1").lastName("lastName1").idCode("11111").build();
newUsers.add(user1);
OfficialUser user2 = OfficialUser.builder().firstName("firstName2-NEW").lastName("lastName2-NEW").idCode("22222").build();
OfficialUser user2 = OfficialUser.builder().firstName("firstName2").lastName("lastName2").idCode("22222").build();
newUsers.add(user2);
return newUsers;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment