001/*-
002 * #%L
003 * Smile CDR - CDR
004 * %%
005 * Copyright (C) 2016 - 2025 Smile CDR, Inc.
006 * %%
007 * All rights reserved.
008 * #L%
009 */
010package ca.cdr.test.app.harness.api;
011
012import jakarta.annotation.Nullable;
013
014/**
015 * Record class that holds configuration information for connecting to a Smile CDR instance.
016 * This context can be used by {@link SmileHarness} implementations to establish connections to the CDR.
017 *
018 * @param protocol The connection protocol. Values are `http` or `https`
019 * @param baseUrl       The base URL of the Smile CDR instance, e.g. `127.0.0.1` or `localhost`
020 * @param jsonAdminPort The port number for the administrative JSON API. If null, will attempt to auto-discover based on the properties file.
021 * @param username      The username for authentication
022 * @param password      The password for authentication
023 */
024public record HarnessContext(
025        String protocol,
026        String baseUrl,
027        @Nullable Integer jsonAdminPort,
028        String username,
029        String password
030) {
031
032        /**
033         * Factory method that creates a default HarnessContext for connecting to a local Smile CDR instance.
034         * This method provides predefined values for a standard out-of-box-experience (OOBE) setup. If you haven't provided a custom properties file,
035         * this harness context should be used. If you have customized users/endpoints, you should build your own HarnessContext.
036         *
037         * @return A HarnessContext configured with default values for localhost connection
038         */
039        public static HarnessContext oobeHarnessContext() {
040                return new HarnessContext(
041                        "http",
042                        "localhost",
043                        null,
044                        "admin",
045                        "password"
046                );
047        }
048
049        public String getContextRoot() {
050                return protocol + "://" + baseUrl;
051        }
052}