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

OZG-5951 restructure call of realmExist in reconciler

parent 8f319b4c
Branches
Tags
No related merge requests found
......@@ -26,7 +26,6 @@ package de.ozgcloud.operator.keycloak.realm;
import org.springframework.stereotype.Component;
import de.ozgcloud.operator.Config;
import de.ozgcloud.operator.keycloak.KeycloakGenericRemoteService;
import de.ozgcloud.operator.keycloak.OzgCloudCustomResourceStatus;
import io.javaoperatorsdk.operator.api.reconciler.Cleaner;
import io.javaoperatorsdk.operator.api.reconciler.Context;
......@@ -44,7 +43,6 @@ import lombok.extern.log4j.Log4j2;
public class KeycloakRealmReconciler implements Reconciler<OzgCloudKeycloakRealm>, Cleaner<OzgCloudKeycloakRealm> {
private final KeycloakRealmService service;
private final KeycloakGenericRemoteService keycloakGenericRemoteService;
@Override
public UpdateControl<OzgCloudKeycloakRealm> reconcile(OzgCloudKeycloakRealm resource, Context<OzgCloudKeycloakRealm> context) {
......@@ -71,7 +69,7 @@ public class KeycloakRealmReconciler implements Reconciler<OzgCloudKeycloakRealm
LOG.info("keep data");
return DeleteControl.defaultDelete();
}
if (!keycloakGenericRemoteService.realmExists(realm.getMetadata().getName())) {
if (!service.realmExists(realm.getMetadata().getName())) {
return DeleteControl.defaultDelete();
}
return deleteRealm(realm);
......
......@@ -87,4 +87,8 @@ class KeycloakRealmService {
public void deleteRealm(String realmName) {
remoteService.deleteRealm(realmName);
}
public boolean realmExists(String realmName) {
return keycloakGenericRemoteService.realmExists(realmName);
}
}
......@@ -35,7 +35,6 @@ import org.mockito.Mock;
import org.mockito.Spy;
import de.ozgcloud.operator.Config;
import de.ozgcloud.operator.keycloak.KeycloakGenericRemoteService;
import de.ozgcloud.operator.keycloak.OzgCloudCustomResourceStatus;
import io.javaoperatorsdk.operator.api.reconciler.DeleteControl;
......@@ -48,9 +47,6 @@ class KeycloakRealmReconcilerTest {
@Mock
private KeycloakRealmService service;
@Mock
private KeycloakGenericRemoteService keycloakGenericRemoteService;
private final String REALM = OzgCloudKeycloakRealmTestFactory.METADATA_NAMESPACE;
@DisplayName("Reconcile")
......@@ -116,7 +112,7 @@ class KeycloakRealmReconcilerTest {
@Test
void shouldDeleteRealmIfRealmExists() {
when(keycloakGenericRemoteService.realmExists(any())).thenReturn(true);
when(service.realmExists(any())).thenReturn(true);
reconciler.cleanup(realm, null);
verify(reconciler).deleteRealm(realm);
......@@ -126,7 +122,7 @@ class KeycloakRealmReconcilerTest {
void shouldReturnValueFromDeleteRealm() {
DeleteControl expected = DeleteControl.defaultDelete();
when(reconciler.deleteRealm(realm)).thenReturn(expected);
when(keycloakGenericRemoteService.realmExists(any())).thenReturn(true);
when(service.realmExists(any())).thenReturn(true);
DeleteControl response = reconciler.cleanup(realm, null);
......@@ -137,12 +133,12 @@ class KeycloakRealmReconcilerTest {
void shouldCallRealmExists() {
reconciler.cleanup(realm, null);
verify(keycloakGenericRemoteService).realmExists(any());
verify(service).realmExists(any());
}
@Test
void shouldNotDeleteRealmIfRealmNotExists() {
when(keycloakGenericRemoteService.realmExists(any())).thenReturn(false);
when(service.realmExists(any())).thenReturn(false);
reconciler.cleanup(realm, null);
......
......@@ -232,4 +232,15 @@ class KeycloakRealmServiceTest {
verify(remoteService).deleteRealm(REALM_NAME);
}
}
@Nested
class TestRealmExists {
@Test
void shouldCallGenericRemoteServiceRealmExists() {
keycloakGenericRemoteService.realmExists(REALM_NAME);
verify(keycloakGenericRemoteService).realmExists(REALM_NAME);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment