001/*
002 * Copyright © 2025 CUI-OpenSource-Software (info@cuioss.de)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package de.cuioss.benchmarking.common.config;
017
018import static de.cuioss.benchmarking.common.constants.BenchmarkConstants.Integration.Properties;
019import static de.cuioss.benchmarking.common.repository.TokenRepositoryConfig.requireProperty;
020
021/**
022 * Configuration for integration benchmark scenarios.
023 * Handles URLs and connection details for external services used in integration testing.
024 * 
025 * <p>Example usage:
026 * <pre>{@code
027 * var integrationConfig = IntegrationConfiguration.fromProperties();
028 * String serviceUrl = integrationConfig.integrationServiceUrl();
029 * }</pre>
030 * 
031 */
032public record IntegrationConfiguration(
033String integrationServiceUrl,
034String keycloakUrl,
035String metricsUrl
036) {
037
038
039    /**
040     * Creates integration configuration from system properties.
041     * All integration URLs are required for integration benchmarks to work properly.
042     * 
043     * @return IntegrationConfiguration with values from properties
044     * @throws IllegalArgumentException if any required property is missing
045     */
046    public static IntegrationConfiguration fromProperties() {
047        return new IntegrationConfiguration(
048                requireProperty(System.getProperty(Properties.INTEGRATION_SERVICE_URL),
049                        "Integration service URL", Properties.INTEGRATION_SERVICE_URL),
050                requireProperty(System.getProperty(Properties.KEYCLOAK_URL),
051                        "Keycloak URL", Properties.KEYCLOAK_URL),
052                requireProperty(System.getProperty(Properties.METRICS_URL),
053                        "Metrics URL", Properties.METRICS_URL)
054        );
055    }
056
057    /**
058     * Builder for IntegrationConfiguration.
059     */
060    public static class Builder {
061        private String integrationServiceUrl;
062        private String keycloakUrl;
063        private String metricsUrl;
064
065        public Builder withIntegrationServiceUrl(String url) {
066            this.integrationServiceUrl = url;
067            return this;
068        }
069
070        public Builder withKeycloakUrl(String url) {
071            this.keycloakUrl = url;
072            return this;
073        }
074
075        public Builder withMetricsUrl(String url) {
076            this.metricsUrl = url;
077            return this;
078        }
079
080        public IntegrationConfiguration build() {
081            return new IntegrationConfiguration(
082                    requireProperty(integrationServiceUrl,
083                            "Integration service URL", Properties.INTEGRATION_SERVICE_URL),
084                    requireProperty(keycloakUrl,
085                            "Keycloak URL", Properties.KEYCLOAK_URL),
086                    requireProperty(metricsUrl,
087                            "Metrics URL", Properties.METRICS_URL)
088            );
089        }
090    }
091
092    /**
093     * Creates a builder for IntegrationConfiguration.
094     * 
095     * @return a new builder
096     */
097    public static Builder builder() {
098        return new Builder();
099    }
100}