Search in sources :

Example 1 with FakeFtpServer

use of org.mockftpserver.fake.FakeFtpServer in project irida by phac-nml.

the class ExportUploadServiceTest method testGetResultsSubmitted.

@SuppressWarnings("unchecked")
@Test
public void testGetResultsSubmitted() throws IOException, UploadException {
    NcbiExportSubmissionService exportSubmissionService = mock(NcbiExportSubmissionService.class);
    NcbiBioSampleFiles sample2 = new NcbiBioSampleFiles();
    sample2.setId("NMLTEST2");
    NcbiBioSampleFiles sample3 = new NcbiBioSampleFiles();
    sample3.setId("NMLTEST3");
    NcbiExportSubmission submission = new NcbiExportSubmission();
    submission.setBioSampleFiles(Lists.newArrayList(sample2, sample3));
    submission.setDirectoryPath("submit/Test/example");
    when(exportSubmissionService.getSubmissionsWithState(any(Set.class))).thenReturn(Lists.newArrayList(submission));
    String report = "<?xml version='1.0' encoding='utf-8'?>\n" + "<SubmissionStatus submission_id=\"SUB189884\" status=\"processing\">\n" + "  <Action action_id=\"SUB189884-nmltest2\" target_db=\"SRA\" status=\"processing\">\n" + "    <Response status=\"processing\"/>\n" + "  </Action>\n" + "  <Action action_id=\"SUB189884-nmltest3\" target_db=\"SRA\" status=\"submitted\"/>\n" + "</SubmissionStatus>\n";
    String ftpHost = "localhost";
    String ftpUser = "test";
    String ftpPassword = "password";
    String baseDirectory = "/home/test/submit/Test";
    String submissionDirectory = baseDirectory + "/example";
    String reportFile = submissionDirectory + "/report.2.xml";
    FakeFtpServer server = new FakeFtpServer();
    server.addUserAccount(new UserAccount(ftpUser, ftpPassword, "/home/test"));
    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry(submissionDirectory));
    fileSystem.add(new FileEntry(reportFile, report));
    server.setFileSystem(fileSystem);
    // finds an open port
    server.setServerControlPort(0);
    ExportUploadService exportUploadService = new ExportUploadService(exportSubmissionService, null, new TestEmailController());
    try {
        server.start();
        int ftpPort = server.getServerControlPort();
        exportUploadService.setConnectionDetails(ftpHost, ftpPort, ftpUser, ftpPassword, baseDirectory);
        exportUploadService.updateRunningUploads();
    } finally {
        server.stop();
    }
    assertEquals("sample2 should have processing state", ExportUploadState.PROCESSING, sample2.getSubmissionStatus());
    assertEquals("sample3 should have processing state", ExportUploadState.SUBMITTED, sample3.getSubmissionStatus());
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) Set(java.util.Set) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) NcbiBioSampleFiles(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) UserAccount(org.mockftpserver.fake.UserAccount) Test(org.junit.Test)

Example 2 with FakeFtpServer

use of org.mockftpserver.fake.FakeFtpServer in project irida by phac-nml.

the class ExportUploadServiceTest method testGetResultsWithAccession.

@SuppressWarnings("unchecked")
@Test
public void testGetResultsWithAccession() throws IOException, UploadException {
    NcbiExportSubmissionService exportSubmissionService = mock(NcbiExportSubmissionService.class);
    NcbiBioSampleFiles sample2 = new NcbiBioSampleFiles();
    sample2.setId("NMLTEST2");
    NcbiExportSubmission submission = new NcbiExportSubmission();
    submission.setBioSampleFiles(Lists.newArrayList(sample2));
    submission.setDirectoryPath("submit/Test/example");
    String newAccession = "SRR12345";
    when(exportSubmissionService.getSubmissionsWithState(any(Set.class))).thenReturn(Lists.newArrayList(submission));
    String report = "<?xml version='1.0' encoding='utf-8'?>\n" + "<SubmissionStatus submission_id=\"SUB11245\" status=\"processed-ok\">\n" + "  <Action action_id=\"SUB11245-nmltest2\" target_db=\"SRA\" status=\"processed-ok\" notify_submitter=\"true\">\n" + "    <Response status=\"processed-ok\">\n" + "      <Object target_db=\"SRA\" object_id=\"RUN:3119494\" spuid_namespace=\"NML\" spuid=\"nmltest2\" accession=\"" + newAccession + "\" status=\"updated\">\n" + "        <Meta>\n" + "          <SRAStudy>SRP12345</SRAStudy>\n" + "        </Meta>\n" + "      </Object>\n" + "    </Response>\n" + "  </Action>\n" + "</SubmissionStatus>";
    String ftpHost = "localhost";
    String ftpUser = "test";
    String ftpPassword = "password";
    String baseDirectory = "/home/test/submit/Test";
    String submissionDirectory = baseDirectory + "/example";
    String reportFile = submissionDirectory + "/report.2.xml";
    FakeFtpServer server = new FakeFtpServer();
    server.addUserAccount(new UserAccount(ftpUser, ftpPassword, "/home/test"));
    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry(submissionDirectory));
    fileSystem.add(new FileEntry(reportFile, report));
    server.setFileSystem(fileSystem);
    // finds an open port
    server.setServerControlPort(0);
    ExportUploadService exportUploadService = new ExportUploadService(exportSubmissionService, null, new TestEmailController());
    try {
        server.start();
        int ftpPort = server.getServerControlPort();
        exportUploadService.setConnectionDetails(ftpHost, ftpPort, ftpUser, ftpPassword, baseDirectory);
        exportUploadService.updateRunningUploads();
    } finally {
        server.stop();
    }
    assertEquals("sample2 should have processing state", ExportUploadState.PROCESSED_OK, sample2.getSubmissionStatus());
    assertEquals("sample2 should have an accession", newAccession, sample2.getAccession());
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) Set(java.util.Set) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) NcbiBioSampleFiles(ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) UserAccount(org.mockftpserver.fake.UserAccount) Test(org.junit.Test)

Example 3 with FakeFtpServer

use of org.mockftpserver.fake.FakeFtpServer in project irida by phac-nml.

the class ExportUploadServiceTest method testUploadSubmission.

@Test
public void testUploadSubmission() throws UploadException, IOException {
    NcbiExportSubmission submission = createFakeSubmission();
    String ftpHost = "localhost";
    String ftpUser = "test";
    String ftpPassword = "password";
    String baseDirectory = "/home/test/submit/Test";
    FakeFtpServer server = new FakeFtpServer();
    server.addUserAccount(new UserAccount(ftpUser, ftpPassword, "/home/test"));
    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new DirectoryEntry(baseDirectory));
    server.setFileSystem(fileSystem);
    // finds an open port
    server.setServerControlPort(0);
    ExportUploadService exportUploadService = new ExportUploadService(null, null, new TestEmailController());
    try {
        server.start();
        int ftpPort = server.getServerControlPort();
        exportUploadService.setConnectionDetails(ftpHost, ftpPort, ftpUser, ftpPassword, baseDirectory);
        String xml = "<xml></xml>";
        exportUploadService.uploadSubmission(submission, xml);
    } finally {
        server.stop();
    }
    @SuppressWarnings("unchecked") List<String> listNames = fileSystem.listNames(baseDirectory);
    assertEquals("submission directory exists", 1, listNames.size());
    String createdDirectory = baseDirectory + "/" + listNames.iterator().next();
    assertTrue("submission.xml created", fileSystem.exists(createdDirectory + "/submission.xml"));
    assertTrue("submit.ready created", fileSystem.exists(createdDirectory + "/submit.ready"));
    SequenceFile createdFile = submission.getBioSampleFiles().iterator().next().getFiles().iterator().next().getSequenceFile();
    assertTrue("seqfile created", fileSystem.exists(createdDirectory + "/" + createdFile.getId() + ".fastq"));
}
Also used : NcbiExportSubmission(ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) SequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile) SingleEndSequenceFile(ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) TestEmailController(ca.corefacility.bioinformatics.irida.service.impl.TestEmailController) UserAccount(org.mockftpserver.fake.UserAccount) Test(org.junit.Test)

Example 4 with FakeFtpServer

use of org.mockftpserver.fake.FakeFtpServer in project cdap by caskdata.

the class LocalizationUtilsTest method testRemoteFile.

@Test
public void testRemoteFile() throws IOException {
    File directory = TEMP_FOLDER.newFolder("ftp");
    File ftpFile = new File(directory, "ftp_file");
    String ftpFileContents = "Contents of ftp_file";
    FileSystem fileSystem = new UnixFakeFileSystem();
    fileSystem.add(new FileEntry(ftpFile.getAbsolutePath(), ftpFileContents));
    String user = "user";
    String password = "password";
    FakeFtpServer ftpServer = new FakeFtpServer();
    // Use any available port
    ftpServer.setServerControlPort(0);
    ftpServer.addUserAccount(new UserAccount(user, password, directory.getAbsolutePath()));
    ftpServer.setFileSystem(fileSystem);
    ftpServer.start();
    try {
        URI uri = URI.create(String.format("ftp://%s:%s@localhost:%d/%s", user, password, ftpServer.getServerControlPort(), ftpFile.getName()));
        File localizationDir = TEMP_FOLDER.newFolder("localRemote");
        File localizedResource = LocalizationUtils.localizeResource("file1", new LocalizeResource(uri, false), localizationDir);
        Assert.assertTrue(localizedResource.exists());
        Assert.assertTrue(localizedResource.isFile());
        Assert.assertEquals(ftpFileContents, com.google.common.io.Files.toString(localizedResource, Charsets.UTF_8));
    } finally {
        ftpServer.stop();
    }
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) LocalizeResource(co.cask.cdap.internal.app.runtime.distributed.LocalizeResource) FileEntry(org.mockftpserver.fake.filesystem.FileEntry) File(java.io.File) UserAccount(org.mockftpserver.fake.UserAccount) URI(java.net.URI) Test(org.junit.Test)

Example 5 with FakeFtpServer

use of org.mockftpserver.fake.FakeFtpServer in project camel by apache.

the class FtpInitialConnectTimeoutTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    fakeFtpServer = new FakeFtpServer();
    fakeFtpServer.setServerControlPort(0);
    fakeFtpServer.start();
    super.setUp();
}
Also used : FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) Before(org.junit.Before)

Aggregations

FakeFtpServer (org.mockftpserver.fake.FakeFtpServer)7 Test (org.junit.Test)6 NcbiExportSubmission (ca.corefacility.bioinformatics.irida.model.NcbiExportSubmission)5 TestEmailController (ca.corefacility.bioinformatics.irida.service.impl.TestEmailController)5 UserAccount (org.mockftpserver.fake.UserAccount)5 FileSystem (org.mockftpserver.fake.filesystem.FileSystem)5 UnixFakeFileSystem (org.mockftpserver.fake.filesystem.UnixFakeFileSystem)5 DirectoryEntry (org.mockftpserver.fake.filesystem.DirectoryEntry)4 FileEntry (org.mockftpserver.fake.filesystem.FileEntry)3 NcbiBioSampleFiles (ca.corefacility.bioinformatics.irida.model.export.NcbiBioSampleFiles)2 Set (java.util.Set)2 SequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SequenceFile)1 SingleEndSequenceFile (ca.corefacility.bioinformatics.irida.model.sequenceFile.SingleEndSequenceFile)1 LocalizeResource (co.cask.cdap.internal.app.runtime.distributed.LocalizeResource)1 File (java.io.File)1 URI (java.net.URI)1 Before (org.junit.Before)1