Search in sources :

Example 1 with MountableFile

use of org.testcontainers.utility.MountableFile in project testcontainers-java by testcontainers.

the class GenericContainerRuleTest method copyToContainerTest.

@Test
public void copyToContainerTest() throws Exception {
    final File tempResultFolder = Files.createTempDir();
    try (final GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2").withCommand("top")) {
        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/");
        alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", tempResultFolder.getAbsolutePath() + "/test_copy_to_container.txt");
        File expectedFile = new File(mountableFile.getResolvedPath());
        File actualFile = new File(tempResultFolder.getAbsolutePath() + "/test_copy_to_container.txt");
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
Also used : MountableFile(org.testcontainers.utility.MountableFile) GenericContainer(org.testcontainers.containers.GenericContainer) MountableFile(org.testcontainers.utility.MountableFile)

Example 2 with MountableFile

use of org.testcontainers.utility.MountableFile in project testcontainers-java by testcontainers.

the class GenericContainerRuleTest method shouldCopyFileFromContainerTest.

@Test
public void shouldCopyFileFromContainerTest() throws IOException, InterruptedException {
    final File tempResultFolder = Files.createTempDir();
    try (final GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2").withCommand("top")) {
        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/");
        alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", tempResultFolder.getAbsolutePath() + "/test_copy_from_container.txt");
        File expectedFile = new File(mountableFile.getResolvedPath());
        File actualFile = new File(tempResultFolder.getAbsolutePath() + "/test_copy_from_container.txt");
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
Also used : MountableFile(org.testcontainers.utility.MountableFile) GenericContainer(org.testcontainers.containers.GenericContainer) MountableFile(org.testcontainers.utility.MountableFile)

Example 3 with MountableFile

use of org.testcontainers.utility.MountableFile in project testcontainers-java by testcontainers.

the class JdbcDatabaseContainer method optionallyMapResourceParameterAsVolume.

protected void optionallyMapResourceParameterAsVolume(@NotNull String paramName, @NotNull String pathNameInContainer, @NotNull String defaultResource) {
    String resourceName = parameters.getOrDefault(paramName, defaultResource);
    if (resourceName != null) {
        final MountableFile mountableFile = MountableFile.forClasspathResource(resourceName);
        addFileSystemBind(mountableFile.getResolvedPath(), pathNameInContainer, BindMode.READ_ONLY);
    }
}
Also used : MountableFile(org.testcontainers.utility.MountableFile)

Aggregations

MountableFile (org.testcontainers.utility.MountableFile)3 GenericContainer (org.testcontainers.containers.GenericContainer)2