use of org.jivesoftware.smack.roster.RosterListener in project spring-integration by spring-projects.
the class PresenceListeningEndpointTests method testRosterPresenceChangeEvent.
@Test
@SuppressWarnings("unchecked")
public void testRosterPresenceChangeEvent() {
XMPPConnection connection = mock(XMPPConnection.class);
PresenceListeningEndpoint rosterEndpoint = new PresenceListeningEndpoint(connection);
QueueChannel channel = new QueueChannel();
rosterEndpoint.setOutputChannel(channel);
rosterEndpoint.setBeanFactory(mock(BeanFactory.class));
rosterEndpoint.afterPropertiesSet();
rosterEndpoint.start();
RosterListener rosterListener = (RosterListener) TestUtils.getPropertyValue(rosterEndpoint, "rosterListener");
Presence presence = new Presence(Type.available, "Hello", 1, Mode.chat);
rosterListener.presenceChanged(presence);
Message<?> message = channel.receive(10);
assertEquals(presence, message.getPayload());
}
use of org.jivesoftware.smack.roster.RosterListener in project spring-integration by spring-projects.
the class PresenceListeningEndpointTests method testWithErrorChannel.
@Test
public void testWithErrorChannel() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
XMPPConnection connection = mock(XMPPConnection.class);
bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection);
PresenceListeningEndpoint endpoint = new PresenceListeningEndpoint();
DirectChannel outChannel = new DirectChannel();
outChannel.subscribe(message -> {
throw new RuntimeException("ooops");
});
PollableChannel errorChannel = new QueueChannel();
endpoint.setBeanFactory(bf);
endpoint.setOutputChannel(outChannel);
endpoint.setErrorChannel(errorChannel);
endpoint.afterPropertiesSet();
RosterListener listener = (RosterListener) TestUtils.getPropertyValue(endpoint, "rosterListener");
Presence presence = new Presence(Type.available);
listener.presenceChanged(presence);
ErrorMessage msg = (ErrorMessage) errorChannel.receive();
assertSame(presence, ((MessagingException) msg.getPayload()).getFailedMessage().getPayload());
}
use of org.jivesoftware.smack.roster.RosterListener in project Spark by igniterealtime.
the class RosterTree method buildFromRoster.
private void buildFromRoster() {
final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
roster.addRosterListener(new RosterListener() {
@Override
public void entriesAdded(Collection<Jid> addresses) {
}
@Override
public void entriesUpdated(Collection<Jid> addresses) {
}
@Override
public void entriesDeleted(Collection<Jid> addresses) {
}
@Override
public void presenceChanged(Presence presence) {
// changePresence(presence.getFrom(), presence.getMode() == Presence.Mode.available);
}
});
for (RosterGroup group : roster.getGroups()) {
final JiveTreeNode groupNode = new JiveTreeNode(group.getName(), true);
groupNode.setAllowsChildren(true);
if (group.getEntryCount() > 0) {
rootNode.add(groupNode);
}
for (RosterEntry entry : group.getEntries()) {
String name = entry.getName();
if (name == null) {
name = entry.getJid().toString();
}
final JiveTreeNode entryNode = new JiveTreeNode(name, false);
final Presence usersPresence = PresenceManager.getPresence(entry.getJid());
addressMap.put(entryNode, entry.getJid().toString());
boolean showUnavailableAgents = true;
if (usersPresence.isAvailable() && !usersPresence.isAway()) {
groupNode.add(entryNode);
} else if (showUnavailableAgents) {
groupNode.add(entryNode);
}
changePresence(entry.getJid().toString(), usersPresence);
final DefaultTreeModel model = (DefaultTreeModel) rosterTree.getModel();
model.nodeStructureChanged(groupNode);
}
}
}
use of org.jivesoftware.smack.roster.RosterListener in project spring-integration by spring-projects.
the class PresenceListeningEndpointTests method testEndpointLifecycle.
@Test
@SuppressWarnings("unchecked")
public void testEndpointLifecycle() {
XMPPConnection connection = mock(XMPPConnection.class);
Roster roster = Roster.getInstanceFor(connection);
Set<RosterListener> rosterSet = TestUtils.getPropertyValue(roster, "rosterListeners", Set.class);
PresenceListeningEndpoint rosterEndpoint = new PresenceListeningEndpoint(connection);
rosterEndpoint.setOutputChannel(new QueueChannel());
rosterEndpoint.setBeanFactory(mock(BeanFactory.class));
rosterEndpoint.afterPropertiesSet();
assertEquals(0, rosterSet.size());
rosterEndpoint.start();
assertEquals(1, rosterSet.size());
rosterEndpoint.stop();
assertEquals(0, rosterSet.size());
}
use of org.jivesoftware.smack.roster.RosterListener in project Spark by igniterealtime.
the class WorkgroupRosterTree method buildFromRoster.
private void buildFromRoster() {
final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
roster.addRosterListener(new RosterListener() {
public void entriesAdded(Collection collection) {
}
public void entriesUpdated(Collection collection) {
}
public void entriesDeleted(Collection collection) {
}
public void presenceChanged(Presence presence) {
changePresence(presence.getFrom(), presence);
}
});
for (RosterGroup group : roster.getGroups()) {
if (workgroupList.contains(group.getName())) {
continue;
}
final JiveTreeNode groupNode = new JiveTreeNode(group.getName(), true);
groupNode.setAllowsChildren(true);
if (group.getEntryCount() > 0) {
rootNode.add(groupNode);
}
for (RosterEntry entry : group.getEntries()) {
String name = entry.getName();
if (name == null) {
name = entry.getJid().toString();
}
if (exclusionList.contains(entry.getJid())) {
continue;
}
final JiveTreeNode entryNode = new JiveTreeNode(name, false);
final Presence usersPresence = roster.getPresence(entry.getJid());
addressMap.put(entryNode, entry.getJid().asEntityBareJidOrThrow());
if (PresenceManager.isAvailable(usersPresence)) {
groupNode.add(entryNode);
} else if (showUnavailableAgents) {
groupNode.add(entryNode);
}
changePresence(entry.getJid(), usersPresence);
final DefaultTreeModel model = (DefaultTreeModel) rosterTree.getModel();
model.nodeStructureChanged(groupNode);
}
}
}
Aggregations