From 77547481c6d72518970dd66e8d597e7efdda81be Mon Sep 17 00:00:00 2001 From: OZGCloud <ozgcloud@mgm-tp.com> Date: Mon, 15 Apr 2024 11:01:45 +0200 Subject: [PATCH] OZG-4870 improve kc smtp config unittests --- .../realm/KeycloakRealmMapperTest.java | 34 +++++++++++-------- .../realm/KeycloakRealmReconcilerTest.java | 9 ----- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/ozgcloud-keycloak-operator/src/test/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmMapperTest.java b/ozgcloud-keycloak-operator/src/test/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmMapperTest.java index c144180..09a9f07 100644 --- a/ozgcloud-keycloak-operator/src/test/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmMapperTest.java +++ b/ozgcloud-keycloak-operator/src/test/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmMapperTest.java @@ -24,7 +24,8 @@ package de.ozgcloud.operator.keycloak.realm; import static org.assertj.core.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import java.util.Map; import org.junit.jupiter.api.Test; import org.mapstruct.factory.Mappers; @@ -102,21 +103,24 @@ class KeycloakRealmMapperTest { void shouldContainSmtpServerKeysValues() { var mapped = mapper.map(OzgCloudKeycloakRealmSpecTestFactory.create()); var mappedSmtpServer = mapped.getSmtpServer(); - assertThat(mappedSmtpServer.get("host")) - .isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_HOST); - assertThat(mappedSmtpServer.get("port")) - .isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_PORT); - assertThat(mappedSmtpServer.get("password")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_PASSWORD); - assertThat(mappedSmtpServer.get("user")) - .isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_USER); - assertThat(mappedSmtpServer.get("starttls")).isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_STARTTLS); - assertThat(mappedSmtpServer.get("auth")) - .isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_AUTH); - assertThat(mappedSmtpServer.get("from")) - .isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_FROM); - assertThat(mappedSmtpServer.get("fromDisplayName")) - .isEqualTo(KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_FROM_DISPLAY_NAME); + + assertThat(Map.of(mappedSmtpServer.get("host"), KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_HOST)); + assertThat(Map.of(mappedSmtpServer.get("port"), KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_PORT)); + assertThat(Map.of(mappedSmtpServer.get("password"), KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_PASSWORD)); + assertThat(Map.of(mappedSmtpServer.get("user"), KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_USER)); + assertThat(Map.of(mappedSmtpServer.get("starttls"), KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_STARTTLS)); + assertThat(Map.of(mappedSmtpServer.get("auth"), KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_AUTH)); + assertThat(Map.of(mappedSmtpServer.get("from"), KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_FROM)); + assertThat(Map.of(mappedSmtpServer.get("fromDisplayName"), KeycloakRealmSmtpServerTestFactory.SMTP_SERVER_FROM_DISPLAY_NAME)); } + + @Test + void shouldMapWhenSmtpServerIsNull() { + var mapped = mapper.map(OzgCloudKeycloakRealmSpecTestFactory.createBuilder().smtpServer(null).build()); + + assertThat(mapped.getSmtpServer()).isEmpty(); + + } } diff --git a/ozgcloud-keycloak-operator/src/test/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmReconcilerTest.java b/ozgcloud-keycloak-operator/src/test/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmReconcilerTest.java index 14cf807..bdcffd8 100644 --- a/ozgcloud-keycloak-operator/src/test/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmReconcilerTest.java +++ b/ozgcloud-keycloak-operator/src/test/java/de/ozgcloud/operator/keycloak/realm/KeycloakRealmReconcilerTest.java @@ -71,15 +71,6 @@ class KeycloakRealmReconcilerTest { assertThat(response.getResource().getStatus().getStatus()).isEqualTo(OzgCloudCustomResourceStatus.OK); } - - @Test - void shouldCreateRealmWithSpecWithoutSMTPServer() { - OzgCloudKeycloakRealm realm = OzgCloudKeycloakRealmTestFactory.create(); - reconciler.reconcile(realm, null); - var spec = realm.getSpec(); - spec.setSmtpServer(null); - verify(service).createRealm(spec, OzgCloudKeycloakRealmTestFactory.METADATA_NAMESPACE); - } } @DisplayName("Cleanup") -- GitLab