How to use getEnvVarOrProperty method of org.testcontainers.utility.TestcontainersConfiguration class

Best Testcontainers-java code snippet using org.testcontainers.utility.TestcontainersConfiguration.getEnvVarOrProperty

Source:EnvironmentAndSystemPropertyClientProviderStrategyTest.java Github

copy

Full Screen

...43 defaultSSLConfig = defaultConfig.getSSLConfig();44 }45 @Test46 public void testWhenConfigAbsent() {47 Mockito.doReturn("auto").when(TestcontainersConfiguration.getInstance()).getEnvVarOrProperty(eq("dockerconfig.source"), anyString());48 Mockito.doReturn(null).when(TestcontainersConfiguration.getInstance()).getEnvVarOrUserProperty(eq("docker.host"), isNull());49 Mockito.doReturn(null).when(TestcontainersConfiguration.getInstance()).getEnvVarOrUserProperty(eq("docker.tls.verify"), isNull());50 Mockito.doReturn(null).when(TestcontainersConfiguration.getInstance()).getEnvVarOrUserProperty(eq("docker.cert.path"), isNull());51 EnvironmentAndSystemPropertyClientProviderStrategy strategy = new EnvironmentAndSystemPropertyClientProviderStrategy();52 TransportConfig transportConfig = strategy.getTransportConfig();53 assertEquals(defaultDockerHost, transportConfig.getDockerHost());54 assertEquals(defaultSSLConfig, transportConfig.getSslConfig());55 }56 @Test57 public void testWhenDockerHostPresent() {58 Mockito.doReturn("auto").when(TestcontainersConfiguration.getInstance()).getEnvVarOrProperty(eq("dockerconfig.source"), anyString());59 Mockito.doReturn("tcp://1.2.3.4:2375").when(TestcontainersConfiguration.getInstance()).getEnvVarOrUserProperty(eq("docker.host"), isNull());60 Mockito.doReturn(null).when(TestcontainersConfiguration.getInstance()).getEnvVarOrUserProperty(eq("docker.tls.verify"), isNull());61 Mockito.doReturn(null).when(TestcontainersConfiguration.getInstance()).getEnvVarOrUserProperty(eq("docker.cert.path"), isNull());62 EnvironmentAndSystemPropertyClientProviderStrategy strategy = new EnvironmentAndSystemPropertyClientProviderStrategy();63 TransportConfig transportConfig = strategy.getTransportConfig();64 assertEquals("tcp://1.2.3.4:2375", transportConfig.getDockerHost().toString());65 assertEquals(defaultSSLConfig, transportConfig.getSslConfig());66 }67 @Test68 public void testWhenDockerHostAndSSLConfigPresent() throws IOException {69 Path tempDir = Files.createTempDirectory("testcontainers-test");70 String tempDirPath = tempDir.toAbsolutePath().toString();71 Mockito.doReturn("auto").when(TestcontainersConfiguration.getInstance()).getEnvVarOrProperty(eq("dockerconfig.source"), anyString());72 Mockito.doReturn("tcp://1.2.3.4:2375").when(TestcontainersConfiguration.getInstance()).getEnvVarOrUserProperty(eq("docker.host"), isNull());73 Mockito.doReturn("1").when(TestcontainersConfiguration.getInstance()).getEnvVarOrUserProperty(eq("docker.tls.verify"), isNull());74 Mockito.doReturn(tempDirPath).when(TestcontainersConfiguration.getInstance()).getEnvVarOrUserProperty(eq("docker.cert.path"), isNull());75 EnvironmentAndSystemPropertyClientProviderStrategy strategy = new EnvironmentAndSystemPropertyClientProviderStrategy();76 TransportConfig transportConfig = strategy.getTransportConfig();77 assertEquals("tcp://1.2.3.4:2375", transportConfig.getDockerHost().toString());78 SSLConfig sslConfig = transportConfig.getSslConfig();79 assertNotNull(sslConfig);80 assertTrue(sslConfig instanceof LocalDirectorySSLConfig);81 assertEquals(tempDirPath, ((LocalDirectorySSLConfig) sslConfig).getDockerCertPath());82 }83 @Test84 public void applicableWhenIgnoringUserPropertiesAndConfigured() {85 Mockito.doReturn("autoIgnoringUserProperties").when(TestcontainersConfiguration.getInstance()).getEnvVarOrProperty(eq("dockerconfig.source"), anyString());86 DefaultDockerClientConfig.Builder configBuilder = DefaultDockerClientConfig.createDefaultConfigBuilder()87 .withDockerHost("tcp://1.2.3.4:2375");88 EnvironmentAndSystemPropertyClientProviderStrategy strategy = new EnvironmentAndSystemPropertyClientProviderStrategy(configBuilder);89 assertTrue(strategy.isApplicable());90 }91 @Test92 public void notApplicableWhenIgnoringUserPropertiesAndNotConfigured() {93 Mockito.doReturn("autoIgnoringUserProperties").when(TestcontainersConfiguration.getInstance()).getEnvVarOrProperty(eq("dockerconfig.source"), anyString());94 EnvironmentAndSystemPropertyClientProviderStrategy strategy = new EnvironmentAndSystemPropertyClientProviderStrategy();95 assertFalse(strategy.isApplicable());96 }97}...

Full Screen

Full Screen

Source:TestcontainersHelper.java Github

copy

Full Screen

...18import org.testcontainers.utility.DockerImageName;19import org.testcontainers.utility.TestcontainersConfiguration;20public class TestcontainersHelper {21 public static String resolveImageName(String imageProperty, String defaultImage) {22 String image = TestcontainersConfiguration.getInstance().getEnvVarOrProperty(imageProperty, defaultImage);23 if (image == null) {24 throw new IllegalStateException("To use the Testcontainers integration correctly, please provide a " +25 "Docker image. To do this, place a file on the classpath named `testcontainers.properties`, " +26 "containing `" + imageProperty + "=IMAGE`, where IMAGE is a suitable image name and tag.");27 } else {28 return image;29 }30 }31 public static DockerImageName resolveDockerImageName(String dbLabel, String tag, String defaultDbImage) {32 String imageProperty = dbLabel + ".container.image";33 String dockerImageString = resolveImageName(imageProperty, defaultDbImage) + ":" + tag;34 return DockerImageName.parse(dockerImageString).asCompatibleSubstituteFor(defaultDbImage);35 }36}...

Full Screen

Full Screen

getEnvVarOrProperty

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.utility.TestcontainersConfiguration;2import java.util.Map;3import java.util.HashMap;4public class getEnvVarOrProperty {5 public static void main(String[] args) {6 TestcontainersConfiguration config = TestcontainersConfiguration.getInstance();7 Map<String, String> env = new HashMap<>();8 env.put("TESTCONTAINERS_RYUK_DISABLED", "true");9 env.put("TESTCONTAINERS_RYUK_CONTAINER_IMAGE", "testcontainers/ryuk:0.2.3");10 env.put("TESTCONTAINERS_RYUK_TIMEOUT", "5000");11 env.put("TESTCONTAINERS_RYUK_TCP_PORT", "8080");12 env.put("TESTCONTAINERS_RYUK_UDP_PORT", "8081");13 env.put("TESTCONTAINERS_RYUK_CONTAINER_NAME", "testcontainers-ryuk");14 env.put("TESTCONTAINERS_RYUK_CONTAINER_NETWORK", "testcontainers");15 env.put("TESTCONTAINERS_RYUK_CONTAINER_NETWORK_ALIAS", "testcontainers-ryuk");16 env.put("TESTCONTAINERS_RYUK_CONTAINER_LABELS", "label1=value1,label2=value2");17 env.put("TESTCONTAINERS_RYUK_CONTAINER_HOSTNAME", "myhostname");18 env.put("TESTCONTAINERS_RYUK_CONTAINER_DOMAINNAME", "mydomainname");19 env.put("TESTCONTAINERS_RYUK_CONTAINER_WORKINGDIR", "/home/testcontainers");20 env.put("TESTCONTAINERS_RYUK_CONTAINER_USER", "testcontainers");21 env.put("TESTCONTAINERS_RYUK_CONTAINER_ENTRYPOINT", "/bin/sh");22 env.put("TESTCONTAINERS_RYUK_CONTAINER_COMMAND", "-c");23 env.put("TESTCONTAINERS_RYUK_CONTAINER_EXTRAHOSTS", "testcontainers-host:

Full Screen

Full Screen

getEnvVarOrProperty

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.utility.TestcontainersConfiguration;2public class TestcontainersConfig {3 public static void main(String[] args) {4 TestcontainersConfiguration config = TestcontainersConfiguration.getInstance();5 String value = config.getEnvVarOrProperty("TESTCONTAINERS_RYUK_DISABLED", "true");6 System.out.println(value);7 }8}

Full Screen

Full Screen

getEnvVarOrProperty

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.utility.TestcontainersConfiguration;2public class TestcontainersConfigurationGetEnvVarOrProperty {3 public static void main(String[] args) {4 String envVarOrProperty = TestcontainersConfiguration.getInstance().getEnvVarOrProperty("TESTCONTAINERS_RYUK_DISABLED");5 System.out.println("Env var or property: " + envVarOrProperty);6 }7}

Full Screen

Full Screen

getEnvVarOrProperty

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.utility.TestcontainersConfiguration;2public class TestcontainersConfiguration {3 public static void main(String[] args) {4 TestcontainersConfiguration testcontainersConfiguration = TestcontainersConfiguration.getInstance();5 String value = testcontainersConfiguration.getEnvVarOrProperty("TESTCONTAINERS_RYUK_DISABLED");6 System.out.println("Value of TESTCONTAINERS_RYUK_DISABLED: " + value);7 }8}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful