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

OZG-5400 update funktion getRealmRepresentation

parent dbf9c59d
No related branches found
No related tags found
No related merge requests found
...@@ -35,7 +35,12 @@ public class KeycloakGenericRemoteService { ...@@ -35,7 +35,12 @@ public class KeycloakGenericRemoteService {
} }
public Optional<RealmRepresentation> getRealmRepresentation(String realmName) { public Optional<RealmRepresentation> getRealmRepresentation(String realmName) {
if (realmExists(realmName)) {
return Optional.of(keycloak.realm(realmName).toRepresentation()); return Optional.of(keycloak.realm(realmName).toRepresentation());
} else {
return Optional.empty();
}
} }
public Optional<RoleRepresentation> getClientRole(String roleName, String realClientId, String realm) { public Optional<RoleRepresentation> getClientRole(String roleName, String realClientId, String realm) {
......
...@@ -198,13 +198,28 @@ class KeycloakGenericRemoteServiceTest { ...@@ -198,13 +198,28 @@ class KeycloakGenericRemoteServiceTest {
@BeforeEach @BeforeEach
void init() { void init() {
when(keycloak.realms()).thenReturn(realmsResource);
}
@Test
void shouldGetRealmFromKeycloakWhenExist() {
when(keycloak.realm(REALM)).thenReturn(realmResource); when(keycloak.realm(REALM)).thenReturn(realmResource);
when(service.realmExists(REALM)).thenReturn(true);
when(realmResource.toRepresentation()).thenReturn(realmRepresentation); when(realmResource.toRepresentation()).thenReturn(realmRepresentation);
var realm = service.getRealmRepresentation(REALM);
assertThat(realm).isNotEmpty().contains(realmRepresentation);
} }
@Test @Test
void shouldGetClientFromKeycloak() { void shouldNotGetRealmFromKeycloakWhenNotExist() {
assertThat(Optional.of(keycloak.realm(REALM).toRepresentation())).isNotEmpty().contains(realmRepresentation);
when(service.realmExists(REALM)).thenReturn(false);
var realm = service.getRealmRepresentation(REALM);
assertTrue(realm.isEmpty());
} }
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment