Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.testcontainers.containers;

import org.junit.jupiter.api.Test;

import java.net.MalformedURLException;
import java.net.URL;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class BrowserWebDriverContainerSeleniumAddressTest {

@Test
void getSeleniumAddressReturnsUrlBuiltFromHostAndMappedPort() throws MalformedURLException {
BrowserWebDriverContainer<?> container = new FixedAddressBrowserWebDriverContainer("localhost", 32768);

assertThat(container.getSeleniumAddress()).isEqualTo(new URL("http", "localhost", 32768, "/wd/hub"));
}

@Test
void getSeleniumAddressThrowsContainerLaunchExceptionWhenUrlCannotBeConstructed() {
BrowserWebDriverContainer<?> container = new FixedAddressBrowserWebDriverContainer("http://bad", 32768);

assertThatThrownBy(container::getSeleniumAddress)
.isInstanceOf(ContainerLaunchException.class)
.hasMessage("Could not construct Selenium address")
.hasCauseInstanceOf(MalformedURLException.class);
}

private static class FixedAddressBrowserWebDriverContainer
extends BrowserWebDriverContainer<FixedAddressBrowserWebDriverContainer> {

private final String host;

private final int mappedPort;

FixedAddressBrowserWebDriverContainer(String host, int mappedPort) {
super();
this.host = host;
this.mappedPort = mappedPort;
}

@Override
public String getHost() {
return host;
}

@Override
public Integer getMappedPort(int originalPort) {
return mappedPort;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.testcontainers.selenium;

import org.junit.jupiter.api.Test;
import org.testcontainers.containers.ContainerLaunchException;
import org.testcontainers.utility.DockerImageName;

import java.net.MalformedURLException;
import java.net.URL;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

class BrowserWebDriverContainerSeleniumAddressTest {

private static final DockerImageName CHROME_IMAGE = DockerImageName.parse("selenium/standalone-chrome:4.13.0");

@Test
void getSeleniumAddressReturnsUrlBuiltFromHostAndMappedPort() throws MalformedURLException {
BrowserWebDriverContainer container = new FixedAddressBrowserWebDriverContainer("localhost", 32768);

assertThat(container.getSeleniumAddress()).isEqualTo(new URL("http", "localhost", 32768, "/wd/hub"));
}

@Test
void getSeleniumAddressThrowsContainerLaunchExceptionWhenUrlCannotBeConstructed() {
BrowserWebDriverContainer container = new FixedAddressBrowserWebDriverContainer("http://bad", 32768);

assertThatThrownBy(container::getSeleniumAddress)
.isInstanceOf(ContainerLaunchException.class)
.hasMessage("Could not construct Selenium address")
.hasCauseInstanceOf(MalformedURLException.class);
}

private static class FixedAddressBrowserWebDriverContainer extends BrowserWebDriverContainer {

private final String host;

private final int mappedPort;

FixedAddressBrowserWebDriverContainer(String host, int mappedPort) {
super(CHROME_IMAGE);
this.host = host;
this.mappedPort = mappedPort;
}

@Override
public String getHost() {
return host;
}

@Override
public Integer getMappedPort(int originalPort) {
return mappedPort;
}
}
}