How to use getReaderForContainerPort80 method of org.testcontainers.junit.GenericContainerRuleTest class

Best Testcontainers-java code snippet using org.testcontainers.junit.GenericContainerRuleTest.getReaderForContainerPort80

Source:GenericContainerRuleTest.java Github

copy

Full Screen

...162 assertEquals("A record can be inserted into and retrieved from MongoDB", 1, doc2.get("value"));163 }164 @Test165 public void environmentAndCustomCommandTest() throws IOException {166 String line = getReaderForContainerPort80(GenericContainerRuleTest.alpineEnvVar).readLine();167 assertEquals("An environment variable can be passed into a command", "42", line);168 }169 @Test170 public void environmentFromMapTest() throws IOException {171 String line = getReaderForContainerPort80(GenericContainerRuleTest.alpineEnvVarFromMap).readLine();172 assertEquals("Environment variables can be passed into a command from a map", "42 and 50", line);173 }174 @Test175 public void customLabelTest() {176 try (final GenericContainer alpineCustomLabel = new GenericContainer("alpine:3.2").withLabel("our.custom", "label").withCommand("top")) {177 alpineCustomLabel.start();178 Map<String, String> labels = alpineCustomLabel.getCurrentContainerInfo().getConfig().getLabels();179 assertTrue("org.testcontainers label is present", labels.containsKey("org.testcontainers"));180 assertTrue("our.custom label is present", labels.containsKey("our.custom"));181 assertEquals("our.custom label value is label", labels.get("our.custom"), "label");182 }183 }184 @Test185 public void exceptionThrownWhenTryingToOverrideTestcontainersLabels() {186 assertThrows("When trying to overwrite an 'org.testcontainers' label, withLabel() throws an exception", IllegalArgumentException.class, () -> {187 new GenericContainer("alpine:3.2").withLabel("org.testcontainers.foo", "false");188 });189 }190 @Test191 public void customClasspathResourceMappingTest() throws IOException {192 // Note: This functionality doesn't work if you are running your build inside a Docker container;193 // in that case this test will fail.194 String line = getReaderForContainerPort80(GenericContainerRuleTest.alpineClasspathResource).readLine();195 assertEquals("Resource on the classpath can be mapped using calls to withClasspathResourceMapping", "FOOBAR", line);196 }197 @Test198 public void customClasspathResourceMappingWithSelinuxTest() throws IOException {199 String line = getReaderForContainerPort80(GenericContainerRuleTest.alpineClasspathResourceSelinux).readLine();200 assertEquals("Resource on the classpath can be mapped using calls to withClasspathResourceMappingSelinux", "FOOBAR", line);201 }202 @Test203 public void exceptionThrownWhenMappedPortNotFound() throws IOException {204 assertThrows("When the requested port is not mapped, getMappedPort() throws an exception", IllegalArgumentException.class, () -> {205 return GenericContainerRuleTest.redis.getMappedPort(666);206 });207 }208 @Test209 public void testExecInContainer() throws Exception {210 // The older "lxc" execution driver doesn't support "exec". At the time of writing (2016/03/29),211 // that's the case for CircleCI.212 // Once they resolve the issue, this clause can be removed.213 Assume.assumeTrue(TestEnvironment.dockerExecutionDriverSupportsExec());214 final GenericContainer.ExecResult result = GenericContainerRuleTest.redis.execInContainer("redis-cli", "role");215 assertTrue("Output for \"redis-cli role\" command should start with \"master\"", result.getStdout().startsWith("master"));216 assertEquals("Stderr for \"redis-cli role\" command should be empty", "", result.getStderr());217 // We expect to reach this point for modern Docker versions.218 }219 @Test220 public void extraHostTest() throws IOException {221 BufferedReader br = getReaderForContainerPort80(GenericContainerRuleTest.alpineExtrahost);222 // read hosts file from container223 StringBuffer hosts = new StringBuffer();224 String line = br.readLine();225 while (line != null) {226 hosts.append(line);227 hosts.append("\n");228 line = br.readLine();229 } 230 Matcher matcher = Pattern.compile("^192.168.1.10\\s.*somehost", Pattern.MULTILINE).matcher(hosts.toString());231 assertTrue("The hosts file of container contains extra host", matcher.find());232 }233 @Test234 public void createContainerCmdHookTest() {235 // Use random name to avoid the conflicts between the tests...

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