Java Code Examples for org.testcontainers.utility.MountableFile#getResolvedPath()

The following examples show how to use org.testcontainers.utility.MountableFile#getResolvedPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileOperationsTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void copyFileToContainerFileTest() throws Exception {
    try (
        GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
            .withCommand("top")
    ) {
        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/test.txt");

        File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt");
        alpineCopyToContainer.copyFileFromContainer("/test.txt", actualFile.getPath());

        File expectedFile = new File(mountableFile.getResolvedPath());
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
 
Example 2
Source File: FileOperationsTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void copyFileToContainerFolderTest() throws Exception {
    try (
        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/");

        File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt");
        alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", actualFile.getPath());

        File expectedFile = new File(mountableFile.getResolvedPath());
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
 
Example 3
Source File: FileOperationsTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void copyFolderToContainerFolderTest() throws Exception {
    try (
        GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
            .withCommand("top")
    ) {

        alpineCopyToContainer.start();
        final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/");
        alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/test/");

        File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt");
        alpineCopyToContainer.copyFileFromContainer("/home/test/test-resource.txt", actualFile.getPath());

        File expectedFile = new File(mountableFile.getResolvedPath() + "/test-resource.txt");
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
 
Example 4
Source File: FileOperationsTest.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Test
public void shouldCopyFileFromContainerTest() throws IOException {
    try (
        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/");

        File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_from_container.txt");
        alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", actualFile.getPath());

        File expectedFile = new File(mountableFile.getResolvedPath());
        assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
    }
}
 
Example 5
Source File: ContainerState.java    From testcontainers-java with MIT License 5 votes vote down vote up
/**
 *
 * Copies a file or directory to the container.
 *
 * @param mountableFile file or directory which is copied into the container
 * @param containerPath destination path inside the container
 */
default void copyFileToContainer(MountableFile mountableFile, String containerPath) {
    File sourceFile = new File(mountableFile.getResolvedPath());

    if (containerPath.endsWith("/") && sourceFile.isFile()) {
        final Logger logger = LoggerFactory.getLogger(GenericContainer.class);
        logger.warn("folder-like containerPath in copyFileToContainer is deprecated, please explicitly specify a file path");
        copyFileToContainer((Transferable) mountableFile, containerPath + sourceFile.getName());
    } else {
        copyFileToContainer((Transferable) mountableFile, containerPath);
    }
}