2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright the original author or authors
|
|
|
|
*
|
|
|
|
* 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.bytestreams.ibb.packet;
|
|
|
|
|
2020-06-14 16:53:21 +02:00
|
|
|
import static org.jivesoftware.smack.test.util.XmlAssertUtil.assertXmlSimilar;
|
2020-04-06 13:25:07 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.packet.IQ;
|
2018-05-09 16:53:08 +02:00
|
|
|
import org.jivesoftware.smack.packet.StreamOpen;
|
2020-04-12 09:34:08 +02:00
|
|
|
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
|
|
|
|
|
|
|
|
import com.jamesmurty.utils.XMLBuilder;
|
2020-04-06 13:25:07 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jxmpp.jid.impl.JidCreate;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test for the Open class.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2014-02-17 23:58:40 +01:00
|
|
|
* @author Henning Staib
|
|
|
|
*/
|
2020-04-12 09:34:08 +02:00
|
|
|
public class OpenTest extends SmackTestSuite {
|
2014-02-17 23:58:40 +01:00
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
@Test
|
2014-02-17 23:58:40 +01:00
|
|
|
public void shouldNotInstantiateWithInvalidArguments1() {
|
2020-04-06 13:25:07 +02:00
|
|
|
assertThrows(IllegalArgumentException.class, () -> {
|
|
|
|
new Open(null, 1);
|
|
|
|
});
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
@Test
|
2014-02-17 23:58:40 +01:00
|
|
|
public void shouldNotInstantiateWithInvalidArguments2() {
|
2020-04-06 13:25:07 +02:00
|
|
|
assertThrows(IllegalArgumentException.class, () -> {
|
|
|
|
new Open("", 1);
|
|
|
|
});
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 13:25:07 +02:00
|
|
|
@Test
|
2014-02-17 23:58:40 +01:00
|
|
|
public void shouldNotInstantiateWithInvalidArguments3() {
|
2020-04-06 13:25:07 +02:00
|
|
|
assertThrows(IllegalArgumentException.class, () -> {
|
|
|
|
new Open("sessionID", -1);
|
|
|
|
});
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldSetIQStanzaAsDefault() {
|
|
|
|
Open open = new Open("sessionID", 4096);
|
|
|
|
assertEquals(StanzaType.IQ, open.getStanza());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldUseMessageStanzaIfGiven() {
|
|
|
|
Open open = new Open("sessionID", 4096, StanzaType.MESSAGE);
|
|
|
|
assertEquals(StanzaType.MESSAGE, open.getStanza());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldBeOfIQTypeSET() {
|
|
|
|
Open open = new Open("sessionID", 4096);
|
2014-06-06 02:20:45 +02:00
|
|
|
assertEquals(IQ.Type.set, open.getType());
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldSetAllFieldsCorrectly() {
|
|
|
|
Open open = new Open("sessionID", 4096, StanzaType.MESSAGE);
|
|
|
|
assertEquals("sessionID", open.getSessionID());
|
|
|
|
assertEquals(4096, open.getBlockSize());
|
|
|
|
assertEquals(StanzaType.MESSAGE, open.getStanza());
|
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final Properties outputProperties = new Properties();
|
2014-02-17 23:58:40 +01:00
|
|
|
{
|
|
|
|
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void shouldReturnValidIQStanzaXML() throws Exception {
|
|
|
|
String control = XMLBuilder.create("iq")
|
|
|
|
.a("from", "romeo@montague.lit/orchard")
|
|
|
|
.a("to", "juliet@capulet.lit/balcony")
|
|
|
|
.a("id", "jn3h8g65")
|
|
|
|
.a("type", "set")
|
|
|
|
.e("open")
|
|
|
|
.a("xmlns", "http://jabber.org/protocol/ibb")
|
|
|
|
.a("block-size", "4096")
|
|
|
|
.a("sid", "i781hf64")
|
|
|
|
.a("stanza", "iq")
|
|
|
|
.asString(outputProperties);
|
|
|
|
|
|
|
|
Open open = new Open("i781hf64", 4096, StanzaType.IQ);
|
2015-02-14 17:15:02 +01:00
|
|
|
open.setFrom(JidCreate.from("romeo@montague.lit/orchard"));
|
|
|
|
open.setTo(JidCreate.from("juliet@capulet.lit/balcony"));
|
2015-02-05 11:17:27 +01:00
|
|
|
open.setStanzaId("jn3h8g65");
|
2015-03-17 11:33:02 +01:00
|
|
|
|
2019-05-07 18:51:52 +02:00
|
|
|
assertXmlSimilar(control, open.toXML(StreamOpen.CLIENT_NAMESPACE).toString());
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|
2015-03-17 11:33:02 +01:00
|
|
|
|
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
}
|