From ec89817a5efded4b9fb6192d0ebd9d1d16804d91 Mon Sep 17 00:00:00 2001 From: Tobias Eidelpes Date: Sat, 17 Oct 2020 18:46:46 +0200 Subject: [PATCH] Add unit tests for TransferServerProtocol --- .../transfer/TransferServerProtocolTest.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/test/java/dslab/transfer/TransferServerProtocolTest.java b/src/test/java/dslab/transfer/TransferServerProtocolTest.java index ef2c139..429b14a 100644 --- a/src/test/java/dslab/transfer/TransferServerProtocolTest.java +++ b/src/test/java/dslab/transfer/TransferServerProtocolTest.java @@ -68,4 +68,70 @@ public class TransferServerProtocolTest extends TestBase { } } + @Test(timeout = 15000) + public void sendWithoutSender_returnsErrorOnSend() throws Exception { + try (JunitSocketClient client = new JunitSocketClient(serverPort, err)) { + client.verify("ok DMTP"); + client.sendAndVerify("begin", "ok"); + client.sendAndVerify("to arthur@earth.planet", "ok 1"); + client.sendAndVerify("subject hello", "ok"); + client.sendAndVerify("data hello from junit", "ok"); + client.sendAndVerify("send", "error"); + client.sendAndVerify("quit", "ok bye"); + } + } + + @Test(timeout = 15000) + public void sendMalformedRecipient_returnsErrorOnSend_1() throws Exception { + try (JunitSocketClient client = new JunitSocketClient(serverPort, err)) { + client.verify("ok DMTP"); + client.sendAndVerify("begin", "ok"); + client.sendAndVerify("from trillian@earth.planet", "ok"); + client.sendAndVerify("to art@hur@earth.planet", "ok 1"); + client.sendAndVerify("subject hello", "ok"); + client.sendAndVerify("data hello from junit", "ok"); + client.sendAndVerify("send", "error"); + client.sendAndVerify("quit", "ok bye"); + } + } + + @Test(timeout = 15000) + public void sendMalformedRecipient_returnsErrorOnSend_2() throws Exception { + try (JunitSocketClient client = new JunitSocketClient(serverPort, err)) { + client.verify("ok DMTP"); + client.sendAndVerify("begin", "ok"); + client.sendAndVerify("from trillian@earth.planet", "ok"); + client.sendAndVerify("to arthur@", "ok 1"); + client.sendAndVerify("subject hello", "ok"); + client.sendAndVerify("data hello from junit", "ok"); + client.sendAndVerify("send", "error"); + client.sendAndVerify("quit", "ok bye"); + } + } + + @Test(timeout = 15000) + public void sendWithoutSubject_returnsOkOnSend() throws Exception { + try (JunitSocketClient client = new JunitSocketClient(serverPort, err)) { + client.verify("ok DMTP"); + client.sendAndVerify("begin", "ok"); + client.sendAndVerify("from trillian@earth.planet", "ok"); + client.sendAndVerify("to arthur@", "ok 1"); + client.sendAndVerify("data hello from junit", "ok"); + client.sendAndVerify("send", "ok"); + client.sendAndVerify("quit", "ok bye"); + } + } + + @Test(timeout = 15000) + public void sendWithoutData_returnsOkOnSend() throws Exception { + try (JunitSocketClient client = new JunitSocketClient(serverPort, err)) { + client.verify("ok DMTP"); + client.sendAndVerify("begin", "ok"); + client.sendAndVerify("from trillian@earth.planet", "ok"); + client.sendAndVerify("to arthur@", "ok 1"); + client.sendAndVerify("subject hello", "ok"); + client.sendAndVerify("send", "ok"); + client.sendAndVerify("quit", "ok bye"); + } + } }