Skip to content

Commit a90d2ba

Browse files
committed
Integration tests
1 parent 0968c80 commit a90d2ba

File tree

3 files changed

+31
-44
lines changed

3 files changed

+31
-44
lines changed

src/it/scala/client.scala

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ class FtpClient(val ftpstate: FtpState) extends Matchers {
9292
case _ => throw new IllegalStateException("Failed to receive server reply")
9393
}
9494

95-
/** send a file to the server and get the data sent */
96-
def <==(filename: String, data: Array[Byte]): (Long, Array[Byte]) = {
95+
/** send a data to the server and get the data sent */
96+
private def sendData(command: String, data: Array[Byte]): (Long, Array[Byte]) = {
9797
if (portOrPasv.isEmpty) pasvMode()
9898
val in = new ByteArrayInputStream(data)
9999
val ref = system.actorOf(DataConnector.props(this), name = "data")
100100
val x = dconSuccess(ref ? DataConnector.Send(Channels.newChannel(in), portOrPasv.get))
101-
(this <-- s"STOR $filename").code shouldBe 150
101+
(this <-- command).code shouldBe 150
102102
val t = Await.result(x, timeout.duration)
103103
delay(100 milliseconds)
104104
replies.head.code shouldBe 226
@@ -107,27 +107,29 @@ class FtpClient(val ftpstate: FtpState) extends Matchers {
107107
}
108108

109109
/** retrieve a file from the server and get the data retrieved */
110-
def <==(filename: String): (Long, Array[Byte]) = {
110+
private def readData(command: String): (Long, Array[Byte]) = {
111111
if (portOrPasv.isEmpty) pasvMode()
112112
val ref = system.actorOf(DataConnector.props(this), name = "data")
113113
val x = dconSuccess(ref ? DataConnector.Receive(portOrPasv.get))
114-
(this <-- s"RETR $filename").code shouldBe 150
114+
(this <-- command).code shouldBe 150
115115
val t = Await.result(x, timeout.duration)
116116
delay(100 milliseconds)
117117
replies.head.code shouldBe 226
118118
portOrPasv = None
119119
t
120120
}
121121

122+
def <==(filename: String, data: Array[Byte]): (Long, Array[Byte]) =
123+
sendData(s"STOR $filename", data)
124+
125+
def appe(filename: String, data: Array[Byte]): (Long, Array[Byte]) =
126+
sendData(s"APPE $filename", data)
127+
128+
def <==(filename: String): (Long, Array[Byte]) =
129+
readData(s"RETR $filename")
130+
122131
def list(command: String): (Long, String) = {
123-
if (portOrPasv.isEmpty) pasvMode()
124-
val ref = system.actorOf(DataConnector.props(this), name = "data")
125-
val x = dconSuccess(ref ? DataConnector.Receive(portOrPasv.get))
126-
(this <-- command).code shouldBe 150
127-
val t = Await.result(x, timeout.duration)
128-
delay(100 milliseconds)
129-
replies.head.code shouldBe 226
130-
portOrPasv = None
132+
val t = readData(command)
131133
(t._1, new String(t._2))
132134
}
133135
}

src/it/scala/simple_scenario_test.scala renamed to src/it/scala/flow_test.scala

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class LoginLogoutSpec extends WordSpec with BeforeAndAfterAll with Matchers {
5353
}
5454
}
5555

56-
//todo RETR, STOR, APPE, REST (with TYPE A/I)
57-
5856
// logout
5957
"QUIT command" should {
6058
"log user out and disconnect" in {
@@ -490,48 +488,34 @@ class FileTransferSpec extends WordSpec with BeforeAndAfterAll with Matchers wit
490488
}
491489

492490
"STOR command" should {
493-
"send file with type A" in {
491+
"send file with type A (unix server)" in {
494492
((client <-- "TYPE A") code) should be (200)
493+
val senddata = "\r\nline1\r\nline2\n\nline3\n"
495494
val expected = "\nline1\nline2\n\nline3\n"
496-
client <== ("my-multiline.txt", expected.getBytes)
495+
client <== ("my-multiline.txt", senddata.getBytes)
497496
server.fileData("/my-multiline.txt") should be (expected.getBytes)
498497
}
499498
"send file with type I" in {
500499
((client <-- "TYPE I") code) should be (200)
501-
val expected = "\nline1\nline2\n\nline3\n"
500+
val expected = "\r\nline1\r\nline2\n\nline3\n"
502501
client <== ("my-multiline-2.txt", expected.getBytes)
503502
server.fileData("/my-multiline-2.txt") should be (expected.getBytes)
504503
}
505504
}
506505

507-
}
508-
509-
/*
510-
class FailedSpec extends WordSpec with BeforeAndAfterAll with Matchers with CreateSampleFiles {
511-
512-
val server = new FtpServer
513-
lazy val client = new FtpClient(server.ftpstate)
514-
515-
override protected def beforeAll() {
516-
server.start()
517-
createSampleFiles()
518-
client.connect()
519-
client.login("myuser", "myuser")
520-
}
521-
522-
override protected def afterAll() {
523-
client.disconnect()
524-
server.stop()
525-
}
526-
527-
"STOR command" should {
528-
"send file with type A" in {
506+
"APPE command" should {
507+
"error on append with type A" in {
529508
((client <-- "TYPE A") code) should be (200)
530-
val expected = "\nline1\nline2\n\nline3\n"
531-
client.pasvMode()
532-
client <== ("my-multiline.txt", expected.getBytes)
509+
((client <-- "APPE /dirA/digits10.dat") code) should be (550)
510+
}
511+
"send file with type I" in {
512+
((client <-- "TYPE I") code) should be (200)
513+
val expected = "1234567890-abc\r\n\n"
514+
client appe ("/dirA/digits10.dat", "-abc\r\n\n".getBytes)
515+
server.fileData("/dirA/digits10.dat") should be (expected.getBytes)
533516
}
534517
}
535518

536519
}
537-
*/
520+
521+
//todo STAT ABOR QUIT with and without active data connection

src/it/scala/server.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class MemoryFile(val path: String, fs: MemoryFileSystem) extends File {
8686

8787
override def write(append: Boolean): WritableByteChannel = {
8888
out = new ByteArrayOutputStream
89+
if (append) out.write(fdata)
8990
Channels.newChannel(out)
9091
}
9192

0 commit comments

Comments
 (0)