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.
|
|
|
|
*/
|
|
|
|
package org.jivesoftware.smackx.httpfileupload;
|
|
|
|
|
2017-07-05 19:09:30 +02:00
|
|
|
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
2017-01-29 22:07:29 +01:00
|
|
|
import org.jivesoftware.smackx.httpfileupload.element.SlotRequest;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2017-01-29 22:07:29 +01:00
|
|
|
import org.junit.Assert;
|
|
|
|
import org.junit.Test;
|
2017-03-09 21:35:29 +01:00
|
|
|
import org.jxmpp.jid.JidTestUtil;
|
2017-07-05 19:09:30 +02:00
|
|
|
import org.xml.sax.SAXException;
|
2017-01-29 22:07:29 +01:00
|
|
|
|
|
|
|
public class SlotRequestCreateTest {
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final String testRequest
|
2017-07-05 18:27:47 +02:00
|
|
|
= "<request xmlns='urn:xmpp:http:upload:0'"
|
|
|
|
+ " filename='my_juliet.png'"
|
|
|
|
+ " size='23456'"
|
|
|
|
+ " content-type='image/jpeg'"
|
|
|
|
+ "/>";
|
2017-01-29 22:07:29 +01:00
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final String testRequestWithoutContentType
|
2017-07-05 18:27:47 +02:00
|
|
|
= "<request xmlns='urn:xmpp:http:upload:0'"
|
|
|
|
+ " filename='my_romeo.png'"
|
|
|
|
+ " size='52523'"
|
|
|
|
+ "/>";
|
2017-01-29 22:07:29 +01:00
|
|
|
|
|
|
|
@Test
|
2017-07-05 19:09:30 +02:00
|
|
|
public void checkSlotRequestCreation() throws SAXException, IOException {
|
2017-03-09 21:35:29 +01:00
|
|
|
SlotRequest slotRequest = new SlotRequest(JidTestUtil.DOMAIN_BARE_JID_1, "my_juliet.png", 23456, "image/jpeg");
|
2017-01-29 22:07:29 +01:00
|
|
|
|
|
|
|
Assert.assertEquals("my_juliet.png", slotRequest.getFilename());
|
|
|
|
Assert.assertEquals(23456, slotRequest.getSize());
|
|
|
|
Assert.assertEquals("image/jpeg", slotRequest.getContentType());
|
|
|
|
|
2017-07-05 19:09:30 +02:00
|
|
|
assertXMLEqual(testRequest, slotRequest.getChildElementXML().toString());
|
2017-01-29 22:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2017-07-05 19:09:30 +02:00
|
|
|
public void checkSlotRequestCreationWithoutContentType() throws SAXException, IOException {
|
2017-03-09 21:35:29 +01:00
|
|
|
SlotRequest slotRequest = new SlotRequest(JidTestUtil.DOMAIN_BARE_JID_1, "my_romeo.png", 52523);
|
2017-01-29 22:07:29 +01:00
|
|
|
|
|
|
|
Assert.assertEquals("my_romeo.png", slotRequest.getFilename());
|
|
|
|
Assert.assertEquals(52523, slotRequest.getSize());
|
|
|
|
Assert.assertEquals(null, slotRequest.getContentType());
|
|
|
|
|
2017-07-05 19:09:30 +02:00
|
|
|
assertXMLEqual(testRequestWithoutContentType, slotRequest.getChildElementXML().toString());
|
2017-01-29 22:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class)
|
|
|
|
public void checkSlotRequestCreationNegativeSize() {
|
2017-03-09 21:35:29 +01:00
|
|
|
new SlotRequest(JidTestUtil.DOMAIN_BARE_JID_1, "my_juliet.png", -23456, "image/jpeg");
|
2017-01-29 22:07:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test(expected = IllegalArgumentException.class)
|
|
|
|
public void checkSlotRequestCreationZeroSize() {
|
2017-03-09 21:35:29 +01:00
|
|
|
new SlotRequest(JidTestUtil.DOMAIN_BARE_JID_1, "my_juliet.png", 0, "image/jpeg");
|
2017-01-29 22:07:29 +01:00
|
|
|
}
|
|
|
|
}
|