Best Testcontainers-java code snippet using org.testcontainers.utility.TestcontainersConfiguration.getConfigurable
Source:TestcontainersConfiguration.java
...133 // specifically not supported as an environment variable or classpath property134 return Boolean.parseBoolean(getEnvVarOrUserProperty("testcontainers.reuse.enable", "false"));135 }136 public String getDockerClientStrategyClassName() {137 // getConfigurable won't apply the TESTCONTAINERS_ prefix when looking for env vars if DOCKER_ appears at the beginning.138 // Because of this overlap, and the desire to not change this specific TESTCONTAINERS_DOCKER_CLIENT_STRATEGY setting,139 // we special-case the logic here so that docker.client.strategy is used when reading properties files and140 // TESTCONTAINERS_DOCKER_CLIENT_STRATEGY is used when searching environment variables.141 // looks for TESTCONTAINERS_ prefixed env var only142 String prefixedEnvVarStrategy = environment.get("TESTCONTAINERS_DOCKER_CLIENT_STRATEGY");143 if (prefixedEnvVarStrategy != null) {144 return prefixedEnvVarStrategy;145 }146 // looks for unprefixed env var or unprefixed property, or null if the strategy is not set at all147 return getEnvVarOrUserProperty("docker.client.strategy", null);148 }149 public String getTransportType() {150 return getEnvVarOrProperty("transport.type", "httpclient5");151 }152 public Integer getImagePullPauseTimeout() {153 return Integer.parseInt(getEnvVarOrProperty("pull.pause.timeout", "30"));154 }155 public String getImageSubstitutorClassName() {156 return getEnvVarOrProperty("image.substitutor", null);157 }158 public Integer getClientPingTimeout() {159 return Integer.parseInt(getEnvVarOrProperty("client.ping.timeout", "5"));160 }161 @Nullable162 @Contract("_, !null, _ -> !null")163 private String getConfigurable(@NotNull final String propertyName, @Nullable final String defaultValue, Properties... propertiesSources) {164 String envVarName = propertyName.replaceAll("\\.", "_").toUpperCase();165 if (!envVarName.startsWith("TESTCONTAINERS_") && !envVarName.startsWith("DOCKER_")) {166 envVarName = "TESTCONTAINERS_" + envVarName;167 }168 if (environment.containsKey(envVarName)) {169 return environment.get(envVarName);170 }171 for (final Properties properties : propertiesSources) {172 if (properties.get(propertyName) != null) {173 return (String) properties.get(propertyName);174 }175 }176 return defaultValue;177 }178 /**179 * Gets a configured setting from an environment variable (if present) or a configuration file property otherwise.180 * The configuration file will be the <code>.testcontainers.properties</code> file in the user's home directory or181 * a <code>testcontainers.properties</code> found on the classpath.182 * <p>183 * Note that when searching environment variables, the prefix `TESTCONTAINERS_` will usually be applied to the184 * property name, which will be converted to upper-case with underscore separators. This prefix will not be added185 * if the property name begins `docker.`.186 *187 * @param propertyName name of configuration file property (dot-separated lower case)188 * @return the found value, or null if not set189 */190 @Contract("_, !null -> !null")191 public String getEnvVarOrProperty(@NotNull final String propertyName, @Nullable final String defaultValue) {192 return getConfigurable(propertyName, defaultValue, userProperties, classpathProperties);193 }194 /**195 * Gets a configured setting from an environment variable (if present) or a configuration file property otherwise.196 * The configuration file will be the <code>.testcontainers.properties</code> file in the user's home directory.197 * <p>198 * Note that when searching environment variables, the prefix `TESTCONTAINERS_` will usually be applied to the199 * property name, which will be converted to upper-case with underscore separators. This prefix will not be added200 * if the property name begins `docker.`.201 *202 * @param propertyName name of configuration file property (dot-separated lower case)203 * @return the found value, or null if not set204 */205 @Contract("_, !null -> !null")206 public String getEnvVarOrUserProperty(@NotNull final String propertyName, @Nullable final String defaultValue) {207 return getConfigurable(propertyName, defaultValue, userProperties);208 }209 /**210 * Gets a configured setting from an environment variable.211 * <p>212 * Note that when searching environment variables, the prefix `TESTCONTAINERS_` will usually be applied to the213 * property name, which will be converted to upper-case with underscore separators. This prefix will not be added214 * if the property name begins `docker.`.215 *216 * @param propertyName name of configuration file property (dot-separated lower case)217 * @return the found value, or null if not set218 */219 @Contract("_, !null -> !null")220 public String getUserProperty(@NotNull final String propertyName, @Nullable final String defaultValue) {221 return getConfigurable(propertyName, defaultValue);222 }223 /**224 * @return properties values available from user properties and classpath properties. Values set by environment225 * variable are NOT included.226 * @deprecated usages should be removed ASAP. See {@link TestcontainersConfiguration#getEnvVarOrProperty(String, String)},227 * {@link TestcontainersConfiguration#getEnvVarOrUserProperty(String, String)} or {@link TestcontainersConfiguration#getUserProperty(String, String)}228 * for suitable replacements.229 */230 @Deprecated231 public Properties getProperties() {232 return Stream.of(userProperties, classpathProperties)233 .reduce(new Properties(), (a, b) -> {234 a.putAll(b);235 return a;...
getConfigurable
Using AI Code Generation
1org.testcontainers.utility.TestcontainersConfiguration.getConfigurable()2org.testcontainers.utility.TestcontainersConfiguration.setConfigurableValue()3org.testcontainers.utility.TestcontainersConfiguration.getConfigurable()4org.testcontainers.utility.TestcontainersConfiguration.setConfigurableValue()5org.testcontainers.utility.TestcontainersConfiguration.getConfigurable()6org.testcontainers.utility.TestcontainersConfiguration.setConfigurableValue()7org.testcontainers.utility.TestcontainersConfiguration.getConfigurable()8org.testcontainers.utility.TestcontainersConfiguration.setConfigurableValue()9org.testcontainers.utility.TestcontainersConfiguration.getConfigurable()10org.testcontainers.utility.TestcontainersConfiguration.setConfigurableValue()11org.testcontainers.utility.TestcontainersConfiguration.getConfigurable()12org.testcontainers.utility.TestcontainersConfiguration.setConfigurableValue()
getConfigurable
Using AI Code Generation
1TestcontainersConfiguration.getInstance().getConfigurable().getEnvVarOrProperty("TESTCONTAINERS_RYUK_DISABLED", "false")2TestcontainersConfiguration.getTestcontainersConfiguration().getConfigurable().getEnvVarOrProperty("TESTCONTAINERS_RYUK_DISABLED", "false")3System.getenv("TESTCONTAINERS_RYUK_DISABLED")4TestcontainersConfiguration.getTestcontainersConfiguration().getConfigurable().getEnvVarOrProperty("TESTCONTAINERS_RYUK_DISABLED", "false")5System.setProperty("TESTCONTAINERS_RYUK_DISABLED", "true")6TestcontainersConfiguration.getTestcontainersConfiguration().getConfigurable().getEnvVarOrProperty("TESTCONTAINERS_RYUK_DISABLED", "false")7TestcontainersConfiguration.getTestcontainersConfiguration().getConfigurable().getEnvVarOrProperty("TESTCONTAINERS_RYUK_DISABLED", "false")
getConfigurable
Using AI Code Generation
1def ryukDisabled = TestcontainersConfiguration.getInstance().getConfigurable().getBoolean("TESTCONTAINERS_RYUK_DISABLED", false)2if (ryukDisabled) {3 println("Ryuk is disabled")4}5else {6 println("Ryuk is enabled")7}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!