Example usage for org.apache.commons.net.ftp FTPReply SERVICE_READY

List of usage examples for org.apache.commons.net.ftp FTPReply SERVICE_READY

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPReply SERVICE_READY.

Prototype

int SERVICE_READY

To view the source code for org.apache.commons.net.ftp FTPReply SERVICE_READY.

Click Source Link

Usage

From source file:jenkins.plugins.publish_over_ftp.jenkins.IntegrationTest.java

@Test
public void testIntegration() throws Exception {
    final FTPClient mockFTPClient = mock(FTPClient.class);
    final int port = 21;
    final int timeout = 3000;
    final BapFtpHostConfiguration testHostConfig = new BapFtpHostConfiguration("testConfig", "testHostname",
            "testUsername", TEST_PASSWORD, "/testRemoteRoot", port, timeout, false, null, false, false) {
        @Override/* w  w  w . java  2 s. c om*/
        public FTPClient createFTPClient() {
            return mockFTPClient;
        }
    };
    new JenkinsTestHelper().setGlobalConfig(testHostConfig);
    final String dirToIgnore = "target";
    final BapFtpTransfer transfer = new BapFtpTransfer("**/*", null, "sub-home", dirToIgnore, true, false,
            false, false, false, false, null);
    final ArrayList transfers = new ArrayList(Collections.singletonList(transfer));
    final BapFtpPublisher publisher = new BapFtpPublisher(testHostConfig.getName(), false, transfers, false,
            false, null, null, null);
    final ArrayList publishers = new ArrayList(Collections.singletonList(publisher));
    final BapFtpPublisherPlugin plugin = new BapFtpPublisherPlugin(publishers, false, false, false, "master",
            null);

    final FreeStyleProject project = createFreeStyleProject();
    project.getPublishersList().add(plugin);
    final String buildDirectory = "build-dir";
    final String buildFileName = "file.txt";
    project.getBuildersList().add(new TestBuilder() {
        @Override
        public boolean perform(final AbstractBuild<?, ?> build, final Launcher launcher,
                final BuildListener listener) throws InterruptedException, IOException {
            final FilePath dir = build.getWorkspace().child(dirToIgnore).child(buildDirectory);
            dir.mkdirs();
            dir.child(buildFileName).write("Helloooooo", "UTF-8");
            build.setResult(Result.SUCCESS);
            return true;
        }
    });

    when(mockFTPClient.getReplyCode()).thenReturn(FTPReply.SERVICE_READY);
    when(mockFTPClient.login(testHostConfig.getUsername(), TEST_PASSWORD)).thenReturn(true);
    when(mockFTPClient.changeWorkingDirectory(testHostConfig.getRemoteRootDir())).thenReturn(true);
    when(mockFTPClient.setFileType(FTPClient.ASCII_FILE_TYPE)).thenReturn(true);
    when(mockFTPClient.changeWorkingDirectory(transfer.getRemoteDirectory())).thenReturn(false)
            .thenReturn(true);
    when(mockFTPClient.makeDirectory(transfer.getRemoteDirectory())).thenReturn(true);
    when(mockFTPClient.changeWorkingDirectory(buildDirectory)).thenReturn(false).thenReturn(true);
    when(mockFTPClient.makeDirectory(buildDirectory)).thenReturn(true);
    when(mockFTPClient.storeFile(eq(buildFileName), (InputStream) anyObject())).thenReturn(true);

    assertBuildStatusSuccess(project.scheduleBuild2(0).get());

    verify(mockFTPClient).connect(testHostConfig.getHostname(), testHostConfig.getPort());
    verify(mockFTPClient).storeFile(eq(buildFileName), (InputStream) anyObject());
    verify(mockFTPClient).setDefaultTimeout(testHostConfig.getTimeout());
    verify(mockFTPClient).setDataTimeout(testHostConfig.getTimeout());
}

From source file:jenkins.plugins.publish_over_ftp.BapHostConfigurationTest.java

private void expectConnectAndLogin() throws Exception {
    mockFTPClient.setDefaultTimeout(bapFtpHostConfiguration.getTimeout());
    mockFTPClient.setDataTimeout(bapFtpHostConfiguration.getTimeout());
    mockFTPClient.connect(bapFtpHostConfiguration.getHostname(), bapFtpHostConfiguration.getPort());
    expect(mockFTPClient.getReplyCode()).andReturn(FTPReply.SERVICE_READY);
    if (bapFtpHostConfiguration.isUseActiveData()) {
        mockFTPClient.enterLocalActiveMode();
    } else {/*from  ww w  .  j  a v  a 2s  .c  o  m*/
        mockFTPClient.enterLocalPassiveMode();
    }
    expect(mockFTPClient.login(bapFtpHostConfiguration.getUsername(), bapFtpHostConfiguration.getPassword()))
            .andReturn(true);
}