Tabnine Logo
MountableFile.forClasspathResource
Code IndexAdd Tabnine to your IDE (free)

How to use
forClasspathResource
method
in
org.testcontainers.utility.MountableFile

Best Java code snippets using org.testcontainers.utility.MountableFile.forClasspathResource (Showing top 20 results out of 315)

origin: testcontainers/testcontainers-java

/**
 * Obtains a {@link MountableFile} corresponding to a resource on the classpath (including resources in JAR files)
 *
 * @param resourceName the classpath path to the resource
 * @return a {@link MountableFile} that may be used to obtain a mountable path
 */
public static MountableFile forClasspathResource(@NotNull final String resourceName) {
  return forClasspathResource(resourceName, null);
}
origin: testcontainers/testcontainers-java

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);
    withCopyFileToContainer(mountableFile, pathNameInContainer);
  }
}
origin: testcontainers/testcontainers-java

  default SELF withFileFromClasspath(String path, String resourcePath) {
    final MountableFile mountableFile = MountableFile.forClasspathResource(resourcePath);

    return ((SELF) this).withFileFromPath(path, Paths.get(mountableFile.getResolvedPath()));
  }
}
origin: testcontainers/testcontainers-java

/**
 * {@inheritDoc}
 */
@Override
public SELF withClasspathResourceMapping(final String resourcePath, final String containerPath, final BindMode mode, final SelinuxContext selinuxContext) {
  final MountableFile mountableFile = MountableFile.forClasspathResource(resourcePath);
  this.addFileSystemBind(mountableFile.getResolvedPath(), containerPath, mode, selinuxContext);
  return self();
}
origin: testcontainers/testcontainers-java

@Test
public void forClasspathResource() throws Exception {
  final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt");
  performChecks(mountableFile);
}
origin: testcontainers/testcontainers-java

private boolean checkMountableFile() {
  DockerClient dockerClient = client();
  MountableFile mountableFile = MountableFile.forClasspathResource(ResourceReaper.class.getName().replace(".", "/") + ".class");
  Volume volume = new Volume("/dummy");
  try {
    return runInsideDocker(
      createContainerCmd -> createContainerCmd.withBinds(new Bind(mountableFile.getResolvedPath(), volume, AccessMode.ro)),
      (__, containerId) -> {
        try (InputStream stream = dockerClient.copyArchiveFromContainerCmd(containerId, volume.getPath()).exec()) {
          stream.read();
          return true;
        } catch (Exception e) {
          return false;
        }
      }
    );
  } catch (Exception e) {
    log.debug("Failure while checking for mountable file support", e);
    return false;
  }
}
origin: testcontainers/testcontainers-java

@Test
public void forClasspathResourceWithAbsolutePath() throws Exception {
  final MountableFile mountableFile = MountableFile.forClasspathResource("/mappable-resource/test-resource.txt");
  performChecks(mountableFile);
}
origin: testcontainers/testcontainers-java

@Test
public void forClasspathResourceFromJar() throws Exception {
  final MountableFile mountableFile = MountableFile.forClasspathResource("META-INF/dummy_unique_name.txt");
  performChecks(mountableFile);
}
origin: testcontainers/testcontainers-java

@Test
public void forClasspathResourceFromJarWithAbsolutePath() throws Exception {
  final MountableFile mountableFile = MountableFile.forClasspathResource("/META-INF/dummy_unique_name.txt");
  performChecks(mountableFile);
}
origin: testcontainers/testcontainers-java

@Test
public void forClasspathResourceWithPermission() throws Exception {
  final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt",
    TEST_FILE_MODE);
  performChecks(mountableFile);
  assertEquals("Valid file mode.", BASE_FILE_MODE | TEST_FILE_MODE, mountableFile.getFileMode());
}
origin: testcontainers/testcontainers-java

@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));
  }
}
origin: testcontainers/testcontainers-java

@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));
  }
}
origin: testcontainers/testcontainers-java

  @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));
    }
  }
}
origin: testcontainers/testcontainers-java

@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));
  }
}
origin: testcontainers/testcontainers-java

  @Test
  public void checkFileCopied() throws IOException, InterruptedException {
    try(
      GenericContainer container = new GenericContainer("alpine:latest")
        .withCommand("sleep","3000")
        .withCopyFileToContainer(MountableFile.forClasspathResource("/mappable-resource/"), containerPath)
    ) {
      container.start();
      String filesList = container.execInContainer("ls","/tmp/mappable-resource").getStdout();
      Assert.assertTrue(filesList.contains(fileName));
    }
  }
}
origin: testcontainers/testcontainers-java

@Test
public void noTrailingSlashesInTarEntryNames() throws Exception {
  final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/test-resource.txt");
  @Cleanup final TarArchiveInputStream tais = intoTarArchive((taos) -> {
    mountableFile.transferTo(taos, "/some/path.txt");
    mountableFile.transferTo(taos, "/path.txt");
    mountableFile.transferTo(taos, "path.txt");
  });
  ArchiveEntry entry;
  while ((entry = tais.getNextEntry()) != null) {
    assertFalse("no entries should have a trailing slash", entry.getName().endsWith("/"));
  }
}
origin: org.testcontainers/jdbc

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);
    withCopyFileToContainer(mountableFile, pathNameInContainer);
  }
}
origin: org.testcontainers/testcontainers

  default SELF withFileFromClasspath(String path, String resourcePath) {
    final MountableFile mountableFile = MountableFile.forClasspathResource(resourcePath);

    return ((SELF) this).withFileFromPath(path, Paths.get(mountableFile.getResolvedPath()));
  }
}
origin: org.testcontainers/testcontainers

private boolean checkMountableFile() {
  DockerClient dockerClient = client();
  MountableFile mountableFile = MountableFile.forClasspathResource(ResourceReaper.class.getName().replace(".", "/") + ".class");
  Volume volume = new Volume("/dummy");
  try {
    return runInsideDocker(createContainerCmd -> createContainerCmd.withBinds(new Bind(mountableFile.getResolvedPath(), volume, AccessMode.ro)), (__, containerId) -> {
      try (InputStream stream = dockerClient.copyArchiveFromContainerCmd(containerId, volume.getPath()).exec()) {
        stream.read();
        return true;
      } catch (Exception e) {
        return false;
      }
    });
  } catch (Exception e) {
    log.debug("Failure while checking for mountable file support", e);
    return false;
  }
}
origin: Playtika/testcontainers-spring-boot

@Bean(name = BEAN_NAME_EMBEDDED_MEMSQL, destroyMethod = "stop")
public GenericContainer memsql(ConfigurableEnvironment environment,
                MemSqlProperties properties,
                MemSqlStatusCheck memSqlStatusCheck) {
  log.info("Starting memsql server. Docker image: {}", properties.dockerImage);
  GenericContainer memsql = new GenericContainer<>(properties.dockerImage)
      .withEnv("IGNORE_MIN_REQUIREMENTS", "1")
      .withLogConsumer(containerLogsConsumer(log))
      .withExposedPorts(properties.port)
      .withCopyFileToContainer(MountableFile.forClasspathResource("mem.sql"), "/schema.sql")
      .waitingFor(memSqlStatusCheck)
      .withStartupTimeout(properties.getTimeoutDuration());
  memsql.start();
  registerMemSqlEnvironment(memsql, environment, properties);
  return memsql;
}
org.testcontainers.utilityMountableFileforClasspathResource

Javadoc

Obtains a MountableFile corresponding to a resource on the classpath (including resources in JAR files)

Popular methods of MountableFile

  • forHostPath
  • getResolvedPath
  • <init>
  • copyFromJarToLocation
  • createTempDirectory
  • deleteOnExit
  • extractClassPathResourceToTempLocation
    Extract a file or directory tree from a JAR file to a temporary location. This allows Docker to moun
  • getClasspathResource
  • getFilesystemPath
  • getModeValue
  • getResourcePath
  • getUnixFileMode
  • getResourcePath,
  • getUnixFileMode,
  • unencodeResourceURIToFilePath,
  • getFileMode,
  • recursiveTar,
  • resolveFilesystemPath,
  • resolvePath,
  • transferTo

Popular in Java

  • Reading from database using SQL prepared statement
  • startActivity (Activity)
  • notifyDataSetChanged (ArrayAdapter)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Collectors (java.util.stream)
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • ImageIO (javax.imageio)
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now