BAEL-2270 Refactor - Moved classes from libraries to libraries-server (#6210)

This commit is contained in:
Diego Moreira
2019-01-24 21:32:29 -03:00
committed by GitHub
parent ef8ae28197
commit 24cf6b473d
4 changed files with 25 additions and 24 deletions

View File

@@ -71,6 +71,30 @@
<artifactId>tomcat-catalina</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-tcp</artifactId>
<version>${smack.version}</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-im</artifactId>
<version>${smack.version}</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-extensions</artifactId>
<version>${smack.version}</version>
</dependency>
<dependency>
<groupId>org.igniterealtime.smack</groupId>
<artifactId>smack-java7</artifactId>
<version>${smack.version}</version>
</dependency>
</dependencies>
<properties>
@@ -82,6 +106,7 @@
<commons.collections.version>4.1</commons.collections.version>
<junit.version>4.12</junit.version>
<tomcat.version>8.5.24</tomcat.version>
<smack.version>4.3.1</smack.version>
</properties>
</project>

View File

@@ -0,0 +1,40 @@
package com.baeldung.smack;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.chat2.Chat;
import org.jivesoftware.smack.chat2.ChatManager;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jxmpp.jid.impl.JidCreate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class StanzaThread implements Runnable {
private Logger logger = LoggerFactory.getLogger(StanzaThread.class);
@Override
public void run() {
XMPPTCPConnectionConfiguration config = null;
try {
config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("baeldung2","baeldung2")
.setXmppDomain("jabb3r.org")
.setHost("jabb3r.org")
.build();
AbstractXMPPConnection connection = new XMPPTCPConnection(config);
connection.connect();
connection.login();
ChatManager chatManager = ChatManager.getInstanceFor(connection);
Chat chat = chatManager.chatWith(JidCreate.from("baeldung@jabb3r.org").asEntityBareJidOrThrow());
chat.send("Hello!");
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}

View File

@@ -0,0 +1,85 @@
package com.baeldung.smack;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.chat2.ChatManager;
import org.jivesoftware.smack.filter.StanzaTypeFilter;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.jxmpp.stringprep.XmppStringprepException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
public class SmackIntegrationTest {
private static AbstractXMPPConnection connection;
private Logger logger = LoggerFactory.getLogger(SmackIntegrationTest.class);
@BeforeClass
public static void setup() throws IOException, InterruptedException, XMPPException, SmackException {
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("baeldung","baeldung")
.setXmppDomain("jabb3r.org")
.setHost("jabb3r.org")
.build();
XMPPTCPConnectionConfiguration config2 = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("baeldung2","baeldung2")
.setXmppDomain("jabb3r.org")
.setHost("jabb3r.org")
.build();
connection = new XMPPTCPConnection(config);
connection.connect();
connection.login();
}
@Test
public void whenSendMessageWithChat_thenReceiveMessage() throws XmppStringprepException, InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
ChatManager chatManager = ChatManager.getInstanceFor(connection);
final String[] expected = {null};
new StanzaThread().run();
chatManager.addIncomingListener((entityBareJid, message, chat) -> {
logger.info("Message arrived: " + message.getBody());
expected[0] = message.getBody();
latch.countDown();
});
latch.await();
Assert.assertEquals("Hello!", expected[0]);
}
@Test
public void whenSendMessage_thenReceiveMessageWithFilter() throws XmppStringprepException, InterruptedException {
CountDownLatch latch = new CountDownLatch(1);
final String[] expected = {null};
new StanzaThread().run();
connection.addAsyncStanzaListener(stanza -> {
if (stanza instanceof Message) {
Message message = (Message) stanza;
expected[0] = message.getBody();
latch.countDown();
}
}, StanzaTypeFilter.MESSAGE);
latch.await();
Assert.assertEquals("Hello!", expected[0]);
}
}