001/*- 002 * #%L 003 * Smile CDR - CDR 004 * %% 005 * Copyright (C) 2016 - 2026 Smile CDR, Inc. 006 * %% 007 * All rights reserved. 008 * #L% 009 */ 010package ca.cdr.test.app.harness.api; 011 012import ca.cdr.test.util.UrlPathUtil; 013import jakarta.annotation.Nonnull; 014import jakarta.annotation.Nullable; 015 016/** 017 * Record class that holds configuration information for connecting to a Smile CDR instance. 018 * This context can be used by {@link SmileHarness} implementations to establish connections to the CDR. 019 * 020 * @param protocol The connection protocol. Values are `http` or `https` 021 * @param baseUrl The base URL of the Smile CDR instance, e.g. `127.0.0.1` or `localhost` 022 * @param jsonAdminPort The port number for the administrative JSON API. If null, will attempt to auto-discover based on the properties file. 023 * @param username The username for authentication 024 * @param password The password for authentication 025 * @param jsonAdminContextPath The {@code context_path} the Admin JSON module is served under, such as 026 * {@code /admin-json}. It is needed before the harness can read any other 027 * module's configuration. Blank and {@code /} both mean the root, which this 028 * record stores as the empty string; use the five-argument constructor for a 029 * root-mounted Admin JSON module. 030 */ 031public record HarnessContext( 032 String protocol, 033 String baseUrl, 034 @Nullable Integer jsonAdminPort, 035 String username, 036 String password, 037 @Nonnull String jsonAdminContextPath 038) { 039 040 public HarnessContext { 041 jsonAdminContextPath = UrlPathUtil.normalizeContextPath(jsonAdminContextPath); 042 } 043 044 /** 045 * Creates a context whose Admin JSON module is served at the root. 046 */ 047 public HarnessContext( 048 String protocol, String baseUrl, @Nullable Integer jsonAdminPort, String username, String password) { 049 this(protocol, baseUrl, jsonAdminPort, username, password, ""); 050 } 051 052 /** 053 * Factory method that creates a default HarnessContext for connecting to a local Smile CDR instance. 054 * This method provides predefined values for a standard out-of-box-experience (OOBE) setup. If you haven't provided a custom properties file, 055 * this harness context should be used. If you have customized users/endpoints, you should build your own HarnessContext. 056 * 057 * @return A HarnessContext configured with default values for localhost connection 058 */ 059 public static HarnessContext oobeHarnessContext() { 060 return new HarnessContext( 061 "http", 062 "localhost", 063 null, 064 "admin", 065 "password" 066 ); 067 } 068 069 public String getContextRoot() { 070 return protocol + "://" + baseUrl; 071 } 072}