From 6aae296280da44244fea0301a7abe59d4c83437f Mon Sep 17 00:00:00 2001 From: steckbrief Date: Sat, 4 Nov 2017 21:04:04 +0100 Subject: initial version of filetransfer:http extension (support for request type=list) --- .../provider/FileListProviderTest.java | 117 +++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 test/de/thedevstack/smackx/filetransferhttp/provider/FileListProviderTest.java (limited to 'test/de/thedevstack/smackx/filetransferhttp') diff --git a/test/de/thedevstack/smackx/filetransferhttp/provider/FileListProviderTest.java b/test/de/thedevstack/smackx/filetransferhttp/provider/FileListProviderTest.java new file mode 100644 index 0000000..8301dbe --- /dev/null +++ b/test/de/thedevstack/smackx/filetransferhttp/provider/FileListProviderTest.java @@ -0,0 +1,117 @@ +package de.thedevstack.smackx.filetransferhttp.provider; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.jivesoftware.smack.util.PacketParserUtils; +import org.junit.Test; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +import de.thedevstack.smackx.filetransferhttp.element.FileList; +import de.thedevstack.smackx.filetransferhttp.element.RemoteFile; +import de.thedevstack.smackx.filetransferhttp.element.RemoteFileInfo; + +public class FileListProviderTest { + + @Test + public void testParseRemoteFileInfo() throws Exception { + String xml = "" + + "my_juliet.png" + + "23456" + + "image/png" + + ""; + XmlPullParser parser = PacketParserUtils.getParserFor(xml); + FileListProvider provider = new FileListProvider(); + RemoteFileInfo info = provider.parseRemoteFileInfo(parser, 0); + assertNotNull(info); + assertEquals("my_juliet.png", info.getFilename()); + assertEquals(23456, info.getSize()); + assertEquals("image/png", info.getContentType()); + } + + @Test + public void testParseRemoteFileInfoWithMissingChildElements() throws Exception { + String xml = "" + + "23456" + + "image/png" + + ""; + XmlPullParser parser = PacketParserUtils.getParserFor(xml); + FileListProvider provider = new FileListProvider(); + RemoteFileInfo info = provider.parseRemoteFileInfo(parser, 0); + assertNull(info); + + xml = "" + + "my_juliet.png" + + "image/png" + + ""; + parser = PacketParserUtils.getParserFor(xml); + provider = new FileListProvider(); + info = provider.parseRemoteFileInfo(parser, 0); + assertNull(info); + + + xml = "" + + "my_juliet.png" + + "23456" + + ""; + parser = PacketParserUtils.getParserFor(xml); + provider = new FileListProvider(); + info = provider.parseRemoteFileInfo(parser, 0); + assertNotNull(info); + assertEquals("my_juliet.png", info.getFilename()); + assertEquals(23456, info.getSize()); + assertNull(info.getContentType()); + } + + @Test + public void testParseRemoteFile() throws XmlPullParserException, IOException { + String xml = "" + + "" + + "my_juliet.png" + + "23456" + + "image/png" + + "" + + ""; + XmlPullParser parser = PacketParserUtils.getParserFor(xml); + FileListProvider provider = new FileListProvider(); + RemoteFile file = provider.parseRemoteFile(parser, 0); + assertNotNull(file); + assertEquals(1234567890, file.getTimestamp()); + assertEquals("my_juliet.png", file.getFilename()); + assertEquals(23456, file.getSize()); + assertEquals("image/png", file.getContentType()); + assertEquals("julia@capulet.tld", file.getTo()); + assertEquals("romeo@montague.tld", file.getFrom()); + } + + @Test + public void testParse() throws Exception { + String xml = "" + + "" + + "" + + "my_juliet.png" + + "23456" + + "image/png" + + "" + + "" + + ""; + XmlPullParser parser = PacketParserUtils.getParserFor(xml); + FileListProvider provider = new FileListProvider(); + FileList fileList = provider.parse(parser, 0); + assertNotNull(fileList); + assertNotNull(fileList.getFiles()); + assertEquals(1, fileList.getFiles().size()); + RemoteFile file = fileList.getFiles().get(0); + assertEquals(1234567890, file.getTimestamp()); + assertEquals("my_juliet.png", file.getFilename()); + assertEquals(23456, file.getSize()); + assertEquals("image/png", file.getContentType()); + assertEquals("julia@capulet.tld", file.getTo()); + assertEquals("romeo@montague.tld", file.getFrom()); + } +} -- cgit v1.2.3