blob: 331a6a5f7c3d4b0f5d1f148d5918acc5712f45a7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
/*
* Copyright (c) 2015 Tarun Gupta.
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
package com.isode.stroke.serializer.payloadserializers;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.isode.stroke.serializer.payloadserializers.BytestreamsSerializer;
import com.isode.stroke.elements.Bytestreams;
import com.isode.stroke.jid.JID;
public class BytestreamsSerializerTest {
public BytestreamsSerializerTest() {
}
@Test
public void testSerialize_withoutUsedStreamHost_singleStreamHost() {
BytestreamsSerializer testling = new BytestreamsSerializer();
Bytestreams byteStreams = new Bytestreams();
byteStreams.addStreamHost(byteStreams.new StreamHost("blah.xyz.edu", new JID("user1@bar.com/bla"), 445));
byteStreams.setStreamID("hello");
String expectedResult = "<query sid=\"hello\" xmlns=\"http://jabber.org/protocol/bytestreams\">" +
"<streamhost host=\"blah.xyz.edu\" jid=\"user1@bar.com/bla\" port=\"445\"/></query>";
assertEquals(expectedResult, testling.serialize(byteStreams));
}
@Test
public void testSerialize_withoutUsedStreamHost_doubleStreamHost() {
BytestreamsSerializer testling = new BytestreamsSerializer();
Bytestreams byteStreams = new Bytestreams();
byteStreams.addStreamHost(byteStreams.new StreamHost("blah.xyz.edu", new JID("user1@bar.com/bla"), 445));
byteStreams.addStreamHost(byteStreams.new StreamHost("bal.zyx.ude", new JID("user1@baz.com/bal"), 449));
byteStreams.setStreamID("hello");
String expectedResult = "<query sid=\"hello\" xmlns=\"http://jabber.org/protocol/bytestreams\">" +
"<streamhost host=\"blah.xyz.edu\" jid=\"user1@bar.com/bla\" port=\"445\"/>" +
"<streamhost host=\"bal.zyx.ude\" jid=\"user1@baz.com/bal\" port=\"449\"/>" +
"</query>";
assertEquals(expectedResult, testling.serialize(byteStreams));
}
@Test
public void testSerialize_withUsedStreamHost() {
BytestreamsSerializer testling = new BytestreamsSerializer();
Bytestreams byteStreams = new Bytestreams();
byteStreams.addStreamHost(byteStreams.new StreamHost("blah.xyz.edu", new JID("user1@bar.com/bla"), 445));
byteStreams.setUsedStreamHost(new JID("user1@baz.com/bal"));
byteStreams.setStreamID("hello");
String expectedResult = "<query sid=\"hello\" xmlns=\"http://jabber.org/protocol/bytestreams\">" +
"<streamhost host=\"blah.xyz.edu\" jid=\"user1@bar.com/bla\" port=\"445\"/>" +
"<streamhost-used jid=\"user1@baz.com/bal\"/>" +
"</query>";
assertEquals(expectedResult, testling.serialize(byteStreams));
}
}
|