// Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/BaseDeployerTest.java
// public class BaseDeployerTest extends BaseTestCase {
//   protected static final int DEPLOYER_DEFAULT_PORT = 55369;
// 
//   protected File getTestResource(String fileName) {
//     final String pathInBuildAgentModule = "src/test/resources/" + fileName;
//     File file = new File(pathInBuildAgentModule);
//     if (!file.exists()) {
//       file = new File("deploy-runner-agent/" + pathInBuildAgentModule);
//     }
//     return file;
//   }
// 
//   protected DeployTestUtils.TempFilesFactory createTempFilesFactory() {
//     return new DeployTestUtils.TempFilesFactory() {
//       @Override
//       public File createTempFile(int size) throws IOException {
//         return BaseDeployerTest.this.createTempFile(size);
//       }
//     };
//   }
// }
// 
// Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/util/DeployTestUtils.java
// public class DeployTestUtils {
//   public static void runProcess(final BuildProcess process, final int timeout) throws RunBuildException {
//     process.start();
//     new WaitFor(timeout) {
//       @Override
//       protected boolean condition() {
//         return process.isFinished();
//       }
//     };
//     assertThat(process.isFinished()).describedAs("Failed to finish test in time").isTrue();
//     assertThat(process.waitFor()).isEqualTo(BuildFinishedStatus.FINISHED_SUCCESS);
//   }
// 
//   public static ArtifactsCollection buildArtifactsCollection(final TempFilesFactory tempFiles, String... destinationDirs) throws IOException {
// 
//     final Map<File, String> filePathMap = new HashMap<File, String>();
//     String dirTo = "dirTo";
//     for (String destinationDir : destinationDirs) {
//       dirTo = destinationDir;
//       final File content = tempFiles.createTempFile(100);
//       filePathMap.put(content, destinationDir);
//     }
//     return new ArtifactsCollection("dirFrom/**", dirTo, filePathMap);
//   }
// 
//   public static void assertCollectionsTransferred(File remoteBase, List<ArtifactsCollection> artifactsCollections) throws IOException {
// 
//     for (ArtifactsCollection artifactsCollection : artifactsCollections) {
//       for (Map.Entry<File, String> fileStringEntry : artifactsCollection.getFilePathMap().entrySet()) {
//         final File source = fileStringEntry.getKey();
//         final String relativePath = fileStringEntry.getValue();
//         final String targetPath = relativePath + (StringUtil.isNotEmpty(relativePath) ? File.separator : "") + source.getName();
//         final File target;
//         if (new File(targetPath).isAbsolute()) {
//           target = new File(targetPath);
//         } else {
//           target = new File(remoteBase, targetPath);
//         }
//         assertTrue(target.exists(), "Destination file [" + targetPath + "] does not exist");
//         assertEquals(FileUtil.readText(target), FileUtil.readText(source), "wrong content");
//       }
//     }
//   }
// 
//   public interface TempFilesFactory {
//     File createTempFile(int size) throws IOException;
//   }
// }
// 
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java
// public class FTPRunnerConstants {
//   public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod";
//   public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod";
//   public static final String TRANSFER_MODE_AUTO = "AUTO";
//   public static final String TRANSFER_MODE_BINARY = "BINARY";
//   public static final String TRANSFER_MODE_ASCII = "ASCII";
//   public static final String AUTH_METHOD_USER_PWD = "USER_PWD";
//   public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS";
//   public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode";
//   public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection";
//   public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode";
//   public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout";
//   public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds";
// }


import jetbrains.buildServer.agent.*;
import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection;
import jetbrains.buildServer.deployer.agent.BaseDeployerTest;
import jetbrains.buildServer.deployer.agent.util.DeployTestUtils;
import jetbrains.buildServer.deployer.common.FTPRunnerConstants;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.io.IOUtils;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.FixedHostPortGenericContainer;
import org.testcontainers.containers.GenericContainer;
import org.testng.annotations.*;
import java.io.*;
import java.util.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
    final File workingDir = createTempDir();

    mockeryCtx.checking(new Expectations() {{
      allowing(myContext).getWorkingDirectory();
      will(returnValue(workingDir));
      allowing(myContext).getBuild();
      will(returnValue(build));
      allowing(myContext).getRunnerParameters();
      will(returnValue(myRunnerParameters));
      allowing(build).getBuildLogger();
      will(returnValue(logger));
      allowing(build).getSharedConfigParameters();
      will(returnValue(mySharedConfigParameters));
    }});
  }

  @AfterClass
  public void tearDownClass() {
    ftp.stop();
  }

  @AfterMethod
  @Override
  public void tearDown() throws Exception {
    super.tearDown();
  }

  @Test
  public void testSimpleTransfer() throws Exception {
    myRunnerParameters.put(FTPRunnerConstants.PARAM_SSL_MODE, "2");
// Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/BaseDeployerTest.java
// public class BaseDeployerTest extends BaseTestCase {
//   protected static final int DEPLOYER_DEFAULT_PORT = 55369;
// 
//   protected File getTestResource(String fileName) {
//     final String pathInBuildAgentModule = "src/test/resources/" + fileName;
//     File file = new File(pathInBuildAgentModule);
//     if (!file.exists()) {
//       file = new File("deploy-runner-agent/" + pathInBuildAgentModule);
//     }
//     return file;
//   }
// 
//   protected DeployTestUtils.TempFilesFactory createTempFilesFactory() {
//     return new DeployTestUtils.TempFilesFactory() {
//       @Override
//       public File createTempFile(int size) throws IOException {
//         return BaseDeployerTest.this.createTempFile(size);
//       }
//     };
//   }
// }
// 
// Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/util/DeployTestUtils.java
// public class DeployTestUtils {
//   public static void runProcess(final BuildProcess process, final int timeout) throws RunBuildException {
//     process.start();
//     new WaitFor(timeout) {
//       @Override
//       protected boolean condition() {
//         return process.isFinished();
//       }
//     };
//     assertThat(process.isFinished()).describedAs("Failed to finish test in time").isTrue();
//     assertThat(process.waitFor()).isEqualTo(BuildFinishedStatus.FINISHED_SUCCESS);
//   }
// 
//   public static ArtifactsCollection buildArtifactsCollection(final TempFilesFactory tempFiles, String... destinationDirs) throws IOException {
// 
//     final Map<File, String> filePathMap = new HashMap<File, String>();
//     String dirTo = "dirTo";
//     for (String destinationDir : destinationDirs) {
//       dirTo = destinationDir;
//       final File content = tempFiles.createTempFile(100);
//       filePathMap.put(content, destinationDir);
//     }
//     return new ArtifactsCollection("dirFrom/**", dirTo, filePathMap);
//   }
// 
//   public static void assertCollectionsTransferred(File remoteBase, List<ArtifactsCollection> artifactsCollections) throws IOException {
// 
//     for (ArtifactsCollection artifactsCollection : artifactsCollections) {
//       for (Map.Entry<File, String> fileStringEntry : artifactsCollection.getFilePathMap().entrySet()) {
//         final File source = fileStringEntry.getKey();
//         final String relativePath = fileStringEntry.getValue();
//         final String targetPath = relativePath + (StringUtil.isNotEmpty(relativePath) ? File.separator : "") + source.getName();
//         final File target;
//         if (new File(targetPath).isAbsolute()) {
//           target = new File(targetPath);
//         } else {
//           target = new File(remoteBase, targetPath);
//         }
//         assertTrue(target.exists(), "Destination file [" + targetPath + "] does not exist");
//         assertEquals(FileUtil.readText(target), FileUtil.readText(source), "wrong content");
//       }
//     }
//   }
// 
//   public interface TempFilesFactory {
//     File createTempFile(int size) throws IOException;
//   }
// }
// 
// Path: deploy-runner-common/src/main/java/jetbrains/buildServer/deployer/common/FTPRunnerConstants.java
// public class FTPRunnerConstants {
//   public static final String PARAM_AUTH_METHOD = "jetbrains.buildServer.deployer.ftp.authMethod";
//   public static final String PARAM_TRANSFER_MODE = "jetbrains.buildServer.deployer.ftp.transferMethod";
//   public static final String TRANSFER_MODE_AUTO = "AUTO";
//   public static final String TRANSFER_MODE_BINARY = "BINARY";
//   public static final String TRANSFER_MODE_ASCII = "ASCII";
//   public static final String AUTH_METHOD_USER_PWD = "USER_PWD";
//   public static final String AUTH_METHOD_ANONYMOUS = "ANONYMOUS";
//   public static final String PARAM_SSL_MODE = "jetbrains.buildServer.deployer.ftp.securityMode";
//   public static final String DATA_CHANNEL_PROTECTION = "jetbrains.buildServer.deployer.ftp.dataChannelProtection";
//   public static final String PARAM_FTP_MODE = "jetbrains.buildServer.deployer.ftp.ftpMode";
//   public static final String PARAM_FTP_CONNECT_TIMEOUT = "jetbrains.deployer.ftp.connectTimeout";
//   public static final String PARAM_FTP_CONTROL_KEEP_ALIVE_TIMEOUT = "jetbrains.deployer.ftp.controlKeepAliveTimeout.seconds";
// }


// Path: deploy-runner-agent/src/test/java/jetbrains/buildServer/deployer/agent/ftp/DockerFtpBuildProcessAdapterTest.java
import jetbrains.buildServer.agent.*;
import jetbrains.buildServer.agent.impl.artifacts.ArtifactsCollection;
import jetbrains.buildServer.deployer.agent.BaseDeployerTest;
import jetbrains.buildServer.deployer.agent.util.DeployTestUtils;
import jetbrains.buildServer.deployer.common.FTPRunnerConstants;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.io.IOUtils;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.FixedHostPortGenericContainer;
import org.testcontainers.containers.GenericContainer;
import org.testng.annotations.*;
import java.io.*;
import java.util.*;
import java.util.zip.GZIPInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

    final File workingDir = createTempDir();

    mockeryCtx.checking(new Expectations() {{
      allowing(myContext).getWorkingDirectory();
      will(returnValue(workingDir));
      allowing(myContext).getBuild();
      will(returnValue(build));
      allowing(myContext).getRunnerParameters();
      will(returnValue(myRunnerParameters));
      allowing(build).getBuildLogger();
      will(returnValue(logger));
      allowing(build).getSharedConfigParameters();
      will(returnValue(mySharedConfigParameters));
    }});
  }

  @AfterClass
  public void tearDownClass() {
    ftp.stop();
  }

  @AfterMethod
  @Override
  public void tearDown() throws Exception {
    super.tearDown();
  }

  @Test
  public void testSimpleTransfer() throws Exception {
    myRunnerParameters.put(FTPRunnerConstants.PARAM_SSL_MODE, "2");
    myArtifactsCollections.add(DeployTestUtils.buildArtifactsCollection(createTempFilesFactory(),