use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class UserCreationPlugin method generateMessages.
public void generateMessages() {
JiveGlobals.setProperty("conversation.maxTimeDebug", String.valueOf(DEFAULT_MAX_TIME_DEBUG));
XMPPServer server = XMPPServer.getInstance();
ExecutorService taskExecutor = Executors.newFixedThreadPool(8);
for (User user : UserManager.getInstance().getUsers()) {
final JID userJid = server.createJID(user.getUsername(), null);
System.out.println("Creating messages for user: " + userJid.getNode());
for (RosterItem ri : user.getRoster().getRosterItems()) {
final JID rosterItemJid = ri.getJid();
taskExecutor.execute(new Runnable() {
@Override
public void run() {
for (int j = 0; j < NUMBER_CONVERSATION; j++) {
String thread = RandomStringUtils.randomAlphanumeric(6);
for (int i = 0; i < NUMBER_MESSAGES; i++) {
if (i % 2 == 0) {
Message msg = new Message();
msg.setBody("Hello to " + rosterItemJid.getNode() + " from " + userJid.getNode() + ", conversation number " + j + " of " + NUMBER_CONVERSATION + ", message " + i + " of " + NUMBER_MESSAGES + " thread " + thread);
msg.setType(Message.Type.chat);
msg.setFrom(userJid);
msg.setTo(rosterItemJid);
msg.setThread(thread);
XMPPServer.getInstance().getMessageRouter().route(msg);
try {
/* otherwise monitoring plugin stores messages out of order */
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
} else {
Message msg = new Message();
msg.setBody("Hello to " + userJid.getNode() + " from " + rosterItemJid.getNode() + ", conversation number " + j + " of " + NUMBER_CONVERSATION + ", message " + i + " of " + NUMBER_MESSAGES + " thread " + thread);
msg.setType(Message.Type.chat);
msg.setFrom(rosterItemJid);
msg.setTo(userJid);
msg.setThread(thread);
XMPPServer.getInstance().getMessageRouter().route(msg);
try {
/* otherwise monitoring plugin stores messages out of order */
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
try {
Thread.sleep(DEFAULT_MAX_TIME_DEBUG);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
});
}
}
taskExecutor.shutdown();
try {
taskExecutor.awaitTermination(2, TimeUnit.HOURS);
System.out.println("Conversation generation finished");
} catch (InterruptedException e) {
e.printStackTrace();
}
JiveGlobals.deleteProperty("conversation.maxTimeDebug");
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class OfflineMessageStoreTest method shouldStoreEmptyChatMessagesWithOtherExtensions.
@Test
public void shouldStoreEmptyChatMessagesWithOtherExtensions() {
Message message = new Message();
message.setType(Message.Type.chat);
PacketExtension chatState = new PacketExtension("composing", "http://jabber.org/protocol/chatstates");
message.addExtension(chatState);
PacketExtension packetExtension2 = new PacketExtension("received", "urn:xmpp:receipts");
message.addExtension(packetExtension2);
assertTrue(OfflineMessageStore.shouldStoreMessage(message));
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class MessageCarbonsTest method testReceived.
@Test
public void testReceived() {
Message message = new Message();
message.setType(Message.Type.chat);
message.setBody("Tests");
Forwarded forwarded = new Forwarded(message);
Received received = new Received(forwarded);
String xml = received.getElement().asXML();
assertEquals("<received xmlns=\"urn:xmpp:carbons:2\"><forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded></received>", xml);
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class MessageCarbonsTest method testSent.
@Test
public void testSent() {
Message message = new Message();
message.setType(Message.Type.chat);
message.setBody("Tests");
Forwarded forwarded = new Forwarded(message);
Sent sent = new Sent(forwarded);
String xml = sent.getElement().asXML();
assertEquals("<sent xmlns=\"urn:xmpp:carbons:2\"><forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body></message></forwarded></sent>", xml);
}
use of org.xmpp.packet.Message in project Openfire by igniterealtime.
the class ForwardTest method testForwarded.
@Test
public void testForwarded() {
Message message = new Message();
message.setType(Message.Type.chat);
message.setBody("Tests");
message.addExtension(new DataForm(DataForm.Type.submit));
Forwarded forwarded = new Forwarded(message);
Forwarded forwarded2 = new Forwarded(message);
String xml1 = forwarded.getElement().asXML();
String xml2 = forwarded2.getElement().asXML();
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml1);
assertEquals("<forwarded xmlns=\"urn:xmpp:forward:0\"><message xmlns=\"jabber:client\" type=\"chat\"><body>Tests</body><x xmlns=\"jabber:x:data\" type=\"submit\"/></message></forwarded>", xml2);
}
Aggregations