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

Merge pull request 'OZG-6821 remove unnessasary realmExists check' (#34) from OZG-6821 into master

parents b5053c69 131a4fa8
Branches
Tags
No related merge requests found
......@@ -40,7 +40,6 @@ public class KeycloakGenericRemoteService {
} else {
return Optional.empty();
}
}
public Optional<RoleRepresentation> getClientRole(String roleName, String realClientId, String realm) {
......
......@@ -69,12 +69,10 @@ class KeycloakRealmService {
}
void createRealm(OzgCloudKeycloakRealmSpec realm, String realmName) {
LOG.debug("{}: Creating new realm...", realmName);
Optional.of(realm)
.map(mapper::map)
.map(realmRepresentation -> addRealmName(realmRepresentation, realmName))
// TODO dieser Filter kann vermutlich gelöscht werden, die Prüfung auf
// realmExists passiert bereits vorher
.filter(realmRepresentation -> !keycloakGenericRemoteService.realmExists(realmName))
.ifPresent(realmRepresentation -> {
remoteService.createRealm(realmRepresentation);
addUserProfileAttributes(realmRepresentation);
......
......@@ -189,36 +189,15 @@ class KeycloakRealmServiceTest {
verify(mapper).map(REALM);
}
@Test
void shouldCallRealmExists() {
service.createRealm(REALM, REALM_NAME);
verify(keycloakGenericRemoteService).realmExists(REALM_NAME);
}
@Test
void shouldCallCreateRealmIfNotExists() {
when(keycloakGenericRemoteService.realmExists(REALM_NAME)).thenReturn(false);
service.createRealm(REALM, REALM_NAME);
verify(remoteService).createRealm(realmRepresentation);
}
@Test
void shouldNOTCallCreateRealmIfAlreadyExists() {
reset(remoteService);
when(keycloakGenericRemoteService.realmExists(REALM_NAME)).thenReturn(true);
service.createRealm(REALM, REALM_NAME);
verify(remoteService, never()).createRealm(any());
}
@Test
void shouldCallAddRealmName() {
when(keycloakGenericRemoteService.realmExists(REALM_NAME)).thenReturn(false);
service.createRealm(REALM, REALM_NAME);
verify(service).addRealmName(realmRepresentation, REALM_NAME);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment