Skip to content

Commit

Permalink
[issue 100] - Removing manually generated Java model and adjusting th…
Browse files Browse the repository at this point in the history
…e clients to fit the generated one
  • Loading branch information
fabiobrz committed Oct 18, 2023
1 parent 09d07d1 commit 5d110c9
Show file tree
Hide file tree
Showing 91 changed files with 4,018 additions and 3,153 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.jboss.intersmash.testsuite.junit5.categories;

import org.junit.jupiter.api.Tag;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.junit.jupiter.api.Tag;

/**
* Mark a test that does not support community deliverables.
* Used per class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
import org.jboss.intersmash.testsuite.IntersmashTestsuiteProperties;
import org.jboss.intersmash.tools.IntersmashConfig;
import org.jboss.intersmash.tools.application.openshift.BootableJarOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7ImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.KafkaOperatorApplication;
import org.jboss.intersmash.tools.application.openshift.MysqlImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.PostgreSQLImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.WildflyImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.Eap7ImageOpenShiftApplication;
import org.jboss.intersmash.tools.application.openshift.input.BinarySource;
import org.jboss.intersmash.tools.application.openshift.input.BuildInput;
import org.jboss.intersmash.tools.application.openshift.input.BuildInputBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,27 @@
package org.jboss.intersmash.testsuite.provision.openshift;

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.jboss.intersmash.testsuite.junit5.categories.NotForCommunityExecutionProfile;
import org.jboss.intersmash.tools.application.openshift.RhSsoOperatorApplication;
import org.jboss.intersmash.tools.junit5.IntersmashExtension;
import org.jboss.intersmash.tools.provision.openshift.RhSsoOperatorProvisioner;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.backup.KeycloakBackup;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.backup.KeycloakBackupBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.backup.spec.KeycloakAWSSpecBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.client.KeycloakClient;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.client.KeycloakClientBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.client.spec.KeycloakAPIClientBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.keycloak.Keycloak;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.keycloak.KeycloakBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.keycloak.spec.KeycloakExternalAccessBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.realm.KeycloakRealm;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.realm.KeycloakRealmBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.realm.spec.KeycloakAPIRealmBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.realm.spec.RedirectorIdentityProviderOverrideBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.user.KeycloakUser;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.user.KeycloakUserBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.user.spec.KeycloakAPIUserBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.user.spec.KeycloakCredential;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.user.spec.KeycloakCredentialBuilder;
import org.jboss.intersmash.tools.provision.openshift.operator.resources.OperatorGroup;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -49,6 +45,16 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.keycloak.v1alpha1.Keycloak;
import org.keycloak.v1alpha1.KeycloakBackup;
import org.keycloak.v1alpha1.KeycloakClient;
import org.keycloak.v1alpha1.KeycloakRealm;
import org.keycloak.v1alpha1.KeycloakUser;
import org.keycloak.v1alpha1.keycloakclientspec.Client;
import org.keycloak.v1alpha1.keycloakclientspec.RealmSelector;
import org.keycloak.v1alpha1.keycloakrealmspec.InstanceSelector;
import org.keycloak.v1alpha1.keycloakuserspec.User;
import org.keycloak.v1alpha1.keycloakuserspec.user.Credentials;
import org.slf4j.event.Level;

import cz.xtf.core.openshift.OpenShiftWaiters;
Expand All @@ -58,7 +64,6 @@
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapBuilder;
import io.fabric8.kubernetes.api.model.DeletionPropagation;
import io.fabric8.kubernetes.api.model.LabelSelectorBuilder;
import lombok.extern.slf4j.Slf4j;

/**
Expand All @@ -72,7 +77,7 @@
*/
@Slf4j
@CleanBeforeAll
@Disabled("WIP - Disabled until global-test.properties is configured with the required property")
@NotForCommunityExecutionProfile
public class RhSsoOperatorProvisionerTest {
// Be aware that since we're using the static mock application, not all provisioner methods will work as expected!
private static final RhSsoOperatorProvisioner KEYCLOAK_OPERATOR_PROVISIONER = initializeOperatorProvisioner();
Expand Down Expand Up @@ -234,14 +239,17 @@ public void clientSecret() {
KEYCLOAK_OPERATOR_PROVISIONER.subscribe();
try {
name = "client-secret";
RealmSelector realmSelector = new RealmSelector();
realmSelector.setMatchLabels(matchLabels);
Client client = new Client();
client.setClientId("client-secret");
client.setSecret("client-secret");
client.setClientAuthenticatorType("client-secret");
client.setProtocol("openid-connect");

KeycloakClient keycloakClient = new KeycloakClientBuilder(name, matchLabels)
.realmSelector(new LabelSelectorBuilder().withMatchLabels(matchLabels).build())
.client(new KeycloakAPIClientBuilder()
.clientId("client-secret")
.secret("client-secret")
.clientAuthenticatorType("client-secret")
.protocol("openid-connect")
.build())
.realmSelector(realmSelector)
.client(client)
.build();
verifyClient(keycloakClient);
} finally {
Expand Down Expand Up @@ -334,6 +342,8 @@ public void realmWithUsers() {
KEYCLOAK_OPERATOR_PROVISIONER.subscribe();
try {
name = "example-keycloakrealm";
InstanceSelector instanceSelector = new InstanceSelector();
instanceSelector.setMatchLabels(matchLabels);
KeycloakRealm keycloakRealm = new KeycloakRealmBuilder(name, matchLabels)
.realm(new KeycloakAPIRealmBuilder()
.id("basic")
Expand Down Expand Up @@ -361,7 +371,7 @@ public void realmWithUsers() {
.forFlow("browser")
.identityProvider("openshift-v4")
.build())
.instanceSelector(new LabelSelectorBuilder().withMatchLabels(matchLabels).build())
.instanceSelector(instanceSelector)
.build();

verifyRealm(keycloakRealm);
Expand Down Expand Up @@ -411,6 +421,8 @@ public void samlRealm() {
KEYCLOAK_OPERATOR_PROVISIONER.subscribe();
try {
name = "example-keycloakrealm";
InstanceSelector instanceSelector = new InstanceSelector();
instanceSelector.setMatchLabels(matchLabels);
KeycloakRealm keycloakRealm = new KeycloakRealmBuilder(name, matchLabels)
.realm(new KeycloakAPIRealmBuilder()
.id("saml-demo")
Expand Down Expand Up @@ -453,7 +465,7 @@ public void samlRealm() {
.protocol("saml")
.build())
.build())
.instanceSelector(new LabelSelectorBuilder().withMatchLabels(matchLabels).build())
.instanceSelector(instanceSelector)
.build();

verifyRealm(keycloakRealm);
Expand All @@ -476,6 +488,8 @@ public void openIdRealm() {
KEYCLOAK_OPERATOR_PROVISIONER.subscribe();
try {
name = "example-keycloakrealm";
InstanceSelector instanceSelector = new InstanceSelector();
instanceSelector.setMatchLabels(matchLabels);
KeycloakRealm keycloakRealm = new KeycloakRealmBuilder(name, matchLabels)
.realm(new KeycloakAPIRealmBuilder()
.id("openid-demo")
Expand Down Expand Up @@ -503,7 +517,7 @@ public void openIdRealm() {
.protocol("openid-connect")
.build())
.build())
.instanceSelector(new LabelSelectorBuilder().withMatchLabels(matchLabels).build())
.instanceSelector(instanceSelector)
.build();

verifyRealm(keycloakRealm);
Expand All @@ -528,16 +542,18 @@ public void basicUser() {
KEYCLOAK_OPERATOR_PROVISIONER.subscribe();
try {
name = "example-realm-user";
org.keycloak.v1alpha1.keycloakuserspec.RealmSelector realmSelector = new org.keycloak.v1alpha1.keycloakuserspec.RealmSelector();
realmSelector.setMatchLabels(matchLabels);
User user = new User();
user.setUsername("realm_user");
user.setFirstName("John");
user.setLastName("Doe");
user.setEmail("[email protected]");
user.setEnabled(true);
user.setEmailVerified(false);
KeycloakUser keycloakUser = new KeycloakUserBuilder(name, matchLabels)
.user(new KeycloakAPIUserBuilder()
.username("realm_user")
.firstName("John")
.lastName("Doe")
.email("[email protected]")
.enabled(true)
.emailVerified(false)
.build())
.realmSelector(new LabelSelectorBuilder().withMatchLabels(matchLabels).build())
.user(user)
.realmSelector(realmSelector)
.build();

verifyUser(keycloakUser);
Expand All @@ -547,9 +563,7 @@ public void basicUser() {
}

/**
* This test case creates and validates a {@link KeycloakUser} CR with a related
* {@link KeycloakCredential}
* instance
* This test case creates and validates a {@link KeycloakUser} CR with related credentials
*
* This is not an integration test, the goal here is to assess that the created CRs are configured as per the
* model specification.
Expand All @@ -563,20 +577,24 @@ public void userWithCredentials() {
KEYCLOAK_OPERATOR_PROVISIONER.subscribe();
try {
name = "example-realm-user-with-creds";
org.keycloak.v1alpha1.keycloakuserspec.RealmSelector realmSelector = new org.keycloak.v1alpha1.keycloakuserspec.RealmSelector();
Credentials credentials = new Credentials();
credentials.setType("password");
credentials.setValue("12345");
User user = new User();
user.setUsername("creds_user");
user.setFirstName("Creds");
user.setLastName("User");
user.setEmail("[email protected]");
user.setEnabled(true);
user.setEmailVerified(false);
user.setCredentials(Collections.singletonList(credentials));
user.setRealmRoles(Collections.singletonList("offline_access"));
user.getClientRoles().put("account", Stream.of("manage-account").collect(Collectors.toList()));
user.getClientRoles().put("realm-management", Stream.of("manage-users").collect(Collectors.toList()));
KeycloakUser keycloakUser = new KeycloakUserBuilder(name, matchLabels)
.user(new KeycloakAPIUserBuilder()
.username("creds_user")
.firstName("Creds")
.lastName("User")
.email("[email protected]")
.enabled(true)
.emailVerified(false)
.credentials(new KeycloakCredentialBuilder().type("password").value("12345").build())
.realmRoles("offline_access")
.clientRole("account", Stream.of("manage-account").collect(Collectors.toList()))
.clientRole("realm-management", Stream.of("manage-users").collect(Collectors.toList()))
.build())
.realmSelector(new LabelSelectorBuilder().withMatchLabels(matchLabels).build())
.user(user)
.realmSelector(realmSelector)
.build();

verifyUser(keycloakUser);
Expand All @@ -602,7 +620,8 @@ public void basicProvisioningTest() {
"Unexpected number of cluster operator pods for '" + KEYCLOAK_OPERATOR_PROVISIONER.getOperatorId()
+ "' after deploy");

int scaledNum = KEYCLOAK_OPERATOR_PROVISIONER.getApplication().getKeycloak().getSpec().getInstances() + 1;
int scaledNum = KEYCLOAK_OPERATOR_PROVISIONER.getApplication().getKeycloak().getSpec().getInstances().intValue()
+ 1;
KEYCLOAK_OPERATOR_PROVISIONER.scale(scaledNum, true);
Assertions.assertEquals(scaledNum, KEYCLOAK_OPERATOR_PROVISIONER.getPods().size(),
"Unexpected number of cluster operator pods for '" + KEYCLOAK_OPERATOR_PROVISIONER.getOperatorId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public class IntersmashConfig {
private static final String COMMUNITY_INFINISPAN_OPERATOR_PACKAGE_MANIFEST = "infinispan";
private static final String PRODUCT_INFINISPAN_OPERATOR_PACKAGE_MANIFEST = "datagrid";
private static final String DEFAULT_INFINISPAN_OPERATOR_PACKAGE_MANIFEST = COMMUNITY_INFINISPAN_OPERATOR_PACKAGE_MANIFEST;
private static final String RHSSO_OPERATOR_CATALOG_SOURCE_NAME = "intersmash.keycloak.operators.catalog_source";
private static final String RHSSO_OPERATOR_CATALOG_SOURCE_NAME = "intersmash.rhsso.operators.catalog_source";
private static final String KEYCLOAK_REALM_IMPORT_OPERATOR_CATALOG_SOURCE_NAME = "intersmash.keycloak.realm_import.operators.catalog_source";

private static final String RHSSO_OPERATOR_INDEX_IMAGE = "intersmash.keycloak.operators.index_image";
private static final String RHSSO_OPERATOR_INDEX_IMAGE = "intersmash.rhsso.operators.index_image";
private static final String KEYCLOAK_REALM_IMPORT_OPERATOR_INDEX_IMAGE = "intersmash.keycloak.realm_import.operators.index_image";
private static final String RHSSO_OPERATOR_CHANNEL = "intersmash.keycloak.operators.channel";
private static final String RHSSO_OPERATOR_CHANNEL = "intersmash.rhsso.operators.channel";
private static final String KEYCLOAK_REALM_IMPORT_OPERATOR_CHANNEL = "intersmash.keycloak.realm_import.operators.channel";
private static final String KEYCLOAK_OPERATOR_PACKAGE_MANIFEST = "intersmash.keycloak.operators.package_manifest";
private static final String RHSSO_OPERATOR_PACKAGE_MANIFEST = "intersmash.rhsso.operators.package_manifest";
private static final String KEYCLOAK_REALM_IMPORT_OPERATOR_PACKAGE_MANIFEST = "intersmash.keycloak.realm_import.operators.package_manifest";
private static final String COMMUNITY_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST = "keycloak-operator";
private static final String PRODUCT_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST = "rhsso-operator";
Expand Down Expand Up @@ -171,7 +171,7 @@ public static String rhSsoOperatorChannel() {
}

public static String rhSsoOperatorPackageManifest() {
return XTFConfig.get(KEYCLOAK_OPERATOR_PACKAGE_MANIFEST, DEFAULT_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST);
return XTFConfig.get(RHSSO_OPERATOR_PACKAGE_MANIFEST, PRODUCT_KEYCLOAK_OPERATOR_PACKAGE_MANIFEST);
}

public static String wildflyOperatorCatalogSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import java.util.List;

import org.jboss.intersmash.tools.application.openshift.input.BuildInput;
import org.jboss.intersmash.tools.provision.openshift.Eap7ImageOpenShiftProvisioner;

import io.fabric8.kubernetes.api.model.EnvVar;
import org.jboss.intersmash.tools.provision.openshift.Eap7ImageOpenShiftProvisioner;

/**
* End user Application descriptor interface which presents a AP 7.z (i.e. Jakarta EE 8 based WildFly) application on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
import java.util.List;

import org.jboss.intersmash.tools.provision.openshift.RhSsoOperatorProvisioner;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.backup.KeycloakBackup;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.client.KeycloakClient;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.keycloak.Keycloak;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.realm.KeycloakRealm;
import org.jboss.intersmash.tools.provision.openshift.operator.keycloak.user.KeycloakUser;
import org.keycloak.v1alpha1.Keycloak;
import org.keycloak.v1alpha1.KeycloakBackup;
import org.keycloak.v1alpha1.KeycloakClient;
import org.keycloak.v1alpha1.KeycloakRealm;
import org.keycloak.v1alpha1.KeycloakUser;

/**
* End user Application interface which presents Keycloak operator application on OpenShift Container Platform.
Expand Down
Loading

0 comments on commit 5d110c9

Please sign in to comment.