1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +02:00

Created new chat manager which handles the creation of Chats.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@6213 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Alex Wenckus 2006-11-22 22:55:37 +00:00 committed by alex
parent 18a35e4e8f
commit ae6065d7cc
36 changed files with 3964 additions and 714 deletions

View file

@ -69,10 +69,6 @@ public class XHTMLExtensionTest extends SmackTestCase {
private int bodiesSent;
private int bodiesReceived;
/**
* Constructor for XHTMLExtensionTest.
* @param name
*/
public XHTMLExtensionTest(String name) {
super(name);
}
@ -84,16 +80,16 @@ public class XHTMLExtensionTest extends SmackTestCase {
*/
public void testSendSimpleXHTMLMessage() {
// User1 creates a chat with user2
Chat chat1 = getConnection(0).createChat(getBareJID(1));
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
// User1 creates a message to send to user2
Message msg = chat1.createMessage();
Message msg = new Message();
msg.setSubject("Any subject you want");
msg.setBody("Hey John, this is my new green!!!!");
// Create a XHTMLExtension Package and add it to the message
XHTMLExtension xhtmlExtension = new XHTMLExtension();
xhtmlExtension.addBody(
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
msg.addExtension(xhtmlExtension);
// User1 sends the message that contains the XHTML to user2
@ -107,62 +103,27 @@ public class XHTMLExtensionTest extends SmackTestCase {
}
/**
* Low level API test.
* 1. User_1 will send a message with XHTML to user_2
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
* is fine
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
* something is wrong
*/
* Low level API test.
* 1. User_1 will send a message with XHTML to user_2
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
* is fine
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
* something is wrong
*/
public void testSendSimpleXHTMLMessageAndDisplayReceivedXHTMLMessage() {
// Create a chat for each connection
Chat chat1 = getConnection(0).createChat(getBareJID(1));
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
// Create a Listener that listens for Messages with the extension
//"http://jabber.org/protocol/xhtml-im"
// This listener will listen on the conn2 and answer an ACK if everything is ok
PacketFilter packetFilter =
new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im");
PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) {
Message message = (Message) packet;
assertNotNull("Body is null", message.getBody());
try {
XHTMLExtension xhtmlExtension =
(XHTMLExtension) message.getExtension(
"html",
"http://jabber.org/protocol/xhtml-im");
assertNotNull(
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
xhtmlExtension);
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
String body = (String) it.next();
System.out.println(body);
}
}
catch (ClassCastException e) {
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
}
try {
chat2.sendMessage("ok");
}
catch (Exception e) {
fail("An error occured sending ack " + e.getMessage());
}
}
};
getConnection(1).addPacketListener(packetListener, packetFilter);
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
final PacketCollector chat2 = getConnection(1).createPacketCollector(
new ThreadFilter(chat1.getThreadID()));
// User1 creates a message to send to user2
Message msg = chat1.createMessage();
Message msg = new Message();
msg.setSubject("Any subject you want");
msg.setBody("Hey John, this is my new green!!!!");
// Create a XHTMLExtension Package and add it to the message
XHTMLExtension xhtmlExtension = new XHTMLExtension();
xhtmlExtension.addBody(
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
"<body><p style='font-size:large'>Hey John, this is my new <span style='color:green'>green</span><em>!!!!</em></p></body>");
msg.addExtension(xhtmlExtension);
// User1 sends the message that contains the XHTML to user2
@ -172,67 +133,65 @@ public class XHTMLExtensionTest extends SmackTestCase {
catch (Exception e) {
fail("An error occured sending the message with XHTML");
}
// Wait for 2 seconds for a reply
msg = chat1.nextMessage(1000);
assertNotNull("No reply received", msg);
Packet packet = chat2.nextResult(2000);
Message message = (Message) packet;
assertNotNull("Body is null", message.getBody());
try {
xhtmlExtension =
(XHTMLExtension) message.getExtension(
"html",
"http://jabber.org/protocol/xhtml-im");
assertNotNull(
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
xhtmlExtension);
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
String body = (String) it.next();
System.out.println(body);
}
}
catch (ClassCastException e) {
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
}
}
/**
* Low level API test. Test a message with two XHTML bodies and several XHTML tags.
* 1. User_1 will send a message with XHTML to user_2
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
* is fine
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
* something is wrong
*/
* Low level API test. Test a message with two XHTML bodies and several XHTML tags.
* 1. User_1 will send a message with XHTML to user_2
* 2. User_2 will receive the message and iterate over the XHTML bodies to check if everything
* is fine
* 3. User_1 will wait several seconds for an ACK from user_2, if none is received then
* something is wrong
*/
public void testSendComplexXHTMLMessageAndDisplayReceivedXHTMLMessage() {
// Create a chat for each connection
Chat chat1 = getConnection(0).createChat(getBareJID(1));
final Chat chat2 = new Chat(getConnection(1), getBareJID(0), chat1.getThreadID());
Chat chat1 = getConnection(0).getChatManager().createChat(getBareJID(1), null);
final PacketCollector chat2 = getConnection(1).createPacketCollector(
new ThreadFilter(chat1.getThreadID()));
// Create a Listener that listens for Messages with the extension
//"http://jabber.org/protocol/xhtml-im"
// This listener will listen on the conn2 and answer an ACK if everything is ok
PacketFilter packetFilter =
new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im");
new PacketExtensionFilter("html", "http://jabber.org/protocol/xhtml-im");
PacketListener packetListener = new PacketListener() {
public void processPacket(Packet packet) {
int received = 0;
Message message = (Message) packet;
assertNotNull("Body is null", message.getBody());
try {
XHTMLExtension xhtmlExtension =
(XHTMLExtension) message.getExtension(
"html",
"http://jabber.org/protocol/xhtml-im");
assertNotNull(
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
xhtmlExtension);
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
received++;
System.out.println((String) it.next());
}
bodiesReceived = received;
}
catch (ClassCastException e) {
fail("ClassCastException - Most probable cause is that smack providers is misconfigured");
}
}
};
getConnection(1).addPacketListener(packetListener, packetFilter);
// User1 creates a message to send to user2
Message msg = chat1.createMessage();
Message msg = new Message();
msg.setSubject("Any subject you want");
msg.setBody(
"awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
"awesome! As Emerson once said: A foolish consistency is the hobgoblin of little minds.");
// Create an XHTMLExtension and add it to the message
XHTMLExtension xhtmlExtension = new XHTMLExtension();
xhtmlExtension.addBody(
"<body xml:lang=\"es-ES\"><h1>impresionante!</h1><p>Como Emerson dijo una vez:</p><blockquote><p>Una consistencia ridícula es el espantajo de mentes pequeñas.</p></blockquote></body>");
"<body xml:lang=\"es-ES\"><h1>impresionante!</h1><p>Como Emerson dijo una vez:</p><blockquote><p>Una consistencia ridícula es el espantajo de mentes pequeñas.</p></blockquote></body>");
xhtmlExtension.addBody(
"<body xml:lang=\"en-US\"><h1>awesome!</h1><p>As Emerson once said:</p><blockquote><p>A foolish consistency is the hobgoblin of little minds.</p></blockquote></body>");
"<body xml:lang=\"en-US\"><h1>awesome!</h1><p>As Emerson once said:</p><blockquote><p>A foolish consistency is the hobgoblin of little minds.</p></blockquote></body>");
msg.addExtension(xhtmlExtension);
// User1 sends the message that contains the XHTML to user2
@ -240,16 +199,38 @@ public class XHTMLExtensionTest extends SmackTestCase {
bodiesSent = xhtmlExtension.getBodiesCount();
bodiesReceived = 0;
chat1.sendMessage(msg);
Thread.sleep(300);
}
catch (Exception e) {
fail("An error occured sending the message with XHTML");
}
Packet packet = chat2.nextResult(2000);
int received = 0;
Message message = (Message) packet;
assertNotNull("Body is null", message.getBody());
try {
xhtmlExtension =
(XHTMLExtension) message.getExtension(
"html",
"http://jabber.org/protocol/xhtml-im");
assertNotNull(
"Message without extension \"http://jabber.org/protocol/xhtml-im\"",
xhtmlExtension);
assertTrue("Message without XHTML bodies", xhtmlExtension.getBodiesCount() > 0);
for (Iterator it = xhtmlExtension.getBodies(); it.hasNext();) {
received++;
System.out.println((String) it.next());
}
bodiesReceived = received;
}
catch (ClassCastException e) {
fail("ClassCastException - Most probable cause is that smack providers is " +
"misconfigured");
}
// Wait half second so that the complete test can run
assertEquals(
"Number of sent and received XHTMP bodies does not match",
bodiesSent,
bodiesReceived);
"Number of sent and received XHTMP bodies does not match",
bodiesSent,
bodiesReceived);
}
protected int getMaxConnections() {