2017-01-29 22:07:29 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright © 2017 Grigory Fedorov
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2017-03-09 21:35:29 +01:00
|
|
|
package org.jivesoftware.smackx.httpfileupload.provider;
|
2017-01-29 22:07:29 +01:00
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
2017-01-29 22:07:29 +01:00
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
|
|
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2017-01-29 22:07:29 +01:00
|
|
|
import org.jivesoftware.smackx.httpfileupload.element.FileTooLargeError;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2017-01-29 22:07:29 +01:00
|
|
|
|
|
|
|
public class FileTooLargeErrorProviderTest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Example 7. Alternative response by the upload service if the file size was too large
|
|
|
|
* @see <a href="http://xmpp.org/extensions/xep-0363.html#errors">XEP-0363: HTTP File Upload 5. Error conditions</a>
|
|
|
|
*/
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final String slotErrorFileToLarge
|
2017-01-29 22:07:29 +01:00
|
|
|
= "<iq from='upload.montague.tld' "
|
|
|
|
+ "id='step_03' "
|
|
|
|
+ "to='romeo@montague.tld/garden' "
|
|
|
|
+ "type='error'>"
|
2017-03-09 21:35:29 +01:00
|
|
|
+ "<request xmlns='urn:xmpp:http:upload:0'>"
|
2017-01-29 22:07:29 +01:00
|
|
|
+ "<filename>my_juliet.png</filename>"
|
|
|
|
+ "<size>23456</size>"
|
|
|
|
+ "</request>"
|
|
|
|
+ "<error type='modify'>"
|
|
|
|
+ "<not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' />"
|
|
|
|
+ "<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>File too large. The maximum file size is 20000 bytes</text>"
|
2017-03-09 21:35:29 +01:00
|
|
|
+ "<file-too-large xmlns='urn:xmpp:http:upload:0'>"
|
2017-01-29 22:07:29 +01:00
|
|
|
+ "<max-file-size>20000</max-file-size>"
|
|
|
|
+ "</file-too-large>"
|
|
|
|
+ "</error>"
|
|
|
|
+ "</iq>";
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkSlotErrorFileToLarge() throws Exception {
|
|
|
|
IQ fileTooLargeErrorIQ = PacketParserUtils.parseStanza(slotErrorFileToLarge);
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
assertEquals(IQ.Type.error, fileTooLargeErrorIQ.getType());
|
2017-01-29 22:07:29 +01:00
|
|
|
|
|
|
|
FileTooLargeError fileTooLargeError = FileTooLargeError.from(fileTooLargeErrorIQ);
|
2019-05-06 22:06:13 +02:00
|
|
|
assertEquals(20000, fileTooLargeError.getMaxFileSize());
|
2017-01-29 22:07:29 +01:00
|
|
|
}
|
|
|
|
}
|