1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-12-27 06:38:01 +01:00
Smack/test-unit/org/jivesoftware/smackx/bytestreams/ibb/packet/OpenTest.java

105 lines
3.4 KiB
Java
Raw Normal View History

/**
* All rights reserved. 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;
import static junit.framework.Assert.*;
import static org.custommonkey.xmlunit.XMLAssert.*;
import java.util.Properties;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
import org.junit.Test;
import com.jamesmurty.utils.XMLBuilder;
/**
* Test for the Open class.
*
* @author Henning Staib
*/
public class OpenTest {
@Test(expected = IllegalArgumentException.class)
public void shouldNotInstantiateWithInvalidArguments1() {
new Open(null, 1);
}
@Test(expected = IllegalArgumentException.class)
public void shouldNotInstantiateWithInvalidArguments2() {
new Open("", 1);
}
@Test(expected = IllegalArgumentException.class)
public void shouldNotInstantiateWithInvalidArguments3() {
new Open("sessionID", -1);
}
@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);
assertEquals(IQ.Type.SET, open.getType());
}
@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());
}
private static Properties outputProperties = new Properties();
{
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);
open.setFrom("romeo@montague.lit/orchard");
open.setTo("juliet@capulet.lit/balcony");
open.setPacketID("jn3h8g65");
assertXMLEqual(control, open.toXML());
}
}