Skip to content
Merged
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
20 changes: 18 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ shadowJar {
}

task jarFileTest(type: Test) {
useJUnitPlatform()
testClassesDirs = sourceSets.jarFileTest.output.classesDirs
classpath = sourceSets.jarFileTest.runtimeClasspath

Expand Down Expand Up @@ -105,6 +106,9 @@ dependencies {

shaded 'org.zeroturnaround:zt-exec:1.12'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'

testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
testImplementation('com.google.cloud.tools:jib-core:0.27.3') {
exclude group: 'com.google.guava', module: 'guava'
}
Expand All @@ -124,8 +128,9 @@ dependencies {

jarFileTestCompileOnly "org.projectlombok:lombok:${lombok.version}"
jarFileTestAnnotationProcessor "org.projectlombok:lombok:${lombok.version}"
jarFileTestImplementation 'junit:junit:4.13.2'
jarFileTestImplementation 'org.assertj:assertj-core:3.27.6'
jarFileTestRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
jarFileTestImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
jarFileTestImplementation 'org.assertj:assertj-core:3.27.4'
jarFileTestImplementation 'org.ow2.asm:asm-debug-all:5.2'
}

Expand All @@ -135,3 +140,14 @@ tasks.generatePomFileForMavenJavaPublication.finalizedBy(
]
}
)

compileTestJava {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
}
options.release.set(17)
}

test {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package org.testcontainers;

import org.assertj.core.api.ListAssert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

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

public class JarFileShadingTest extends AbstractJarFileTest {
class JarFileShadingTest extends AbstractJarFileTest {

@Test
public void testPackages() throws Exception {
void testPackages() throws Exception {
assertThatFileList(root).containsOnly("org", "META-INF");

assertThatFileList(root.resolve("org")).containsOnly("testcontainers");
}

@Test
public void testMetaInf() throws Exception {
void testMetaInf() throws Exception {
assertThatFileList(root.resolve("META-INF"))
.containsOnly(
"MANIFEST.MF",
Expand All @@ -33,7 +33,7 @@ public void testMetaInf() throws Exception {
}

@Test
public void testMetaInfServices() throws Exception {
void testMetaInfServices() throws Exception {
assertThatFileList(root.resolve("META-INF").resolve("services"))
.allMatch(it -> it.startsWith("org.testcontainers."));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import lombok.RequiredArgsConstructor;
import org.assertj.core.api.Assertions;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.Parameter;
import org.junit.jupiter.params.ParameterizedClass;
import org.junit.jupiter.params.provider.MethodSource;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
Expand All @@ -30,23 +30,22 @@

/**
* This test checks that we don't expose any shaded class in our public API.
* We use {@link Parameterized} runner here to create a test per public class in Testcontainers' JAR file.
*/
@RunWith(Parameterized.class)
@ParameterizedClass
@MethodSource("data")
@RequiredArgsConstructor
public class PublicBinaryAPITest extends AbstractJarFileTest {

private static String SHADED_PACKAGE = "org.testcontainers.shaded.";
private static final String SHADED_PACKAGE = "org.testcontainers.shaded.";

private static String SHADED_PACKAGE_PATH = SHADED_PACKAGE.replaceAll("\\.", "/");
private static final String SHADED_PACKAGE_PATH = SHADED_PACKAGE.replaceAll("\\.", "/");

static {
Assertions.registerFormatterForType(ClassNode.class, it -> it.name);
Assertions.registerFormatterForType(FieldNode.class, it -> it.name);
Assertions.registerFormatterForType(MethodNode.class, it -> it.name + it.desc);
}

@Parameters(name = "{0}")
public static List<Object[]> data() throws Exception {
List<Object[]> result = new ArrayList<>();

Expand Down Expand Up @@ -85,41 +84,43 @@ public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IO
return result;
}

private final String fileName;
@Parameter(0)
private String fileName;

private final ClassNode classNode;
@Parameter(1)
private ClassNode classNode;

@Before
@BeforeEach
public void setUp() {
switch (classNode.name) {
// Necessary evil
case "org/testcontainers/dockerclient/UnixSocketClientProviderStrategy":
case "org/testcontainers/dockerclient/DockerClientProviderStrategy":
case "org/testcontainers/dockerclient/WindowsClientProviderStrategy":
case "org/testcontainers/utility/DynamicPollInterval":
Assume.assumeTrue(false);
Assumptions.assumeTrue(false);
}
}

@Test
public void testSuperClass() {
void testSuperClass() {
assertThat(classNode.superName).doesNotStartWith(SHADED_PACKAGE_PATH);
}

@Test
public void testInterfaces() {
void testInterfaces() {
assertThat(classNode.interfaces).allSatisfy(it -> assertThat(it).doesNotStartWith(SHADED_PACKAGE_PATH));
}

@Test
public void testMethodReturnTypes() {
void testMethodReturnTypes() {
assertThat(classNode.methods)
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
.allSatisfy(it -> assertThat(Type.getReturnType(it.desc).getClassName()).doesNotStartWith(SHADED_PACKAGE));
}

@Test
public void testMethodArguments() {
void testMethodArguments() {
assertThat(classNode.methods)
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
.allSatisfy(method -> {
Expand All @@ -130,7 +131,7 @@ public void testMethodArguments() {
}

@Test
public void testFields() {
void testFields() {
assertThat(classNode.fields)
.filteredOn(it -> (it.access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED)) != 0)
.allSatisfy(it -> assertThat(Type.getType(it.desc).getClassName()).doesNotStartWith(SHADED_PACKAGE));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package alt.testcontainers.images;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.testcontainers.TestImages;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.startupcheck.OneShotStartupCheckStrategy;
import org.testcontainers.images.AbstractImagePullPolicy;
import org.testcontainers.images.ImageData;
import org.testcontainers.utility.DockerImageName;

public class OutOfPackageImagePullPolicyTest {
class OutOfPackageImagePullPolicyTest {

@Test
public void shouldSupportCustomPoliciesOutOfTestcontainersPackage() {
void shouldSupportCustomPoliciesOutOfTestcontainersPackage() {
try (
GenericContainer<?> container = new GenericContainer<>(TestImages.TINY_IMAGE)
.withImagePullPolicy(
Expand Down
6 changes: 3 additions & 3 deletions core/src/test/java/org/testcontainers/DaemonTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.testcontainers;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;

import java.io.File;
Expand All @@ -14,7 +14,7 @@
/**
* This test forks a new JVM, otherwise it's not possible to reliably diff the threads
*/
public class DaemonTest {
class DaemonTest {

public static void main(String[] args) {
Thread mainThread = Thread.currentThread();
Expand Down Expand Up @@ -46,7 +46,7 @@ public static void main(String[] args) {
}

@Test
public void testThatAllThreadsAreDaemons() throws Exception {
void testThatAllThreadsAreDaemons() throws Exception {
ProcessBuilder processBuilder = new ProcessBuilder(
new File(System.getProperty("java.home")).toPath().resolve("bin").resolve("java").toString(),
"-ea",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package org.testcontainers;

import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.testcontainers.dockerclient.LogToStringContainerCallback;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MockTestcontainersConfigurationRule;
import org.testcontainers.utility.MockTestcontainersConfigurationExtension;

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

/**
* Test for {@link DockerClientFactory}.
*/
public class DockerClientFactoryTest {

@Rule
public MockTestcontainersConfigurationRule configurationMock = new MockTestcontainersConfigurationRule();
@ExtendWith(MockTestcontainersConfigurationExtension.class)
class DockerClientFactoryTest {

@Test
public void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() {
void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() {
try (DockerRegistryContainer registryContainer = new DockerRegistryContainer()) {
registryContainer.start();
DockerImageName imageName = registryContainer.createImage();
Expand All @@ -40,14 +38,14 @@ public void runCommandInsideDockerShouldNotFailIfImageDoesNotExistsLocally() {
}

@Test
public void dockerHostIpAddress() {
void dockerHostIpAddress() {
DockerClientFactory instance = new DockerClientFactory();
instance.strategy = null;
assertThat(instance.dockerHostIpAddress()).isNotNull();
}

@Test
public void failedChecksFailFast() {
void failedChecksFailFast() {
DockerClientFactory instance = DockerClientFactory.instance();
assertThat(instance.client()).isNotNull();
assertThat(instance.cachedClientFailure).isNull();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.testcontainers.containers;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.rnorth.ducttape.TimeoutException;
import org.testcontainers.containers.wait.strategy.Wait;

Expand All @@ -13,7 +13,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;

public class ComposeContainerWithServicesTest {
class ComposeContainerWithServicesTest {

public static final File SIMPLE_COMPOSE_FILE = new File(
"src/test/resources/compose-scaling-multiple-containers.yml"
Expand All @@ -28,7 +28,7 @@ public class ComposeContainerWithServicesTest {
);

@Test
public void testDesiredSubsetOfServicesAreStarted() {
void testDesiredSubsetOfServicesAreStarted() {
try (ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE).withServices("redis")) {
compose.start();

Expand All @@ -37,7 +37,7 @@ public void testDesiredSubsetOfServicesAreStarted() {
}

@Test
public void testDesiredSubsetOfScaledServicesAreStarted() {
void testDesiredSubsetOfScaledServicesAreStarted() {
try (ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE).withScaledService("redis", 2)) {
compose.start();

Expand All @@ -46,7 +46,7 @@ public void testDesiredSubsetOfScaledServicesAreStarted() {
}

@Test
public void testDesiredSubsetOfSpecifiedAndScaledServicesAreStarted() {
void testDesiredSubsetOfSpecifiedAndScaledServicesAreStarted() {
try (
ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE)
.withServices("redis")
Expand All @@ -59,7 +59,7 @@ public void testDesiredSubsetOfSpecifiedAndScaledServicesAreStarted() {
}

@Test
public void testDesiredSubsetOfSpecifiedOrScaledServicesAreStarted() {
void testDesiredSubsetOfSpecifiedOrScaledServicesAreStarted() {
try (
ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE)
.withServices("other")
Expand All @@ -72,7 +72,7 @@ public void testDesiredSubsetOfSpecifiedOrScaledServicesAreStarted() {
}

@Test
public void testAllServicesAreStartedIfNotSpecified() {
void testAllServicesAreStartedIfNotSpecified() {
try (ComposeContainer compose = new ComposeContainer(SIMPLE_COMPOSE_FILE)) {
compose.start();

Expand All @@ -81,7 +81,7 @@ public void testAllServicesAreStartedIfNotSpecified() {
}

@Test
public void testScaleInComposeFileIsRespected() {
void testScaleInComposeFileIsRespected() {
try (ComposeContainer compose = new ComposeContainer(COMPOSE_FILE_WITH_INLINE_SCALE)) {
compose.start();

Expand All @@ -91,7 +91,7 @@ public void testScaleInComposeFileIsRespected() {
}

@Test
public void testStartupTimeoutSetsTheHighestTimeout() {
void testStartupTimeoutSetsTheHighestTimeout() {
assertThat(
catchThrowable(() -> {
try (
Expand All @@ -113,7 +113,7 @@ public void testStartupTimeoutSetsTheHighestTimeout() {
}

@Test
public void testWaitingForHealthcheck() {
void testWaitingForHealthcheck() {
try (
ComposeContainer compose = new ComposeContainer(COMPOSE_FILE_WITH_HEALTHCHECK)
.waitingFor("redis", Wait.forHealthcheck().withStartupTimeout(Duration.ofMinutes(2)))
Expand All @@ -125,7 +125,7 @@ public void testWaitingForHealthcheck() {
}

@Test
public void testWaitingForHealthcheckWithRestartDoesNotCrash() {
void testWaitingForHealthcheckWithRestartDoesNotCrash() {
try (
ComposeContainer compose = new ComposeContainer(COMPOSE_FILE_WITH_HEALTHCHECK)
.waitingFor("redis", Wait.forHealthcheck().withStartupTimeout(Duration.ofMinutes(1)))
Expand Down
Loading
Loading