From 37a5005b3273faafdd4972c78fbceca948798ade Mon Sep 17 00:00:00 2001 From: Fedor Dudinskiy Date: Wed, 24 May 2023 17:15:55 +0200 Subject: [PATCH] Unification of all test-framework-related options Since all of them are now gathered in one place it would become easier to monitor and document them Required for potential automation of https://github.com/quarkus-qe/quarkus-test-framework/issues/369 --- .../DockerContainerManagedResource.java | 7 +- ...GenericDockerContainerManagedResource.java | 7 +- .../quarkus/test/bootstrap/BaseService.java | 9 +- .../test/configuration/Configuration.java | 125 +++++++++++++++--- .../test/configuration/PropertyLookup.java | 4 +- .../java/io/quarkus/test/logging/Log.java | 4 +- .../test/logging/ServiceLoggingHandler.java | 3 +- .../metrics/MetricsExtensionBootstrap.java | 8 +- .../quarkus/test/utils/AwaitilityUtils.java | 5 +- .../KubernetesContainerManagedResource.java | 21 ++- ...etesQuarkusApplicationManagedResource.java | 11 +- .../bootstrap/inject/OpenShiftClient.java | 14 +- .../OpenShiftContainerManagedResource.java | 18 ++- ...hiftQuarkusApplicationManagedResource.java | 12 +- ...tStrimziKafkaContainerManagedResource.java | 14 +- ...GenericDockerContainerManagedResource.java | 8 +- 16 files changed, 184 insertions(+), 86 deletions(-) diff --git a/quarkus-test-containers/src/main/java/io/quarkus/test/services/containers/DockerContainerManagedResource.java b/quarkus-test-containers/src/main/java/io/quarkus/test/services/containers/DockerContainerManagedResource.java index b0122ca8f..caceba185 100644 --- a/quarkus-test-containers/src/main/java/io/quarkus/test/services/containers/DockerContainerManagedResource.java +++ b/quarkus-test-containers/src/main/java/io/quarkus/test/services/containers/DockerContainerManagedResource.java @@ -1,6 +1,5 @@ package io.quarkus.test.services.containers; -import static io.quarkus.test.bootstrap.BaseService.SERVICE_STARTUP_TIMEOUT; import static io.quarkus.test.bootstrap.BaseService.SERVICE_STARTUP_TIMEOUT_DEFAULT; import static io.quarkus.test.utils.PropertiesUtils.RESOURCE_PREFIX; import static io.quarkus.test.utils.PropertiesUtils.RESOURCE_WITH_DESTINATION_PREFIX; @@ -24,6 +23,7 @@ import io.quarkus.test.bootstrap.ManagedResource; import io.quarkus.test.bootstrap.Protocol; import io.quarkus.test.bootstrap.ServiceContext; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.logging.LoggingHandler; import io.quarkus.test.logging.TestContainersLoggingHandler; import io.quarkus.test.services.URILike; @@ -31,7 +31,6 @@ public abstract class DockerContainerManagedResource implements ManagedResource { - private static final String DELETE_IMAGE_ON_STOP_PROPERTY = "container.delete.image.on.stop"; private static final String TARGET = "target"; private final ServiceContext context; @@ -59,7 +58,7 @@ public void start() { } innerContainer.withStartupTimeout(context.getOwner().getConfiguration() - .getAsDuration(SERVICE_STARTUP_TIMEOUT, SERVICE_STARTUP_TIMEOUT_DEFAULT)); + .getAsDuration(Configuration.Property.SERVICE_STARTUP_TIMEOUT, SERVICE_STARTUP_TIMEOUT_DEFAULT)); innerContainer.withEnv(resolveProperties()); loggingHandler = new TestContainersLoggingHandler(context.getOwner(), innerContainer); @@ -69,7 +68,7 @@ public void start() { } private boolean isDockerImageDeletedOnStop() { - return context.getOwner().getConfiguration().isTrue(DELETE_IMAGE_ON_STOP_PROPERTY); + return context.getOwner().getConfiguration().isTrue(Configuration.Property.DELETE_IMAGE_ON_STOP_PROPERTY); } protected abstract GenericContainer initContainer(); diff --git a/quarkus-test-containers/src/main/java/io/quarkus/test/services/containers/GenericDockerContainerManagedResource.java b/quarkus-test-containers/src/main/java/io/quarkus/test/services/containers/GenericDockerContainerManagedResource.java index 024021470..6cddbe26f 100644 --- a/quarkus-test-containers/src/main/java/io/quarkus/test/services/containers/GenericDockerContainerManagedResource.java +++ b/quarkus-test-containers/src/main/java/io/quarkus/test/services/containers/GenericDockerContainerManagedResource.java @@ -4,13 +4,12 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.logging.Log; import io.quarkus.test.utils.DockerUtils; public class GenericDockerContainerManagedResource extends DockerContainerManagedResource { - private static final String PRIVILEGED_MODE = "container.privileged-mode"; - private static final String REUSABLE_MODE = "container.reusable"; private final ContainerManagedResourceBuilder model; protected GenericDockerContainerManagedResource(ContainerManagedResourceBuilder model) { @@ -68,10 +67,10 @@ public void stop() { } protected boolean isReusable() { - return model.getContext().getOwner().getConfiguration().isTrue(REUSABLE_MODE); + return model.getContext().getOwner().getConfiguration().isTrue(Configuration.Property.REUSABLE_MODE); } private boolean isPrivileged() { - return model.getContext().getOwner().getConfiguration().isTrue(PRIVILEGED_MODE); + return model.getContext().getOwner().getConfiguration().isTrue(Configuration.Property.PRIVILEGED_MODE); } } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/bootstrap/BaseService.java b/quarkus-test-core/src/main/java/io/quarkus/test/bootstrap/BaseService.java index e53289648..082b701c4 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/bootstrap/BaseService.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/bootstrap/BaseService.java @@ -1,5 +1,6 @@ package io.quarkus.test.bootstrap; +import static io.quarkus.test.configuration.Configuration.Property.SERVICE_STARTUP_CHECK_POLL_INTERVAL; import static io.quarkus.test.utils.AwaitilityUtils.AwaitilitySettings; import static io.quarkus.test.utils.AwaitilityUtils.untilIsTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -27,11 +28,7 @@ public class BaseService implements Service { - public static final String SERVICE_STARTUP_TIMEOUT = "startup.timeout"; public static final Duration SERVICE_STARTUP_TIMEOUT_DEFAULT = Duration.ofMinutes(5); - public static final String DELETE_FOLDER_ON_EXIT = "delete.folder.on.exit"; - - private static final String SERVICE_STARTUP_CHECK_POLL_INTERVAL = "startup.check-poll-interval"; private static final Duration SERVICE_STARTUP_CHECK_POLL_INTERVAL_DEFAULT = Duration.ofSeconds(2); protected ServiceContext context; @@ -224,7 +221,7 @@ public void stop() { public void close() { if (!context.getScenarioContext().isDebug()) { stop(); - if (getConfiguration().isTrue(DELETE_FOLDER_ON_EXIT)) { + if (getConfiguration().isTrue(Configuration.Property.DELETE_FOLDER_ON_EXIT)) { try { FileUtils.deletePath(getServiceFolder()); } catch (Exception ex) { @@ -296,7 +293,7 @@ private void waitUntilServiceIsStarted() { Duration startupCheckInterval = getConfiguration() .getAsDuration(SERVICE_STARTUP_CHECK_POLL_INTERVAL, SERVICE_STARTUP_CHECK_POLL_INTERVAL_DEFAULT); Duration startupTimeout = getConfiguration() - .getAsDuration(SERVICE_STARTUP_TIMEOUT, SERVICE_STARTUP_TIMEOUT_DEFAULT); + .getAsDuration(Configuration.Property.SERVICE_STARTUP_TIMEOUT, SERVICE_STARTUP_TIMEOUT_DEFAULT); untilIsTrue(this::isRunningOrFailed, AwaitilitySettings .using(startupCheckInterval, startupTimeout) .doNotIgnoreExceptions() diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/configuration/Configuration.java b/quarkus-test-core/src/main/java/io/quarkus/test/configuration/Configuration.java index c1626d9e5..ca4fd044d 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/configuration/Configuration.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/configuration/Configuration.java @@ -2,31 +2,36 @@ import java.io.InputStream; import java.time.Duration; +import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; +import java.util.EnumMap; import java.util.List; -import java.util.Map; import java.util.Map.Entry; +import java.util.NoSuchElementException; +import java.util.Optional; import java.util.Properties; import java.util.stream.Collectors; import java.util.stream.Stream; +import jakarta.annotation.Nullable; + import org.apache.commons.lang3.StringUtils; public final class Configuration { private static final String GLOBAL_PROPERTIES = System.getProperty("ts.test.resources.file.location", "global.properties"); private static final String TEST_PROPERTIES = "test.properties"; - private static final String PREFIX_TEMPLATE = "ts.%s."; + private static final String PREFIX = "ts."; + private static final String PREFIX_TEMPLATE = PREFIX + "%s."; private static final String GLOBAL_SCOPE = "global"; - private final Map properties; + private final EnumMap properties; - private Configuration(Map properties) { + private Configuration(EnumMap properties) { this.properties = properties; } - public List getAsList(String property) { + public List getAsList(Property property) { String value = get(property); if (StringUtils.isEmpty(value)) { return Collections.emptyList(); @@ -35,7 +40,7 @@ public List getAsList(String property) { return Stream.of(value.split(",")).collect(Collectors.toList()); } - public Duration getAsDuration(String property, Duration defaultValue) { + public Duration getAsDuration(Property property, Duration defaultValue) { String value = get(property); if (StringUtils.isEmpty(value)) { return defaultValue; @@ -48,7 +53,7 @@ public Duration getAsDuration(String property, Duration defaultValue) { return Duration.parse(value); } - public Double getAsDouble(String property, double defaultValue) { + public Double getAsDouble(Property property, double defaultValue) { String value = get(property); if (StringUtils.isEmpty(value)) { return defaultValue; @@ -57,24 +62,24 @@ public Double getAsDouble(String property, double defaultValue) { return Double.parseDouble(value); } - public String get(String property) { + public String get(Property property) { return properties.get(property); } - public String getOrDefault(String property, String defaultValue) { + public String getOrDefault(Property property, String defaultValue) { return properties.getOrDefault(property, defaultValue); } - public boolean isTrue(String property) { + public boolean isTrue(Property property) { return is(property, Boolean.TRUE.toString()); } - public boolean is(String property, String expected) { + public boolean is(Property property, String expected) { return StringUtils.equalsIgnoreCase(properties.get(property), expected); } public static Configuration load() { - Map properties = new HashMap<>(); + EnumMap properties = new EnumMap<>(Property.class); // Lowest priority: properties from global.properties and scope `global` properties.putAll(loadPropertiesFrom(GLOBAL_PROPERTIES, GLOBAL_SCOPE)); // Then, properties from system properties and scope `global` @@ -95,32 +100,108 @@ public static Configuration load(String serviceName) { return configuration; } - private static Map loadPropertiesFromSystemProperties(String scope) { + private static EnumMap loadPropertiesFromSystemProperties(String scope) { return loadPropertiesFrom(System.getProperties(), scope); } - private static Map loadPropertiesFrom(String propertiesFile, String scope) { + private static EnumMap loadPropertiesFrom(String propertiesFile, String scope) { try (InputStream input = Configuration.class.getClassLoader().getResourceAsStream(propertiesFile)) { Properties prop = new Properties(); prop.load(input); return loadPropertiesFrom(prop, scope); - } catch (Exception ignored) { - // There is no properties file: this is not mandatory. + } catch (Exception exception) { + if (exception instanceof NullPointerException && exception.getMessage().equals("inStream parameter is null")) { + System.out.println("No properties file: " + propertiesFile); + } else { + throw new IllegalStateException(exception); + } } - return Collections.emptyMap(); + return new EnumMap<>(Property.class); } - private static Map loadPropertiesFrom(Properties prop, String scope) { - Map properties = new HashMap<>(); + private static EnumMap loadPropertiesFrom(Properties prop, String scope) { + EnumMap properties = new EnumMap<>(Property.class); + String prefix = String.format(PREFIX_TEMPLATE, scope); for (Entry entry : prop.entrySet()) { String key = (String) entry.getKey(); if (StringUtils.startsWith(key, prefix)) { - properties.put(key.replace(prefix, StringUtils.EMPTY), (String) entry.getValue()); + String property = key.replace(prefix, StringUtils.EMPTY); + properties.put(Property.byName(property), (String) entry.getValue()); } } - return properties; } + + public enum Property { //todo search for uses + RESOURCES_FILE_LOCATION("resources.file.location"), + SERVICE_STARTUP_TIMEOUT("startup.timeout"), + DELETE_FOLDER_ON_EXIT("delete.folder.on.exit"), + SERVICE_STARTUP_CHECK_POLL_INTERVAL("startup.check-poll-interval"), + TIMEOUT_FACTOR_PROPERTY("factor.timeout"), + KUBERNETES_DEPLOYMENT_SERVICE_PROPERTY("kubernetes.service"), + KUBERNETES_DEPLOYMENT_TEMPLATE_PROPERTY("kubernetes.template"), + KUBERNETES_USE_INTERNAL_SERVICE_AS_URL_PROPERTY("kubernetes.use-internal-service-as-url"), + OPENSHIFT_DEPLOYMENT_SERVICE_PROPERTY("openshift.service"), + OPENSHIFT_DEPLOYMENT_TEMPLATE_PROPERTY("openshift.template"), + OPENSHIFT_USE_INTERNAL_SERVICE_AS_URL_PROPERTY("openshift.use-internal-service-as-url"), + + DELETE_IMAGE_ON_STOP_PROPERTY("container.delete.image.on.stop"), + IMAGE_STREAM_TIMEOUT("imagestream.install.timeout"), + OPERATOR_INSTALL_TIMEOUT("operator.install.timeout"), + + CREATE_SERVICE_BY_DEFAULT("generated-service.enabled"), + PROPAGATE_PROPERTIES_STRATEGY("maven.propagate-properties-strategy"), + PROPAGATE_PROPERTIES_STRATEGY_ALL_EXCLUSIONS("maven.propagate-properties-strategy.all.exclude"), + PRIVILEGED_MODE("container.privileged-mode"), + REUSABLE_MODE("container.reusable"), + EXPECTED_OUTPUT("quarkus.expected.log"), + PORT_RANGE_MIN("port.range.min"), + PORT_RANGE_MAX("port.range.max"), + PORT_RESOLUTION_STRATEGY("port.resolution.strategy"), + + METRICS_EXTENSION_ENABLED_PROPERTY("metrics.enabled"), + METRICS_PUSH_AFTER_EACH_TEST("metrics.push-after-each-test"), + METRICS_EXPORT_PROMETHEUS_PROPERTY("metrics.export.prometheus.endpoint"), + JAEGER_HTTP_ENDPOINT_SYSTEM_PROPERTY("tracing.jaeger.endpoint"), + + LOG_ENABLE("log.enable"), + LOG_LEVEL_NAME("log.level"), + LOG_FORMAT("log.format"), + LOG_FILE_OUTPUT("log.file.output"), + LOG_NOCOLOR("log.nocolor"); + + private final String name; + + Property(String name) { + this.name = name; + } + + public String getName(@Nullable String scope) { + String scopePart = ""; + if (scope != null) { + scopePart = scope + "."; + } + return PREFIX + scopePart + name; + } + + public String getName() { + return name; + } + + public static Optional getByName(String requested) { + return Arrays.stream(Property.values()) + .filter(property -> property.name.equals(requested)) + .findAny(); + } + + static Property byName(String requested) { + return getByName(requested).orElseThrow(() -> new NoSuchElementException("Unknown property: " + requested)); + } + + public static boolean isKnownProperty(String toCheck) { + return Arrays.stream(Property.values()).map(property -> property.name).anyMatch(name -> name.equals(toCheck)); + } + } } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/configuration/PropertyLookup.java b/quarkus-test-core/src/main/java/io/quarkus/test/configuration/PropertyLookup.java index 8fa2735d0..54770885f 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/configuration/PropertyLookup.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/configuration/PropertyLookup.java @@ -37,7 +37,7 @@ public String get(ServiceContext service) { } // Or from test.properties - value = service.getOwner().getConfiguration().get(propertyKey); + value = Configuration.Property.getByName(propertyKey).map(GLOBAL::get).orElse(""); if (StringUtils.isNotBlank(value)) { return value; } @@ -50,7 +50,7 @@ public String get(ServiceContext service) { public String get() { // Try first using the Configuration API - String value = GLOBAL.get(propertyKey); + String value = Configuration.Property.getByName(propertyKey).map(GLOBAL::get).orElse(""); if (StringUtils.isNotBlank(value)) { return value; } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/logging/Log.java b/quarkus-test-core/src/main/java/io/quarkus/test/logging/Log.java index babc5e67c..2e749a601 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/logging/Log.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/logging/Log.java @@ -23,6 +23,7 @@ import io.quarkus.test.bootstrap.QuarkusScenarioBootstrap; import io.quarkus.test.bootstrap.ScenarioContext; import io.quarkus.test.bootstrap.Service; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.configuration.PropertyLookup; public final class Log { @@ -32,7 +33,6 @@ public final class Log { public static final PropertyLookup LOG_NOCOLOR = new PropertyLookup("log.nocolor", "false"); public static final String LOG_SUFFIX = ".log"; - public static final String LOG_LEVEL_NAME = "log.level"; private static final Service NO_SERVICE = null; private static final String COLOR_RESET = "\u001b[0m"; @@ -142,7 +142,7 @@ private static void log(Service service, Level level, String msg, Object... args private static boolean isServiceLogLevelAllowed(Service service, Level level) { boolean enabled = true; if (Objects.nonNull(service) && Objects.nonNull(service.getConfiguration())) { - String serviceLogLevel = service.getConfiguration().getOrDefault(LOG_LEVEL_NAME, EMPTY); + String serviceLogLevel = service.getConfiguration().getOrDefault(Configuration.Property.LOG_LEVEL_NAME, EMPTY); if (!serviceLogLevel.isEmpty()) { enabled = Level.parse(serviceLogLevel).intValue() <= level.intValue(); } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/logging/ServiceLoggingHandler.java b/quarkus-test-core/src/main/java/io/quarkus/test/logging/ServiceLoggingHandler.java index 9936dfd41..34aa7cb01 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/logging/ServiceLoggingHandler.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/logging/ServiceLoggingHandler.java @@ -1,6 +1,7 @@ package io.quarkus.test.logging; import io.quarkus.test.bootstrap.Service; +import io.quarkus.test.configuration.Configuration; public abstract class ServiceLoggingHandler extends LoggingHandler { @@ -17,7 +18,7 @@ protected void logInfo(String line) { @Override protected boolean isLogEnabled() { - return service.getConfiguration().isTrue("log.enable"); + return service.getConfiguration().isTrue(Configuration.Property.LOG_ENABLE); } } diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/metrics/MetricsExtensionBootstrap.java b/quarkus-test-core/src/main/java/io/quarkus/test/metrics/MetricsExtensionBootstrap.java index ee5b8e33e..9a66bd266 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/metrics/MetricsExtensionBootstrap.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/metrics/MetricsExtensionBootstrap.java @@ -9,10 +9,10 @@ public class MetricsExtensionBootstrap implements ExtensionBootstrap { - private static final PropertyLookup METRICS_EXTENSION_ENABLED_PROPERTY = new PropertyLookup( - "metrics.enabled", "true"); - private static final PropertyLookup METRICS_PUSH_AFTER_EACH_TEST = new PropertyLookup( - "metrics.push-after-each-test", "false"); + private static final PropertyLookup METRICS_EXTENSION_ENABLED_PROPERTY = new PropertyLookup("metrics.enabled", + "true"); + private static final PropertyLookup METRICS_PUSH_AFTER_EACH_TEST = new PropertyLookup("metrics.push-after-each-test", + "false"); private final boolean extensionEnabled; diff --git a/quarkus-test-core/src/main/java/io/quarkus/test/utils/AwaitilityUtils.java b/quarkus-test-core/src/main/java/io/quarkus/test/utils/AwaitilityUtils.java index 802a19405..411a28bbf 100644 --- a/quarkus-test-core/src/main/java/io/quarkus/test/utils/AwaitilityUtils.java +++ b/quarkus-test-core/src/main/java/io/quarkus/test/utils/AwaitilityUtils.java @@ -17,6 +17,7 @@ import org.hamcrest.Matchers; import io.quarkus.test.bootstrap.Service; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.logging.Log; /** @@ -24,7 +25,6 @@ */ public final class AwaitilityUtils { - private static final String TIMEOUT_FACTOR_PROPERTY = "factor.timeout"; private static final int POLL_SECONDS = 1; private static final int TIMEOUT_SECONDS = 30; @@ -174,7 +174,8 @@ private static ConditionFactory awaits(AwaitilitySettings settings) { private static long timeoutInSeconds(AwaitilitySettings settings) { double timeoutFactor = 1.0; if (settings.service != null) { - timeoutFactor = settings.service.getConfiguration().getAsDouble(TIMEOUT_FACTOR_PROPERTY, timeoutFactor); + timeoutFactor = settings.service.getConfiguration() + .getAsDouble(Configuration.Property.TIMEOUT_FACTOR_PROPERTY, timeoutFactor); } return Math.round(settings.timeout.toSeconds() * timeoutFactor); diff --git a/quarkus-test-kubernetes/src/main/java/io/quarkus/test/services/containers/KubernetesContainerManagedResource.java b/quarkus-test-kubernetes/src/main/java/io/quarkus/test/services/containers/KubernetesContainerManagedResource.java index 3bf9065ed..4c55a2729 100644 --- a/quarkus-test-kubernetes/src/main/java/io/quarkus/test/services/containers/KubernetesContainerManagedResource.java +++ b/quarkus-test-kubernetes/src/main/java/io/quarkus/test/services/containers/KubernetesContainerManagedResource.java @@ -1,5 +1,8 @@ package io.quarkus.test.services.containers; +import static io.quarkus.test.configuration.Configuration.Property.KUBERNETES_DEPLOYMENT_SERVICE_PROPERTY; +import static io.quarkus.test.configuration.Configuration.Property.KUBERNETES_DEPLOYMENT_TEMPLATE_PROPERTY; +import static io.quarkus.test.configuration.Configuration.Property.KUBERNETES_USE_INTERNAL_SERVICE_AS_URL_PROPERTY; import static java.util.regex.Pattern.quote; import java.util.List; @@ -10,15 +13,13 @@ import io.quarkus.test.bootstrap.ManagedResource; import io.quarkus.test.bootstrap.Protocol; import io.quarkus.test.bootstrap.inject.KubectlClient; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.logging.KubernetesLoggingHandler; import io.quarkus.test.logging.LoggingHandler; import io.quarkus.test.services.URILike; public class KubernetesContainerManagedResource implements ManagedResource { - private static final String DEPLOYMENT_SERVICE_PROPERTY = "kubernetes.service"; - private static final String DEPLOYMENT_TEMPLATE_PROPERTY = "kubernetes.template"; - private static final String USE_INTERNAL_SERVICE_AS_URL_PROPERTY = "kubernetes.use-internal-service-as-url"; private static final String DEPLOYMENT_TEMPLATE_PROPERTY_DEFAULT = "/kubernetes-deployment-template.yml"; private static final String DEPLOYMENT = "kubernetes.yml"; @@ -88,14 +89,15 @@ public List logs() { } private void applyDeployment() { - String deploymentFile = model.getContext().getOwner().getConfiguration().getOrDefault(DEPLOYMENT_TEMPLATE_PROPERTY, - DEPLOYMENT_TEMPLATE_PROPERTY_DEFAULT); + String deploymentFile = getConfiguration() + .getOrDefault(KUBERNETES_DEPLOYMENT_TEMPLATE_PROPERTY, + DEPLOYMENT_TEMPLATE_PROPERTY_DEFAULT); client.applyServiceProperties(model.getContext().getOwner(), deploymentFile, this::replaceDeploymentContent, model.getContext().getServiceFolder().resolve(DEPLOYMENT)); } private String replaceDeploymentContent(String content) { - String customServiceName = model.getContext().getOwner().getConfiguration().get(DEPLOYMENT_SERVICE_PROPERTY); + String customServiceName = getConfiguration().get(KUBERNETES_DEPLOYMENT_SERVICE_PROPERTY); if (StringUtils.isNotEmpty(customServiceName)) { // replace it by the service owner name content = content.replaceAll(quote(customServiceName), model.getContext().getName()); @@ -109,6 +111,11 @@ private String replaceDeploymentContent(String content) { private boolean useInternalServiceAsUrl() { return Boolean.TRUE.toString() - .equals(model.getContext().getOwner().getConfiguration().get(USE_INTERNAL_SERVICE_AS_URL_PROPERTY)); + .equals(getConfiguration() + .get(KUBERNETES_USE_INTERNAL_SERVICE_AS_URL_PROPERTY)); + } + + private Configuration getConfiguration() { + return model.getContext().getOwner().getConfiguration(); } } diff --git a/quarkus-test-kubernetes/src/main/java/io/quarkus/test/services/quarkus/ContainerRegistryKubernetesQuarkusApplicationManagedResource.java b/quarkus-test-kubernetes/src/main/java/io/quarkus/test/services/quarkus/ContainerRegistryKubernetesQuarkusApplicationManagedResource.java index 21fc73004..7cd1ed286 100644 --- a/quarkus-test-kubernetes/src/main/java/io/quarkus/test/services/quarkus/ContainerRegistryKubernetesQuarkusApplicationManagedResource.java +++ b/quarkus-test-kubernetes/src/main/java/io/quarkus/test/services/quarkus/ContainerRegistryKubernetesQuarkusApplicationManagedResource.java @@ -9,13 +9,12 @@ import org.apache.commons.lang3.StringUtils; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.utils.DockerUtils; public class ContainerRegistryKubernetesQuarkusApplicationManagedResource extends KubernetesQuarkusApplicationManagedResource { - private static final String DEPLOYMENT_SERVICE_PROPERTY = "kubernetes.service"; - private static final String DEPLOYMENT_TEMPLATE_PROPERTY = "kubernetes.template"; private static final String QUARKUS_KUBERNETES_TEMPLATE = "/quarkus-app-kubernetes-template.yml"; private static final String DEPLOYMENT = "kubernetes.yml"; @@ -46,8 +45,9 @@ private String createImageAndPush() { } private void loadDeployment() { - String deploymentFile = model.getContext().getOwner().getConfiguration().getOrDefault(DEPLOYMENT_TEMPLATE_PROPERTY, - QUARKUS_KUBERNETES_TEMPLATE); + String deploymentFile = model.getContext().getOwner().getConfiguration() + .getOrDefault(Configuration.Property.KUBERNETES_DEPLOYMENT_TEMPLATE_PROPERTY, + QUARKUS_KUBERNETES_TEMPLATE); client.applyServiceProperties(model.getContext().getOwner(), deploymentFile, this::replaceDeploymentContent, addExtraTemplateProperties(), @@ -55,7 +55,8 @@ private void loadDeployment() { } private String replaceDeploymentContent(String content) { - String customServiceName = model.getContext().getOwner().getConfiguration().get(DEPLOYMENT_SERVICE_PROPERTY); + String customServiceName = model.getContext().getOwner().getConfiguration() + .get(Configuration.Property.KUBERNETES_DEPLOYMENT_SERVICE_PROPERTY); if (StringUtils.isNotEmpty(customServiceName)) { // replace it by the service owner name content = content.replaceAll(quote(customServiceName), model.getContext().getName()); diff --git a/quarkus-test-openshift/src/main/java/io/quarkus/test/bootstrap/inject/OpenShiftClient.java b/quarkus-test-openshift/src/main/java/io/quarkus/test/bootstrap/inject/OpenShiftClient.java index 50724a471..fb65f9c3a 100644 --- a/quarkus-test-openshift/src/main/java/io/quarkus/test/bootstrap/inject/OpenShiftClient.java +++ b/quarkus-test-openshift/src/main/java/io/quarkus/test/bootstrap/inject/OpenShiftClient.java @@ -1,5 +1,6 @@ package io.quarkus.test.bootstrap.inject; +import static io.quarkus.test.configuration.Configuration.Property.IMAGE_STREAM_TIMEOUT; import static io.quarkus.test.model.CustomVolume.VolumeType.CONFIG_MAP; import static io.quarkus.test.model.CustomVolume.VolumeType.SECRET; import static io.quarkus.test.utils.AwaitilityUtils.AwaitilitySettings; @@ -67,6 +68,7 @@ import io.fabric8.openshift.client.OpenShiftConfigBuilder; import io.fabric8.openshift.client.impl.OpenShiftClientImpl; import io.quarkus.test.bootstrap.Service; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.configuration.PropertyLookup; import io.quarkus.test.logging.Log; import io.quarkus.test.model.CustomVolume; @@ -84,8 +86,7 @@ public final class OpenShiftClient { "ts.openshift.ephemeral.namespaces.enabled", Boolean.TRUE.toString()); private static final Logger LOG = Logger.getLogger(OpenShiftClient.class); - private static final String IMAGE_STREAM_TIMEOUT = "imagestream.install.timeout"; - private static final String OPERATOR_INSTALL_TIMEOUT = "operator.install.timeout"; + private static final Duration TIMEOUT_DEFAULT = Duration.ofMinutes(5); private static final int PROJECT_NAME_SIZE = 10; private static final int PROJECT_CREATION_RETRIES = 5; @@ -449,9 +450,11 @@ public void awaitFor(Service service, Path file) { && !StringUtils.equals(obj.getMetadata().getName(), service.getName())) { ImageStream is = (ImageStream) obj; untilIsTrue(() -> hasImageStreamTags(is), - AwaitilitySettings.defaults().withService(service) + AwaitilitySettings.defaults() + .withService(service) .usingTimeout( - service.getConfiguration().getAsDuration(IMAGE_STREAM_TIMEOUT, TIMEOUT_DEFAULT))); + service.getConfiguration() + .getAsDuration(IMAGE_STREAM_TIMEOUT, TIMEOUT_DEFAULT))); } } } catch (IOException e) { @@ -504,7 +507,8 @@ public void installOperator(Service service, String name, String channel, String }, AwaitilitySettings .defaults() .withService(service) - .usingTimeout(service.getConfiguration().getAsDuration(OPERATOR_INSTALL_TIMEOUT, TIMEOUT_DEFAULT))); + .usingTimeout(service.getConfiguration() + .getAsDuration(Configuration.Property.OPERATOR_INSTALL_TIMEOUT, TIMEOUT_DEFAULT))); Log.info("Operator installed... %s", service.getName()); } diff --git a/quarkus-test-openshift/src/main/java/io/quarkus/test/services/containers/OpenShiftContainerManagedResource.java b/quarkus-test-openshift/src/main/java/io/quarkus/test/services/containers/OpenShiftContainerManagedResource.java index 05f91f406..da0f5d171 100644 --- a/quarkus-test-openshift/src/main/java/io/quarkus/test/services/containers/OpenShiftContainerManagedResource.java +++ b/quarkus-test-openshift/src/main/java/io/quarkus/test/services/containers/OpenShiftContainerManagedResource.java @@ -10,15 +10,13 @@ import io.quarkus.test.bootstrap.OpenShiftExtensionBootstrap; import io.quarkus.test.bootstrap.Protocol; import io.quarkus.test.bootstrap.inject.OpenShiftClient; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.logging.LoggingHandler; import io.quarkus.test.logging.OpenShiftLoggingHandler; import io.quarkus.test.services.URILike; public class OpenShiftContainerManagedResource implements ManagedResource { - private static final String DEPLOYMENT_SERVICE_PROPERTY = "openshift.service"; - private static final String DEPLOYMENT_TEMPLATE_PROPERTY = "openshift.template"; - private static final String USE_INTERNAL_SERVICE_AS_URL_PROPERTY = "openshift.use-internal-service-as-url"; private static final String DEPLOYMENT_TEMPLATE_PROPERTY_DEFAULT = "/openshift-deployment-template.yml"; private static final String DEPLOYMENT = "openshift.yml"; @@ -112,8 +110,13 @@ protected OpenShiftClient getClient() { return client; } + private Configuration getConfiguration() { + return model.getContext().getOwner().getConfiguration(); + } + protected String replaceDeploymentContent(String content) { - String customServiceName = model.getContext().getOwner().getConfiguration().get(DEPLOYMENT_SERVICE_PROPERTY); + String customServiceName = getConfiguration() + .get(Configuration.Property.OPENSHIFT_DEPLOYMENT_SERVICE_PROPERTY); if (StringUtils.isNotEmpty(customServiceName)) { // replace it by the service owner name content = content.replaceAll(quote(customServiceName), model.getContext().getOwner().getName()); @@ -126,7 +129,7 @@ protected String replaceDeploymentContent(String content) { } private void applyDeployment() { - String deploymentFile = model.getContext().getOwner().getConfiguration().getOrDefault(DEPLOYMENT_TEMPLATE_PROPERTY, + String deploymentFile = getConfiguration().getOrDefault(Configuration.Property.OPENSHIFT_DEPLOYMENT_TEMPLATE_PROPERTY, getTemplateByDefault()); client.applyServicePropertiesUsingTemplate(model.getContext().getOwner(), deploymentFile, this::replaceDeploymentContent, @@ -135,8 +138,9 @@ private void applyDeployment() { private boolean useInternalServiceAsUrl() { return Boolean.TRUE.toString() - .equals(model.getContext().getOwner().getConfiguration() - .getOrDefault(USE_INTERNAL_SERVICE_AS_URL_PROPERTY, "" + useInternalServiceByDefault())); + .equals(getConfiguration() + .getOrDefault(Configuration.Property.OPENSHIFT_USE_INTERNAL_SERVICE_AS_URL_PROPERTY, + "" + useInternalServiceByDefault())); } } diff --git a/quarkus-test-openshift/src/main/java/io/quarkus/test/services/quarkus/TemplateOpenShiftQuarkusApplicationManagedResource.java b/quarkus-test-openshift/src/main/java/io/quarkus/test/services/quarkus/TemplateOpenShiftQuarkusApplicationManagedResource.java index 454653007..bce225c34 100644 --- a/quarkus-test-openshift/src/main/java/io/quarkus/test/services/quarkus/TemplateOpenShiftQuarkusApplicationManagedResource.java +++ b/quarkus-test-openshift/src/main/java/io/quarkus/test/services/quarkus/TemplateOpenShiftQuarkusApplicationManagedResource.java @@ -7,13 +7,12 @@ import org.apache.commons.lang3.StringUtils; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.logging.Log; public abstract class TemplateOpenShiftQuarkusApplicationManagedResource extends OpenShiftQuarkusApplicationManagedResource { - private static final String DEPLOYMENT_SERVICE_PROPERTY = "openshift.service"; - private static final String DEPLOYMENT_TEMPLATE_PROPERTY = "openshift.template"; private static final String DEPLOYMENT = "openshift.yml"; private static final String QUARKUS_HTTP_PORT_PROPERTY = "quarkus.http.port"; @@ -52,8 +51,9 @@ protected Map addExtraTemplateProperties() { } private void applyTemplate() { - String deploymentFile = model.getContext().getOwner().getConfiguration().getOrDefault(DEPLOYMENT_TEMPLATE_PROPERTY, - getDefaultTemplate()); + String deploymentFile = model.getContext().getOwner().getConfiguration() + .getOrDefault(Configuration.Property.OPENSHIFT_DEPLOYMENT_TEMPLATE_PROPERTY, + getDefaultTemplate()); client.applyServicePropertiesUsingTemplate(model.getContext().getOwner(), deploymentFile, this::internalReplaceDeploymentContent, @@ -62,7 +62,9 @@ private void applyTemplate() { } private String internalReplaceDeploymentContent(String content) { - String customServiceName = model.getContext().getOwner().getConfiguration().get(DEPLOYMENT_SERVICE_PROPERTY); + String customServiceName = model.getContext().getOwner() + .getConfiguration() + .get(Configuration.Property.OPENSHIFT_DEPLOYMENT_SERVICE_PROPERTY); if (StringUtils.isNotEmpty(customServiceName)) { // replace it by the service owner name content = content.replaceAll(quote(customServiceName), model.getContext().getOwner().getName()); diff --git a/quarkus-test-service-kafka/src/main/java/io/quarkus/test/services/containers/OpenShiftStrimziKafkaContainerManagedResource.java b/quarkus-test-service-kafka/src/main/java/io/quarkus/test/services/containers/OpenShiftStrimziKafkaContainerManagedResource.java index 337c52fa6..cd86d29fa 100644 --- a/quarkus-test-service-kafka/src/main/java/io/quarkus/test/services/containers/OpenShiftStrimziKafkaContainerManagedResource.java +++ b/quarkus-test-service-kafka/src/main/java/io/quarkus/test/services/containers/OpenShiftStrimziKafkaContainerManagedResource.java @@ -13,6 +13,7 @@ import io.quarkus.test.bootstrap.OpenShiftExtensionBootstrap; import io.quarkus.test.bootstrap.Protocol; import io.quarkus.test.bootstrap.inject.OpenShiftClient; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.logging.LoggingHandler; import io.quarkus.test.logging.OpenShiftLoggingHandler; import io.quarkus.test.services.URILike; @@ -20,8 +21,6 @@ public class OpenShiftStrimziKafkaContainerManagedResource implements ManagedResource { - private static final String DEPLOYMENT_SERVICE_PROPERTY = "openshift.service"; - private static final String DEPLOYMENT_TEMPLATE_PROPERTY = "openshift.template"; private static final String DEPLOYMENT_TEMPLATE_PROPERTY_DEFAULT = "/strimzi-deployment-template.yml"; private static final String DEPLOYMENT = "kafka.yml"; @@ -124,8 +123,9 @@ private void createRegistryService() { } private void applyDeployment() { - String deploymentFile = model.getContext().getOwner().getConfiguration().getOrDefault(DEPLOYMENT_TEMPLATE_PROPERTY, - DEPLOYMENT_TEMPLATE_PROPERTY_DEFAULT); + String deploymentFile = getConfiguration() + .getOrDefault(Configuration.Property.OPENSHIFT_DEPLOYMENT_TEMPLATE_PROPERTY, + DEPLOYMENT_TEMPLATE_PROPERTY_DEFAULT); client.applyServicePropertiesUsingTemplate(model.getContext().getOwner(), deploymentFile, this::replaceDeploymentContent, model.getContext().getServiceFolder().resolve(DEPLOYMENT)); @@ -156,8 +156,12 @@ private String getKafkaBootstrapUrl() { return host.getHost() + ":" + host.getPort(); } + private Configuration getConfiguration() { + return model.getContext().getOwner().getConfiguration(); + } + private String replaceDeploymentContent(String content) { - String customServiceName = model.getContext().getOwner().getConfiguration().get(DEPLOYMENT_SERVICE_PROPERTY); + String customServiceName = getConfiguration().get(Configuration.Property.OPENSHIFT_DEPLOYMENT_SERVICE_PROPERTY); if (StringUtils.isNotEmpty(customServiceName)) { // replace it by the service owner name content = content.replaceAll(quote(customServiceName), model.getContext().getOwner().getName()); diff --git a/quarkus-test-service-keycloak/src/main/java/io/quarkus/test/services/containers/KeycloakGenericDockerContainerManagedResource.java b/quarkus-test-service-keycloak/src/main/java/io/quarkus/test/services/containers/KeycloakGenericDockerContainerManagedResource.java index d61be93c4..c549155b7 100644 --- a/quarkus-test-service-keycloak/src/main/java/io/quarkus/test/services/containers/KeycloakGenericDockerContainerManagedResource.java +++ b/quarkus-test-service-keycloak/src/main/java/io/quarkus/test/services/containers/KeycloakGenericDockerContainerManagedResource.java @@ -4,14 +4,12 @@ import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; +import io.quarkus.test.configuration.Configuration; import io.quarkus.test.logging.Log; import io.quarkus.test.utils.DockerUtils; public class KeycloakGenericDockerContainerManagedResource extends GenericDockerContainerManagedResource { - private static final String PRIVILEGED_MODE = "container.privileged-mode"; - private static final String REUSABLE_MODE = "container.reusable"; - private final KeycloakContainerManagedResourceBuilder model; protected KeycloakGenericDockerContainerManagedResource(KeycloakContainerManagedResourceBuilder model) { @@ -60,10 +58,10 @@ public void stop() { } protected boolean isReusable() { - return model.getContext().getOwner().getConfiguration().isTrue(REUSABLE_MODE); + return model.getContext().getOwner().getConfiguration().isTrue(Configuration.Property.REUSABLE_MODE); } private boolean isPrivileged() { - return model.getContext().getOwner().getConfiguration().isTrue(PRIVILEGED_MODE); + return model.getContext().getOwner().getConfiguration().isTrue(Configuration.Property.PRIVILEGED_MODE); } }