diff options
author | steckbrief <steckbrief@chefmail.de> | 2017-11-04 21:04:04 +0100 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2017-11-04 21:04:04 +0100 |
commit | 6aae296280da44244fea0301a7abe59d4c83437f (patch) | |
tree | 833a372a6357efb8e0a4fa20f90193cd271db3ea /test/de/thedevstack/smackx/filetransferhttp/provider |
Diffstat (limited to 'test/de/thedevstack/smackx/filetransferhttp/provider')
-rw-r--r-- | test/de/thedevstack/smackx/filetransferhttp/provider/FileListProviderTest.java | 117 |
1 files changed, 117 insertions, 0 deletions
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 = "<file-info>" + + "<filename>my_juliet.png</filename>" + + "<size>23456</size>" + + "<content-type>image/png</content-type>" + + "</file-info>"; + 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 = "<file-info>" + + "<size>23456</size>" + + "<content-type>image/png</content-type>" + + "</file-info>"; + XmlPullParser parser = PacketParserUtils.getParserFor(xml); + FileListProvider provider = new FileListProvider(); + RemoteFileInfo info = provider.parseRemoteFileInfo(parser, 0); + assertNull(info); + + xml = "<file-info>" + + "<filename>my_juliet.png</filename>" + + "<content-type>image/png</content-type>" + + "</file-info>"; + parser = PacketParserUtils.getParserFor(xml); + provider = new FileListProvider(); + info = provider.parseRemoteFileInfo(parser, 0); + assertNull(info); + + + xml = "<file-info>" + + "<filename>my_juliet.png</filename>" + + "<size>23456</size>" + + "</file-info>"; + 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 = "<file timestamp='1234567890' to='julia@capulet.tld' from='romeo@montague.tld'>" + + "<file-info>" + + "<filename>my_juliet.png</filename>" + + "<size>23456</size>" + + "<content-type>image/png</content-type>" + + "</file-info>" + + "</file>"; + 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 = "<list>" + + "<file timestamp='1234567890' to='julia@capulet.tld' from='romeo@montague.tld'>" + + "<file-info>" + + "<filename>my_juliet.png</filename>" + + "<size>23456</size>" + + "<content-type>image/png</content-type>" + + "</file-info>" + + "</file>" + + "</list>"; + 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()); + } +} |