1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-11 21:41:08 +01:00

Follow-up commit after merging support for XEP-0446: File Metadata Element

This is a follow-up commit after 441d677644 ("Initial support for
XEP-0446: File Metadata Element"). It includes the following changes

1. Use idiomatic provider design for FileMetadataElementProvider
2. Add XEP-0264 and XEP-0446 to the list of supported XEPs (both where
   added with441d6776447f)
This commit is contained in:
Florian Schmaus 2023-12-16 16:53:34 +01:00
parent 3d6fa5dbae
commit b5180f819f
4 changed files with 120 additions and 78 deletions

View file

@ -31,7 +31,6 @@ import org.jivesoftware.smackx.file_metadata.provider.FileMetadataElementProvide
import org.jivesoftware.smackx.hashes.HashManager;
import org.jivesoftware.smackx.hashes.element.HashElement;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
@ -39,8 +38,28 @@ import org.jxmpp.util.XmppDateTime;
public class FileMetadataElementTest extends SmackTestSuite {
private static Date date;
private static FileMetadataElement metadataElement;
private static final Date date;
static {
try {
date = XmppDateTime.parseDate("2015-07-26T21:46:00+01:00");
} catch (ParseException e) {
throw new IllegalStateException(e);
}
}
private static final FileMetadataElement metadataElement = FileMetadataElement.builder()
.setModificationDate(date)
.setWidth(1920)
.setHeight(1080)
.addDescription("Picture of 24th XSF Summit")
.addDescription("Foto vom 24. XSF Summit", "de")
.addHash(new HashElement(HashManager.ALGORITHM.SHA_256, "2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU="))
.setLength(63000)
.setMediaType("text/plain")
.setName("text.txt")
.setSize(6144)
.build();
private static final String expectedXml = "<file xmlns='urn:xmpp:file:metadata:0'>" +
"<date>2015-07-26T20:46:00.000+00:00</date>" +
"<width>1920</width>" +
@ -66,24 +85,6 @@ public class FileMetadataElementTest extends SmackTestSuite {
"<size>6144</size>" +
"</file>";
@BeforeAll
public static void setup() throws ParseException {
date = XmppDateTime.parseDate("2015-07-26T21:46:00+01:00");
metadataElement = FileMetadataElement.builder()
.setModificationDate(date)
.setWidth(1920)
.setHeight(1080)
.addDescription("Picture of 24th XSF Summit")
.addDescription("Foto vom 24. XSF Summit", "de")
.addHash(new HashElement(HashManager.ALGORITHM.SHA_256, "2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU="))
.setLength(63000)
.setMediaType("text/plain")
.setName("text.txt")
.setSize(6144)
.build();
}
@Test
public void testSerialization() {
assertXmlSimilar(expectedXml, metadataElement.toXML().toString());
@ -105,6 +106,28 @@ public class FileMetadataElementTest extends SmackTestSuite {
assertEquals(metadataElement, parsed);
}
@ParameterizedTest
@EnumSource(SmackTestUtil.XmlPullParserKind.class)
public void testParseUnknownExtension(SmackTestUtil.XmlPullParserKind parserKind) throws Exception {
final String xml = "<file xmlns='urn:xmpp:file:metadata:0'>" +
"<date>2015-07-26T20:46:00.000+00:00</date>" +
"<width>1920</width>" +
"<height>1080</height>" +
"<unknown-extension>foo</unknown-extension>" +
"<desc>Picture of 24th XSF Summit</desc>" +
"<desc xml:lang='de'>Foto vom 24. XSF Summit</desc>" +
"<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU=</hash>" +
"<length>63000</length>" +
"<media-type>text/plain</media-type>" +
"<name>text.txt</name>" +
"<size>6144</size>" +
"</file>";
FileMetadataElement parsed = SmackTestUtil.parse(xml, FileMetadataElementProvider.class, parserKind);
assertEquals(metadataElement, parsed);
}
@Test
public void nameIsEscaped() {
FileMetadataElement e = FileMetadataElement.builder().setName("/etc/passwd").build();