mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-10-31 17:25:58 +01:00
Add more HTTP File Upload SlotProvider tests
This commit is contained in:
parent
0a0066c806
commit
3a7c20ce54
1 changed files with 79 additions and 12 deletions
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Copyright © 2017 Grigory Fedorov
|
* Copyright © 2017 Grigory Fedorov, Florian Schmaus
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,41 +16,108 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.httpfileupload.provider;
|
package org.jivesoftware.smackx.httpfileupload.provider;
|
||||||
|
|
||||||
|
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
|
||||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||||
|
|
||||||
import org.jivesoftware.smackx.httpfileupload.element.Slot;
|
import org.jivesoftware.smackx.httpfileupload.element.Slot;
|
||||||
|
import org.jivesoftware.smackx.httpfileupload.element.Slot_V0_2;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SlotProviderTest {
|
public class SlotProviderTest {
|
||||||
|
|
||||||
|
private static final String PUT_URL_STRING = "https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my_juliet.png";
|
||||||
|
|
||||||
|
private static final String GET_URL_STRING = "https://download.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my_juliet.png";
|
||||||
|
|
||||||
|
private static final URL PUT_URL = urlFromString(PUT_URL_STRING);
|
||||||
|
private static final URL GET_URL = urlFromString(GET_URL_STRING);
|
||||||
|
|
||||||
|
private static URL urlFromString(String urlString) {
|
||||||
|
try {
|
||||||
|
return new URL(urlString);
|
||||||
|
}
|
||||||
|
catch (MalformedURLException e) {
|
||||||
|
throw new Error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example 6. The upload service responds with a slot
|
* Example 6. The upload service responds with a slot
|
||||||
* @see <a href="http://xmpp.org/extensions/xep-0363.html#request">XEP-0363: HTTP File Upload 4. Requesting a slot</a>
|
* @see <a href="http://xmpp.org/extensions/xep-0363.html#request">XEP-0363: HTTP File Upload 4. Requesting a slot</a>
|
||||||
*/
|
*/
|
||||||
String slotExample
|
private static final String SLOT_IQ
|
||||||
= "<iq from='upload.montague.tld' "
|
= "<iq from='upload.montague.tld' "
|
||||||
+ "id='step_03' "
|
+ "id='step_03' "
|
||||||
+ "to='romeo@montague.tld/garden' "
|
+ "to='romeo@montague.tld/garden' "
|
||||||
+ "type='result'>"
|
+ "type='result'>"
|
||||||
+ "<slot xmlns='urn:xmpp:http:upload:0'>"
|
+ "<slot xmlns='urn:xmpp:http:upload:0'>"
|
||||||
+ "<put url='https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my_juliet.png'></put>"
|
+ "<put url='" + PUT_URL_STRING + "'></put>"
|
||||||
+ "<get url='https://download.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my_juliet.png'></get>"
|
+ "<get url='" + GET_URL_STRING + "'></get>"
|
||||||
+ "</slot>"
|
+ "</slot>"
|
||||||
+ "</iq>";
|
+ "</iq>";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkSlotProvider() throws Exception {
|
public void checkSlotProvider() throws Exception {
|
||||||
Slot slot = PacketParserUtils.parseStanza(slotExample);
|
Slot slot = PacketParserUtils.parseStanza(SLOT_IQ);
|
||||||
|
|
||||||
Assert.assertEquals(IQ.Type.result, slot.getType());
|
checkUrls(slot);
|
||||||
Assert.assertEquals(new URL("https://upload.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my_juliet.png"),
|
|
||||||
slot.getPutUrl());
|
assertXMLEqual(SLOT_IQ, slot.toXML().toString());
|
||||||
Assert.assertEquals(new URL("https://download.montague.tld/4a771ac1-f0b2-4a4a-9700-f2a26fa2bb67/my_juliet.png"),
|
}
|
||||||
slot.getGetUrl());
|
|
||||||
|
private static final String SLOT_V0_2_IQ =
|
||||||
|
"<iq from='upload.montague.tld' " +
|
||||||
|
"id='step_03' " +
|
||||||
|
"to='romeo@montague.tld/garden' " +
|
||||||
|
"type='result'>" +
|
||||||
|
"<slot xmlns='urn:xmpp:http:upload'>" +
|
||||||
|
"<put>" + PUT_URL_STRING + "</put>" +
|
||||||
|
"<get>" + GET_URL_STRING + "</get>" +
|
||||||
|
"</slot>" +
|
||||||
|
"</iq>";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkSlotV0_2Provider() throws Exception {
|
||||||
|
Slot_V0_2 slot = PacketParserUtils.parseStanza(SLOT_V0_2_IQ);
|
||||||
|
|
||||||
|
checkUrls(slot);
|
||||||
|
|
||||||
|
String slotXml = slot.toXML().toString();
|
||||||
|
assertXMLEqual(SLOT_V0_2_IQ, slotXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final String SLOT_WITH_HEADERS_IQ =
|
||||||
|
"<iq from='upload.montague.tld' " +
|
||||||
|
"id='step_03' " +
|
||||||
|
"to='romeo@montague.tld/garden' " +
|
||||||
|
"type='result'>" +
|
||||||
|
"<slot xmlns='urn:xmpp:http:upload:0'>" +
|
||||||
|
"<put url='" + PUT_URL_STRING + "'>" +
|
||||||
|
"<header name='Authorization'>Basic Base64String==</header>" +
|
||||||
|
"<header name='Host'>montague.tld</header>" +
|
||||||
|
"</put>" +
|
||||||
|
"<get url='" + GET_URL_STRING + "' />" +
|
||||||
|
"</slot>" +
|
||||||
|
"</iq>";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void checkSlotWithHeaders() throws Exception {
|
||||||
|
Slot slot = PacketParserUtils.parseStanza(SLOT_WITH_HEADERS_IQ);
|
||||||
|
|
||||||
|
checkUrls(slot);
|
||||||
|
|
||||||
|
String slotXml = slot.toXML().toString();
|
||||||
|
assertXMLEqual(SLOT_WITH_HEADERS_IQ, slotXml);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkUrls(Slot slot) {
|
||||||
|
assertEquals(PUT_URL, slot.getPutUrl());
|
||||||
|
assertEquals(GET_URL, slot.getGetUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue