mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-07 05:31:08 +01:00
merged branch improve_bytestreams in trunk
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@11821 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
ef74695a1b
commit
8b54f34153
74 changed files with 11866 additions and 1902 deletions
|
|
@ -0,0 +1,81 @@
|
|||
/**
|
||||
* 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.packet.Close;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
* Test for the Close class.
|
||||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
public class CloseTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotInstantiateWithInvalidArguments1() {
|
||||
new Close(null);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotInstantiateWithInvalidArguments2() {
|
||||
new Close("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeOfIQTypeSET() {
|
||||
Close close = new Close("sessionID");
|
||||
assertEquals(IQ.Type.SET, close.getType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetAllFieldsCorrectly() {
|
||||
Close close = new Close("sessionID");
|
||||
assertEquals("sessionID", close.getSessionID());
|
||||
}
|
||||
|
||||
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", "us71g45j")
|
||||
.a("type", "set")
|
||||
.e("close")
|
||||
.a("xmlns", "http://jabber.org/protocol/ibb")
|
||||
.a("sid", "i781hf64")
|
||||
.asString(outputProperties);
|
||||
|
||||
Close close = new Close("i781hf64");
|
||||
close.setFrom("romeo@montague.lit/orchard");
|
||||
close.setTo("juliet@capulet.lit/balcony");
|
||||
close.setPacketID("us71g45j");
|
||||
|
||||
assertXMLEqual(control, close.toXML());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,95 @@
|
|||
/**
|
||||
* 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.smackx.bytestreams.ibb.packet.DataPacketExtension;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
* Test for the DataPacketExtension class.
|
||||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
public class DataPacketExtensionTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotInstantiateWithInvalidArgument1() {
|
||||
new DataPacketExtension(null, 0, "data");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotInstantiateWithInvalidArgument2() {
|
||||
new DataPacketExtension("", 0, "data");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotInstantiateWithInvalidArgument3() {
|
||||
new DataPacketExtension("sessionID", -1, "data");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotInstantiateWithInvalidArgument4() {
|
||||
new DataPacketExtension("sessionID", 70000, "data");
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotInstantiateWithInvalidArgument5() {
|
||||
new DataPacketExtension("sessionID", 0, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetAllFieldsCorrectly() {
|
||||
DataPacketExtension data = new DataPacketExtension("sessionID", 0, "data");
|
||||
assertEquals("sessionID", data.getSessionID());
|
||||
assertEquals(0, data.getSeq());
|
||||
assertEquals("data", data.getData());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullIfDataIsInvalid() {
|
||||
// pad character is not at end of data
|
||||
DataPacketExtension data = new DataPacketExtension("sessionID", 0, "BBBB=CCC");
|
||||
assertNull(data.getDecodedData());
|
||||
|
||||
// invalid Base64 character
|
||||
data = new DataPacketExtension("sessionID", 0, new String(new byte[] { 123 }));
|
||||
assertNull(data.getDecodedData());
|
||||
}
|
||||
|
||||
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("data")
|
||||
.a("xmlns", "http://jabber.org/protocol/ibb")
|
||||
.a("seq", "0")
|
||||
.a("sid", "i781hf64")
|
||||
.t("DATA")
|
||||
.asString(outputProperties);
|
||||
|
||||
DataPacketExtension data = new DataPacketExtension("i781hf64", 0, "DATA");
|
||||
assertXMLEqual(control, data.toXML());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/**
|
||||
* 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 static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smack.util.Base64;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Data;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.jamesmurty.utils.XMLBuilder;
|
||||
|
||||
/**
|
||||
* Test for the Data class.
|
||||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
public class DataTest {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldNotInstantiateWithInvalidArgument() {
|
||||
new Data(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldBeOfIQTypeSET() {
|
||||
DataPacketExtension dpe = mock(DataPacketExtension.class);
|
||||
Data data = new Data(dpe);
|
||||
assertEquals(IQ.Type.SET, data.getType());
|
||||
}
|
||||
|
||||
private static Properties outputProperties = new Properties();
|
||||
{
|
||||
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnValidIQStanzaXML() throws Exception {
|
||||
String encodedData = Base64.encodeBytes("Test".getBytes());
|
||||
|
||||
String control = XMLBuilder.create("iq")
|
||||
.a("from", "romeo@montague.lit/orchard")
|
||||
.a("to", "juliet@capulet.lit/balcony")
|
||||
.a("id", "kr91n475")
|
||||
.a("type", "set")
|
||||
.e("data")
|
||||
.a("xmlns", "http://jabber.org/protocol/ibb")
|
||||
.a("seq", "0")
|
||||
.a("sid", "i781hf64")
|
||||
.t(encodedData)
|
||||
.asString(outputProperties);
|
||||
|
||||
DataPacketExtension dpe = mock(DataPacketExtension.class);
|
||||
String dataTag = XMLBuilder.create("data")
|
||||
.a("xmlns", "http://jabber.org/protocol/ibb")
|
||||
.a("seq", "0")
|
||||
.a("sid", "i781hf64")
|
||||
.t(encodedData)
|
||||
.asString(outputProperties);
|
||||
when(dpe.toXML()).thenReturn(dataTag);
|
||||
Data data = new Data(dpe);
|
||||
data.setFrom("romeo@montague.lit/orchard");
|
||||
data.setTo("juliet@capulet.lit/balcony");
|
||||
data.setPacketID("kr91n475");
|
||||
|
||||
assertXMLEqual(control, data.toXML());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* 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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue