How to use onDisconnect method of com.consol.citrus.ftp.server.FtpServerFtpLet class

Best Citrus code snippet using com.consol.citrus.ftp.server.FtpServerFtpLet.onDisconnect

Source:FtpServerFtpLet.java Github

copy

Full Screen

...121 }122 return FtpletResult.DEFAULT;123 }124 @Override125 public FtpletResult onDisconnect(FtpSession session) {126 if (!endpointConfiguration.isAutoConnect()) {127 FtpMessage response = handleMessage(FtpMessage.command(FTPCmd.QUIT)128 .arguments(Optional.ofNullable(session.getUser()).map(User::getName).orElse("unknown") + ":" +129 Optional.ofNullable(session.getUser()).map(User::getPassword).orElse("n/a")));130 if (response.hasReplyCode()) {131 writeFtpReply(session, response);132 }133 }134 if (log.isDebugEnabled()) {135 log.debug(String.format("Closing FTP connection: '%s'", session.getSessionId()));136 }137 return FtpletResult.DISCONNECT;138 }139 /**...

Full Screen

Full Screen

onDisconnect

Using AI Code Generation

copy

Full Screen

1package com.consol.citrus.ftp.server;2import com.consol.citrus.endpoint.Endpoint;3import com.consol.citrus.exceptions.CitrusRuntimeException;4import com.consol.citrus.util.FileUtils;5import org.apache.ftpserver.ftplet.*;6import org.slf4j.Logger;7import org.slf4j.LoggerFactory;8import java.io.*;9import java.util.List;10public class FtpServerFtpLet implements Ftplet {11 private static Logger log = LoggerFactory.getLogger(FtpServerFtpLet.class);12 private final FtpServerConfiguration configuration;13 private final Endpoint endpoint;14 public FtpServerFtpLet(FtpServerConfiguration configuration, Endpoint endpoint) {15 this.configuration = configuration;16 this.endpoint = endpoint;17 }18 public void init(FtpletContext ftpletContext) throws FtpException {19 }20 public void destroy() {21 }22 public FtpletResult beforeCommand(FtpSession ftpSession, FtpRequest ftpRequest) throws FtpException, IOException {23 return FtpletResult.DEFAULT;24 }25 public FtpletResult afterCommand(FtpSession ftpSession, FtpRequest ftpRequest, FtpReply ftpReply) throws FtpException, IOException {26 return FtpletResult.DEFAULT;27 }28 public FtpletResult onConnect(FtpSession ftpSession) throws FtpException, IOException {29 return FtpletResult.DEFAULT;30 }31 public FtpletResult onDisconnect(FtpSession ftpSession) throws FtpException, IOException {32 if (configuration.isAutoDelete()) {33 try {34 FileUtils.deleteFiles(configuration.getAutoDeletePath(), configuration.getAutoDeletePattern());35 log.info("Deleted all files in directory: '" + configuration.getAutoDeletePath() + "' with pattern: '" + configuration.getAutoDeletePattern() + "'");36 } catch (IOException e) {37 throw new CitrusRuntimeException("Failed to delete files from directory: '" + configuration.getAutoDeletePath() + "' with pattern: '" + configuration.getAutoDeletePattern() + "'", e);38 }39 }40 return FtpletResult.DEFAULT;41 }

Full Screen

Full Screen

onDisconnect

Using AI Code Generation

copy

Full Screen

1package org.mycompany.citrus;2import com.consol.citrus.dsl.endpoint.CitrusEndpoints;3import com.consol.citrus.dsl.runner.TestRunner;4import com.consol.citrus.dsl.testng.TestNGCitrusTest;5import com.consol.citrus.ftp.client.FtpClient;6import com.consol.citrus.ftp.message.FtpMessageHeaders;7import com.consol.citrus.ftp.server.FtpServer;8import com.consol.citrus.ftp.server.FtpServerFtpLet;9import com.consol.citrus.message.MessageType;10import org.springframework.context.annotation.Bean;11import org.springframework.context.annotation.Configuration;12import org.springframework.context.annotation.Import;13import org.testng.annotations.Test;14import java.io.File;15import java.util.Arrays;16public class FtpSampleIT extends TestNGCitrusTest {17 @Import(DefaultTestConfig.class)18 public class TestConfig {19 public FtpServer ftpServer() {20 FtpServer ftpServer = CitrusEndpoints.ftp()21 .server()22 .autoStart(true)23 .port(22222)24 .user("citrus")25 .password("citrus")26 .autoConnect(true)27 .build();28 ftpServer.getFtpServer().setFtpLets(Arrays.asList(new FtpServerFtpLet() {29 public void onDisconnect() {30 System.out.println("Disconnected");31 }32 }));33 return ftpServer;34 }35 public FtpClient ftpClient() {36 return CitrusEndpoints.ftp()37 .client()38 .port(22222)39 .autoConnect(true)40 .user("citrus")41 .password("citrus")42 .build();43 }44 }45 public void testFtp(TestRunner runner) {46 runner.ftp(ftpClient())47 .send()48 .put(new File("src/test/resources/ftp/test.txt"))49 .header(FtpMessageHeaders.FILE_NAME, "test.txt");50 runner.ftp(ftpClient())51 .receive()52 .get("test.txt");53 runner.ftp(ftpClient())54 .send()55 .delete("test.txt");56 runner.ftp(ftpClient())57 .receive()58 .delete("test.txt");59 runner.ftp(ftpClient())60 .send()61 .mkdir("test");

Full Screen

Full Screen

onDisconnect

Using AI Code Generation

copy

Full Screen

1ftpClient.disconnect();2ftpClient.connect("localhost", 2222);3ftpClient.login("test", "test");4ftpClient.changeWorkingDirectory("citrus:ftp");5ftpClient.storeFile("citrus_ftp_test.txt", new ByteArrayInputStream("Hello Citrus!".getBytes()));6ftpClient.disconnect();7ftpClient.disconnect();8ftpClient.connect("localhost", 2222);9ftpClient.login("test", "test");10ftpClient.changeWorkingDirectory("citrus:ftp");11ftpClient.storeFile("citrus_ftp_test.txt", new ByteArrayInputStream("Hello Citrus!".getBytes()));12ftpClient.disconnect();

Full Screen

Full Screen

onDisconnect

Using AI Code Generation

copy

Full Screen

1ftp:client()2 .send()3 .command("USER ${ftp.username}")4 .command("PASS ${ftp.password}")5 .command("MKD test")6 .command("CWD test")7 .command("STOR test.txt")8 .message("Hello Citrus!")9 .disconnect()10 .onDisconnect()11 .execute("ftpServerFtpLet", "disconnect");12ftp:client()13 .send()14 .command("USER ${ftp.username}")15 .command("PASS ${ftp.password}")16 .command("MKD test")17 .command("CWD test")18 .command("STOR test.txt")19 .message("Hello Citrus!")20 .disconnect()21 .onConnect()22 .execute("ftpServerFtpLet", "connect");23[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ citrus-ftp-2.8.0-SNAPSHOT ---

Full Screen

Full Screen

onDisconnect

Using AI Code Generation

copy

Full Screen

1package org.citrusframework.demo;2import com.consol.citrus.annotations.CitrusTest;3import com.consol.citrus.dsl.junit.JUnit4CitrusTestRunner;4import com.consol.citrus.ftp.client.FtpClient;5import com.consol.citrus.ftp.server.FtpServer;6import com.consol.citrus.ftp.server.FtpServerFtpLet;7import com.consol.citrus.ftp.server.FtpServerFtpLet.FtpServerFtpLetBuilder;8import com.consol.citrus.ftp.server.FtpServerProperties;9import com.consol.citrus.ftp.server.FtpServerProperties.AuthenticationMode;10import com.consol.citrus.message.MessageType;11import org.springframework.beans.factory.annotation.Autowired;12import org.springframework.core.io.ClassPathResource;13import org.testng.annotations.Test;14public class FtpServerIT extends JUnit4CitrusTestRunner {15 private FtpClient ftpClient;16 private FtpServer ftpServer;17 public void testFtpServer() {18 run(ftpServer());19 run(ftp(ftpClient)20 .send("USER anonymous")21 .receive("331 Please specify the password.")22 .send("PASS anonymous")23 .receive("230 Login successful.")24 .send("TYPE A")25 .receive("200 Switching to ASCII mode.")26 .send("PASV")27 .receive("227 Entering Passive Mode (127,0,0,1,8,225)."));28 run(ftp(ftpClient)29 .send("STOR test.txt")30 .send(new ClassPathResource("com/consol/citrus/samples/ftp/test.txt"))31 .receive("226 Transfer complete."));32 run(ftp(ftpClient)33 .send("RETR test.txt")34 .receive(new ClassPathResource("com/consol/citrus/samples/ftp/test.txt")));

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Citrus automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful