KEYCLOAK-5040 ProfileAssume needs to use server info endpoint

This commit is contained in:
Marko Strukelj 2017-11-09 11:17:04 +01:00 committed by Stian Thorgersen
parent 19eed51582
commit dae0fafc8a

View file

@ -18,26 +18,58 @@
package org.keycloak.testsuite; package org.keycloak.testsuite;
import org.junit.Assume; import org.junit.Assume;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.common.Profile; import org.keycloak.common.Profile;
import org.keycloak.representations.info.ProfileInfoRepresentation;
import org.keycloak.testsuite.util.AdminClientUtil;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** /**
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a> * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
*/ */
public class ProfileAssume { public class ProfileAssume {
private static Set<String> disabledFeatures;
private static String profile;
static {
String host = System.getProperty("auth.server.host", "localhost");
String port = System.getProperty("auth.server.http.port", "8180");
String authServerContextRoot = "http://" + host + ":" + port;
try {
Keycloak adminClient = AdminClientUtil.createAdminClient(false, authServerContextRoot);
ProfileInfoRepresentation profileInfo = adminClient.serverInfo().getInfo().getProfileInfo();
profile = profileInfo.getName();
List<String> disabled = profileInfo.getDisabledFeatures();
disabledFeatures = Collections.unmodifiableSet(new HashSet(disabled));
adminClient.close();
} catch (Exception e) {
throw new RuntimeException("Failed to obtain profile / features info from serverinfo endpoint of " + authServerContextRoot, e);
}
}
public static void assumeFeatureEnabled(Profile.Feature feature) { public static void assumeFeatureEnabled(Profile.Feature feature) {
Assume.assumeTrue("Ignoring test as " + feature.name() + " is not enabled", Profile.isFeatureEnabled(feature)); Assume.assumeTrue("Ignoring test as " + feature.name() + " is not enabled", isFeatureEnabled(feature));
} }
public static void assumePreview() { public static void assumePreview() {
Assume.assumeTrue("Ignoring test as community/preview profile is not enabled", !Profile.getName().equals("product")); Assume.assumeTrue("Ignoring test as community/preview profile is not enabled", !profile.equals("product"));
} }
public static void assumePreviewDisabled() { public static void assumePreviewDisabled() {
Assume.assumeFalse("Ignoring test as community/preview profile is enabled", !Profile.getName().equals("product")); Assume.assumeFalse("Ignoring test as community/preview profile is enabled", !profile.equals("product"));
} }
public static void assumeCommunity() { public static void assumeCommunity() {
Assume.assumeTrue("Ignoring test as community profile is not enabled", Profile.getName().equals("community")); Assume.assumeTrue("Ignoring test as community profile is not enabled", profile.equals("community"));
}
private static boolean isFeatureEnabled(Profile.Feature feature) {
return !disabledFeatures.contains(feature.name());
} }
} }