diff --git a/src/test/java/com/knecon/fforesight/utils/TenantSyncUtils.java b/src/test/java/com/knecon/fforesight/utils/TenantSyncUtils.java new file mode 100644 index 0000000..986ecc7 --- /dev/null +++ b/src/test/java/com/knecon/fforesight/utils/TenantSyncUtils.java @@ -0,0 +1,76 @@ +package com.knecon.fforesight.utils; + +import static org.mockito.Mockito.when; + +import java.util.concurrent.TimeUnit; + +import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder; +import org.jboss.resteasy.client.jaxrs.internal.ResteasyClientBuilderImpl; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.keycloak.OAuth2Constants; +import org.keycloak.admin.client.KeycloakBuilder; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import com.knecon.fforesight.AbstractTenantUserManagementIntegrationTest; +import com.knecon.fforesight.feigntestclients.external.TenantsClient; +import com.knecon.fforesight.feigntestclients.internal.InternalTenantsClient; +import com.knecon.fforesight.tenantusermanagement.TenantUserManagementServiceApplication; +import com.knecon.fforesight.tenantusermanagement.service.KeyCloakRoleManagerService; +import com.knecon.fforesight.tenantusermanagement.service.RealmService; + +@ActiveProfiles(profiles = "taas") +@ExtendWith(SpringExtension.class) +@EnableFeignClients(basePackageClasses = {TenantsClient.class, InternalTenantsClient.class}) +@Import(AbstractTenantUserManagementIntegrationTest.TestConfiguration.class) +@SpringBootTest(classes = TenantUserManagementServiceApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class TenantSyncUtils { + + private final static String SERVER_URL = "https://taas-staging.knecon.com/auth"; + private final static String REALM = "taas"; + private final static String CLIENT_ID = "taas"; + private final static String CLIENT_SECRET = "MJOvReKpRpsTdSEmQQnIJX89DQAwXwiF"; + + @MockBean + RabbitTemplate rabbitTemplate; + + @MockBean + RealmService realmService; + + @Autowired + KeyCloakRoleManagerService keyCloakRoleManagerService; + + + @Test + @Disabled + public void syncTenant() { + + var adminClient = KeycloakBuilder.builder() + .serverUrl(SERVER_URL) + .realm("master") + .clientId(CLIENT_ID) + .clientSecret(CLIENT_SECRET) + .grantType(OAuth2Constants.CLIENT_CREDENTIALS) + .resteasyClient(new ResteasyClientBuilderImpl().connectionTTL(2, TimeUnit.SECONDS) + .hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY) + .connectionPoolSize(10) + .disableTrustManager() + .build()) + .build(); + + var realm = adminClient.realm(REALM); + + when(realmService.realm(REALM)).thenReturn(realm); + + keyCloakRoleManagerService.updateRoles(REALM); + } + +}