mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-10 18:59:41 +02:00
Normalize newlines to '\n'
Change all \r\n into unix style newlines. Add missing newlines at the end of a file and activate the newline checkstyle module, that enforces '\n' as newline and a newline at the end of every file.
This commit is contained in:
parent
1e57f1c659
commit
d069e1be64
364 changed files with 50349 additions and 50346 deletions
|
@ -12,45 +12,45 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.Privacy;
|
||||
import org.jivesoftware.smack.packet.PrivacyItem;
|
||||
|
||||
/**
|
||||
* This class supports automated tests about privacy communication from the
|
||||
* server to the client.
|
||||
*
|
||||
* @author Francisco Vives
|
||||
*/
|
||||
|
||||
public class PrivacyClient implements PrivacyListListener {
|
||||
/**
|
||||
* holds if the receiver list was modified
|
||||
*/
|
||||
private boolean wasModified = false;
|
||||
|
||||
/**
|
||||
* holds a privacy to hold server requests Clients should not use Privacy
|
||||
* class since it is private for the smack framework.
|
||||
*/
|
||||
private Privacy privacy = new Privacy();
|
||||
|
||||
public PrivacyClient(PrivacyListManager manager) {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
|
||||
privacy.setPrivacyList(listName, listItem);
|
||||
}
|
||||
|
||||
public void updatedPrivacyList(String listName) {
|
||||
this.wasModified = true;
|
||||
}
|
||||
|
||||
public boolean wasModified() {
|
||||
return this.wasModified;
|
||||
}
|
||||
}
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.packet.Privacy;
|
||||
import org.jivesoftware.smack.packet.PrivacyItem;
|
||||
|
||||
/**
|
||||
* This class supports automated tests about privacy communication from the
|
||||
* server to the client.
|
||||
*
|
||||
* @author Francisco Vives
|
||||
*/
|
||||
|
||||
public class PrivacyClient implements PrivacyListListener {
|
||||
/**
|
||||
* holds if the receiver list was modified
|
||||
*/
|
||||
private boolean wasModified = false;
|
||||
|
||||
/**
|
||||
* holds a privacy to hold server requests Clients should not use Privacy
|
||||
* class since it is private for the smack framework.
|
||||
*/
|
||||
private Privacy privacy = new Privacy();
|
||||
|
||||
public PrivacyClient(PrivacyListManager manager) {
|
||||
super();
|
||||
}
|
||||
|
||||
public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
|
||||
privacy.setPrivacyList(listName, listItem);
|
||||
}
|
||||
|
||||
public void updatedPrivacyList(String listName) {
|
||||
this.wasModified = true;
|
||||
}
|
||||
|
||||
public boolean wasModified() {
|
||||
return this.wasModified;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,246 +12,246 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.ping.PingManager;
|
||||
|
||||
/**
|
||||
* Tests the connection and reconnection mechanism
|
||||
*
|
||||
* @author Francisco Vives
|
||||
*/
|
||||
|
||||
public class ReconnectionTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Tests the connection and reconnection mechanism
|
||||
*
|
||||
* @author Francisco Vives
|
||||
*/
|
||||
|
||||
public class ReconnectionTest extends SmackTestCase {
|
||||
|
||||
private static final long MIN_RECONNECT_WAIT = 17; // Seconds
|
||||
|
||||
public ReconnectionTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests an automatic reconnection.
|
||||
* Simulates a connection error and then waits until gets reconnected.
|
||||
*/
|
||||
|
||||
public void testAutomaticReconnection() throws Exception {
|
||||
|
||||
public ReconnectionTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests an automatic reconnection.
|
||||
* Simulates a connection error and then waits until gets reconnected.
|
||||
*/
|
||||
|
||||
public void testAutomaticReconnection() throws Exception {
|
||||
XMPPConnection connection = getConnection(0);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Simulates an error in the connection
|
||||
connection.notifyConnectionError(new Exception("Simulated Error"));
|
||||
latch.await(MIN_RECONNECT_WAIT, TimeUnit.SECONDS);
|
||||
|
||||
// After 10 seconds, the reconnection manager must reestablishes the connection
|
||||
assertEquals("The ConnectionListener.connectionStablished() notification was not fired", true, listener.reconnected);
|
||||
assertTrue("The ReconnectionManager algorithm has reconnected without waiting at least 5 seconds", listener.attemptsNotifications > 0);
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
}
|
||||
|
||||
public void testAutomaticReconnectionWithCompression() throws Exception {
|
||||
// Create the configuration for this new connection
|
||||
ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
|
||||
config.setCompressionEnabled(true);
|
||||
config.setSASLAuthenticationEnabled(true);
|
||||
|
||||
XMPPConnection connection = new XMPPConnection(config);
|
||||
// Connect to the server
|
||||
connection.connect();
|
||||
// Log into the server
|
||||
connection.login(getUsername(0), getPassword(0), "MyOtherResource");
|
||||
|
||||
assertTrue("Failed to use compression", connection.isUsingCompression());
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Simulates an error in the connection
|
||||
connection.notifyConnectionError(new Exception("Simulated Error"));
|
||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Simulates an error in the connection
|
||||
connection.notifyConnectionError(new Exception("Simulated Error"));
|
||||
latch.await(MIN_RECONNECT_WAIT, TimeUnit.SECONDS);
|
||||
|
||||
// After 10 seconds, the reconnection manager must reestablishes the connection
|
||||
assertEquals("The ConnectionListener.connectionEstablished() notification was not fired", true, listener.reconnected);
|
||||
|
||||
// After 10 seconds, the reconnection manager must reestablishes the connection
|
||||
assertEquals("The ConnectionListener.connectionStablished() notification was not fired", true, listener.reconnected);
|
||||
assertTrue("The ReconnectionManager algorithm has reconnected without waiting at least 5 seconds", listener.attemptsNotifications > 0);
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a manual reconnection.
|
||||
* Simulates a connection error, disables the reconnection mechanism and then reconnects.
|
||||
*/
|
||||
public void testManualReconnectionWithCancelation() throws Exception {
|
||||
XMPPConnection connection = getConnection(0);
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
}
|
||||
|
||||
public void testAutomaticReconnectionWithCompression() throws Exception {
|
||||
// Create the configuration for this new connection
|
||||
ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
|
||||
config.setCompressionEnabled(true);
|
||||
config.setSASLAuthenticationEnabled(true);
|
||||
|
||||
XMPPConnection connection = new XMPPConnection(config);
|
||||
// Connect to the server
|
||||
connection.connect();
|
||||
// Log into the server
|
||||
connection.login(getUsername(0), getPassword(0), "MyOtherResource");
|
||||
|
||||
assertTrue("Failed to use compression", connection.isUsingCompression());
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Produces a connection error
|
||||
connection.notifyConnectionError(new Exception("Simulated Error"));
|
||||
assertEquals(
|
||||
"An error occurs but the ConnectionListener.connectionClosedOnError(e) was not notified",
|
||||
true, listener.connectionClosedOnError);
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Simulates an error in the connection
|
||||
connection.notifyConnectionError(new Exception("Simulated Error"));
|
||||
latch.await(MIN_RECONNECT_WAIT, TimeUnit.SECONDS);
|
||||
|
||||
// After 10 seconds, the reconnection manager must reestablishes the connection
|
||||
assertEquals("The ConnectionListener.connectionEstablished() notification was not fired", true, listener.reconnected);
|
||||
assertTrue("The ReconnectionManager algorithm has reconnected without waiting at least 5 seconds", listener.attemptsNotifications > 0);
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a manual reconnection.
|
||||
* Simulates a connection error, disables the reconnection mechanism and then reconnects.
|
||||
*/
|
||||
public void testManualReconnectionWithCancelation() throws Exception {
|
||||
XMPPConnection connection = getConnection(0);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener(latch);
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Produces a connection error
|
||||
connection.notifyConnectionError(new Exception("Simulated Error"));
|
||||
assertEquals(
|
||||
"An error occurs but the ConnectionListener.connectionClosedOnError(e) was not notified",
|
||||
true, listener.connectionClosedOnError);
|
||||
// Thread.sleep(1000);
|
||||
|
||||
// Cancels the automatic reconnection
|
||||
connection.getConfiguration().setReconnectionAllowed(false);
|
||||
// Waits for a reconnection that must not happened.
|
||||
Thread.sleep(MIN_RECONNECT_WAIT * 1000);
|
||||
// Cancels the automatic reconnection
|
||||
assertEquals(false, listener.reconnected);
|
||||
|
||||
// Makes a manual reconnection from an error terminated connection without reconnection
|
||||
connection.connect();
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a manual reconnection after a login.
|
||||
* Closes the connection and then reconnects.
|
||||
*/
|
||||
public void testCloseAndManualReconnection() throws Exception {
|
||||
XMPPConnection connection = getConnection(0);
|
||||
String username = connection.getConfiguration().getUsername();
|
||||
String password = connection.getConfiguration().getPassword();
|
||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener();
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Produces a normal disconnection
|
||||
connection.disconnect();
|
||||
assertEquals("ConnectionListener.connectionClosed() was not notified",
|
||||
true, listener.connectionClosed);
|
||||
// Waits 10 seconds waiting for a reconnection that must not happened.
|
||||
Thread.sleep(MIN_RECONNECT_WAIT * 1000);
|
||||
assertEquals("The connection was stablished but it was not allowed to", false,
|
||||
listener.reconnected);
|
||||
|
||||
// Makes a manual reconnection
|
||||
connection.connect();
|
||||
connection.login(username, password);
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a reconnection in a anonymously logged connection.
|
||||
* Closes the connection and then reconnects.
|
||||
*/
|
||||
public void testAnonymousReconnection() throws Exception {
|
||||
XMPPConnection connection = createConnection();
|
||||
connection.connect();
|
||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener();
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Makes the anounymous login
|
||||
connection.loginAnonymously();
|
||||
|
||||
// Produces a normal disconnection
|
||||
connection.disconnect();
|
||||
assertEquals("ConnectionListener.connectionClosed() was not notified",
|
||||
true, listener.connectionClosed);
|
||||
// Makes a manual reconnection
|
||||
connection.connect();
|
||||
connection.loginAnonymously();
|
||||
assertEquals("Failed the manual connection", true, connection.isAnonymous());
|
||||
}
|
||||
|
||||
private XMPPConnection createXMPPConnection() throws Exception {
|
||||
XMPPConnection connection;
|
||||
// Create the configuration
|
||||
ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
|
||||
config.setCompressionEnabled(Boolean.getBoolean("test.compressionEnabled"));
|
||||
config.setSASLAuthenticationEnabled(true);
|
||||
connection = new XMPPConnection(config);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute some server interaction in order to test that the regenerated connection works fine.
|
||||
*/
|
||||
private void executeSomeServerInteraction(XMPPConnection connection) throws XMPPException {
|
||||
PingManager pingManager = PingManager.getInstanceFor(connection);
|
||||
pingManager.pingMyServer();
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
private class XMPPConnectionTestListener implements ConnectionListener {
|
||||
|
||||
// Variables to support listener notifications verification
|
||||
private volatile boolean connectionClosed = false;
|
||||
private volatile boolean connectionClosedOnError = false;
|
||||
private volatile boolean reconnected = false;
|
||||
private volatile boolean reconnectionFailed = false;
|
||||
private volatile int remainingSeconds = 0;
|
||||
private volatile int attemptsNotifications = 0;
|
||||
|
||||
// Cancels the automatic reconnection
|
||||
connection.getConfiguration().setReconnectionAllowed(false);
|
||||
// Waits for a reconnection that must not happened.
|
||||
Thread.sleep(MIN_RECONNECT_WAIT * 1000);
|
||||
// Cancels the automatic reconnection
|
||||
assertEquals(false, listener.reconnected);
|
||||
|
||||
// Makes a manual reconnection from an error terminated connection without reconnection
|
||||
connection.connect();
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a manual reconnection after a login.
|
||||
* Closes the connection and then reconnects.
|
||||
*/
|
||||
public void testCloseAndManualReconnection() throws Exception {
|
||||
XMPPConnection connection = getConnection(0);
|
||||
String username = connection.getConfiguration().getUsername();
|
||||
String password = connection.getConfiguration().getPassword();
|
||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener();
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Produces a normal disconnection
|
||||
connection.disconnect();
|
||||
assertEquals("ConnectionListener.connectionClosed() was not notified",
|
||||
true, listener.connectionClosed);
|
||||
// Waits 10 seconds waiting for a reconnection that must not happened.
|
||||
Thread.sleep(MIN_RECONNECT_WAIT * 1000);
|
||||
assertEquals("The connection was stablished but it was not allowed to", false,
|
||||
listener.reconnected);
|
||||
|
||||
// Makes a manual reconnection
|
||||
connection.connect();
|
||||
connection.login(username, password);
|
||||
|
||||
// Executes some server interaction testing the connection
|
||||
executeSomeServerInteraction(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a reconnection in a anonymously logged connection.
|
||||
* Closes the connection and then reconnects.
|
||||
*/
|
||||
public void testAnonymousReconnection() throws Exception {
|
||||
XMPPConnection connection = createConnection();
|
||||
connection.connect();
|
||||
XMPPConnectionTestListener listener = new XMPPConnectionTestListener();
|
||||
connection.addConnectionListener(listener);
|
||||
|
||||
// Makes the anounymous login
|
||||
connection.loginAnonymously();
|
||||
|
||||
// Produces a normal disconnection
|
||||
connection.disconnect();
|
||||
assertEquals("ConnectionListener.connectionClosed() was not notified",
|
||||
true, listener.connectionClosed);
|
||||
// Makes a manual reconnection
|
||||
connection.connect();
|
||||
connection.loginAnonymously();
|
||||
assertEquals("Failed the manual connection", true, connection.isAnonymous());
|
||||
}
|
||||
|
||||
private XMPPConnection createXMPPConnection() throws Exception {
|
||||
XMPPConnection connection;
|
||||
// Create the configuration
|
||||
ConnectionConfiguration config = new ConnectionConfiguration(getHost(), getPort());
|
||||
config.setCompressionEnabled(Boolean.getBoolean("test.compressionEnabled"));
|
||||
config.setSASLAuthenticationEnabled(true);
|
||||
connection = new XMPPConnection(config);
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute some server interaction in order to test that the regenerated connection works fine.
|
||||
*/
|
||||
private void executeSomeServerInteraction(XMPPConnection connection) throws XMPPException {
|
||||
PingManager pingManager = PingManager.getInstanceFor(connection);
|
||||
pingManager.pingMyServer();
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
private class XMPPConnectionTestListener implements ConnectionListener {
|
||||
|
||||
// Variables to support listener notifications verification
|
||||
private volatile boolean connectionClosed = false;
|
||||
private volatile boolean connectionClosedOnError = false;
|
||||
private volatile boolean reconnected = false;
|
||||
private volatile boolean reconnectionFailed = false;
|
||||
private volatile int remainingSeconds = 0;
|
||||
private volatile int attemptsNotifications = 0;
|
||||
private volatile boolean reconnectionCanceled = false;
|
||||
private CountDownLatch countDownLatch;
|
||||
private CountDownLatch countDownLatch;
|
||||
|
||||
private XMPPConnectionTestListener(CountDownLatch latch) {
|
||||
countDownLatch = latch;
|
||||
}
|
||||
}
|
||||
|
||||
private XMPPConnectionTestListener() {
|
||||
}
|
||||
/**
|
||||
* Methods to test the listener.
|
||||
*/
|
||||
/**
|
||||
* Methods to test the listener.
|
||||
*/
|
||||
public void connectionClosed() {
|
||||
connectionClosed = true;
|
||||
|
||||
if (countDownLatch != null)
|
||||
if (countDownLatch != null)
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
|
||||
public void connectionClosedOnError(Exception e) {
|
||||
}
|
||||
|
||||
public void connectionClosedOnError(Exception e) {
|
||||
connectionClosedOnError = true;
|
||||
}
|
||||
|
||||
public void reconnectionCanceled() {
|
||||
reconnectionCanceled = true;
|
||||
}
|
||||
|
||||
public void reconnectionCanceled() {
|
||||
reconnectionCanceled = true;
|
||||
|
||||
if (countDownLatch != null)
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
|
||||
public void reconnectingIn(int seconds) {
|
||||
attemptsNotifications = attemptsNotifications + 1;
|
||||
}
|
||||
|
||||
public void reconnectingIn(int seconds) {
|
||||
attemptsNotifications = attemptsNotifications + 1;
|
||||
remainingSeconds = seconds;
|
||||
}
|
||||
|
||||
public void reconnectionSuccessful() {
|
||||
reconnected = true;
|
||||
}
|
||||
|
||||
public void reconnectionSuccessful() {
|
||||
reconnected = true;
|
||||
|
||||
if (countDownLatch != null)
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
|
||||
public void reconnectionFailed(Exception error) {
|
||||
reconnectionFailed = true;
|
||||
}
|
||||
|
||||
public void reconnectionFailed(Exception error) {
|
||||
reconnectionFailed = true;
|
||||
|
||||
if (countDownLatch != null)
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -707,4 +707,4 @@ public class RosterSmackTest extends SmackTestCase {
|
|||
public void entriesAdded(Collection<String> addresses) {}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,373 +12,373 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import org.jivesoftware.smack.provider.PrivacyProvider;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* Test the PrivacyProvider class with valids privacy xmls
|
||||
*
|
||||
* @author Francisco Vives
|
||||
*/
|
||||
public class PrivacyProviderTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for PrivacyTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public PrivacyProviderTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
new PrivacyProviderTest(null).testFull();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with all kind of stanzas.
|
||||
* To create the xml string based from an xml file, replace:\n with: "\n + "
|
||||
*/
|
||||
public void testFull() {
|
||||
// Make the XML to test
|
||||
String xml = ""
|
||||
+ " <iq type='result' id='getlist2' to='romeo@example.net/orchard'> "
|
||||
+ " <query xmlns='jabber:iq:privacy'> "
|
||||
+ " <active name='testFilter'/> "
|
||||
+ " <default name='testSubscription'/> "
|
||||
+ " <list name='testFilter'> "
|
||||
+ " <item type='jid' "
|
||||
+ " value='tybalt@example.com' "
|
||||
+ " action='deny' "
|
||||
+ " order='1'/> "
|
||||
+ " <item action='allow' order='2'> "
|
||||
+ " <message/> "
|
||||
+ " <presence-in/> "
|
||||
+ " <presence-out/> "
|
||||
+ " <iq/> "
|
||||
+ " </item> "
|
||||
+ " </list> "
|
||||
+ " <list name='testSubscription'> "
|
||||
+ " <item type='subscription' "
|
||||
+ " value='both' "
|
||||
+ " action='allow' "
|
||||
+ " order='10'/> "
|
||||
+ " <item type='subscription' "
|
||||
+ " value='to' "
|
||||
+ " action='allow' "
|
||||
+ " order='11'/> "
|
||||
+ " <item type='subscription' "
|
||||
+ " value='from' "
|
||||
+ " action='allow' "
|
||||
+ " order='12'/> "
|
||||
+ " <item type='subscription' "
|
||||
+ " value='none' "
|
||||
+ " action='deny' "
|
||||
+ " order='5'> "
|
||||
+ " <message/> "
|
||||
+ " </item> "
|
||||
+ " <item action='deny' order='15'/> "
|
||||
+ " </list> "
|
||||
+ " <list name='testJID'> "
|
||||
+ " <item type='jid' "
|
||||
+ " value='juliet@example.com' "
|
||||
+ " action='allow' "
|
||||
+ " order='6'/> "
|
||||
+ " <item type='jid' "
|
||||
+ " value='benvolio@example.org/palm' "
|
||||
+ " action='deny' "
|
||||
+ " order='7'/> "
|
||||
+ " <item type='jid' "
|
||||
+ " action='allow' "
|
||||
+ " order='42'/> "
|
||||
+ " <item action='deny' order='666'/> "
|
||||
+ " </list> "
|
||||
+ " <list name='testGroup'> "
|
||||
+ " <item type='group' "
|
||||
+ " value='Enemies' "
|
||||
+ " action='deny' "
|
||||
+ " order='4'> "
|
||||
+ " <message/> "
|
||||
+ " </item> "
|
||||
+ " <item action='deny' order='666'/> "
|
||||
+ " </list> "
|
||||
+ " <list name='testEmpty'/> "
|
||||
+ " </query> "
|
||||
+ " <error type='cancel'> "
|
||||
+ " <item-not-found "
|
||||
+ " xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> "
|
||||
+ " </error> "
|
||||
+ "</iq> ";
|
||||
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser);
|
||||
|
||||
// check if it exist
|
||||
assertNotNull(packet);
|
||||
// assertEquals(xml, packet.getChildElementXML());
|
||||
|
||||
// check the default and active names
|
||||
assertEquals("testFilter", packet.getActiveName());
|
||||
assertEquals("testSubscription", packet.getDefaultName());
|
||||
|
||||
// check the list
|
||||
assertEquals(2, packet.getPrivacyList("testFilter").size());
|
||||
assertEquals(5, packet.getPrivacyList("testSubscription").size());
|
||||
assertEquals(4, packet.getPrivacyList("testJID").size());
|
||||
assertEquals(2, packet.getPrivacyList("testGroup").size());
|
||||
assertEquals(0, packet.getPrivacyList("testEmpty").size());
|
||||
|
||||
// check each privacy item
|
||||
PrivacyItem item = packet.getItem("testGroup", 4);
|
||||
assertEquals("Enemies", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.group, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(true, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(false, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testFilter", 1);
|
||||
assertEquals("tybalt@example.com", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.jid, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testFilter", 2);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(null, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(true, item.isFilterMessage());
|
||||
assertEquals(true, item.isFilterIQ());
|
||||
assertEquals(true, item.isFilterPresence_in());
|
||||
assertEquals(true, item.isFilterPresence_out());
|
||||
assertEquals(false, item.isFilterEverything());
|
||||
|
||||
// TEST THE testSubscription LIST
|
||||
item = packet.getItem("testSubscription", 10);
|
||||
assertEquals("both", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.subscription, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testSubscription", 11);
|
||||
assertEquals("to", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.subscription, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testSubscription", 12);
|
||||
assertEquals("from", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.subscription, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testSubscription", 5);
|
||||
assertEquals("none", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.subscription, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(true, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(false, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testSubscription", 15);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(null, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
// TEST THE testJID LIST
|
||||
|
||||
item = packet.getItem("testJID", 6);
|
||||
assertEquals("juliet@example.com", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.jid, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testJID", 7);
|
||||
assertEquals("benvolio@example.org/palm", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.jid, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testJID", 42);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(PrivacyItem.Type.jid, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testJID", 666);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(null, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
// TEST THE testGroup LIST
|
||||
|
||||
item = packet.getItem("testGroup", 4);
|
||||
assertEquals("Enemies", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.group, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(true, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(false, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testGroup", 666);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(null, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with empty lists. It includes the active,
|
||||
* default and special list.
|
||||
* To create the xml string based from an xml file, replace:\n with: "\n + "
|
||||
*/
|
||||
public void testEmptyLists() {
|
||||
// Make the XML to test
|
||||
String xml = ""
|
||||
+ " <iq type='result' id='getlist1' to='romeo@example.net/orchard'> "
|
||||
+ " <query xmlns='jabber:iq:privacy'> "
|
||||
+ " <active/> "
|
||||
+ " <default name='public'/> "
|
||||
+ " <list name='public'/> "
|
||||
+ " <list name='private'/> "
|
||||
+ " <list name='special'/> "
|
||||
+ " </query> "
|
||||
+ " </iq> ";
|
||||
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser);
|
||||
|
||||
assertNotNull(packet);
|
||||
assertNotNull(packet.getChildElementXML());
|
||||
|
||||
assertEquals("public", packet.getDefaultName());
|
||||
assertEquals(null, packet.getActiveName());
|
||||
|
||||
assertEquals(0, packet.getPrivacyList("public").size());
|
||||
assertEquals(0, packet.getPrivacyList("private").size());
|
||||
assertEquals(0, packet.getPrivacyList("special").size());
|
||||
|
||||
assertEquals(true, packet.isDeclineActiveList());
|
||||
assertEquals(false, packet.isDeclineDefaultList());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with empty lists. It includes the active,
|
||||
* default and special list.
|
||||
* To create the xml string based from an xml file, replace:\n with: "\n + "
|
||||
*/
|
||||
public void testDeclineLists() {
|
||||
// Make the XML to test
|
||||
String xml = ""
|
||||
+ " <iq type='result' id='getlist1' to='romeo@example.net/orchard'> "
|
||||
+ " <query xmlns='jabber:iq:privacy'> "
|
||||
+ " <active/> "
|
||||
+ " <default/> "
|
||||
+ " </query> "
|
||||
+ " </iq> ";
|
||||
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser);
|
||||
|
||||
assertNotNull(packet);
|
||||
|
||||
assertEquals(null, packet.getDefaultName());
|
||||
assertEquals(null, packet.getActiveName());
|
||||
|
||||
assertEquals(true, packet.isDeclineActiveList());
|
||||
assertEquals(true, packet.isDeclineDefaultList());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private XmlPullParser getParserFromXML(String xml) throws XmlPullParserException {
|
||||
MXParser parser = new MXParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(new StringReader(xml));
|
||||
return parser;
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
package org.jivesoftware.smack.packet;
|
||||
|
||||
import org.jivesoftware.smack.provider.PrivacyProvider;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
/**
|
||||
* Test the PrivacyProvider class with valids privacy xmls
|
||||
*
|
||||
* @author Francisco Vives
|
||||
*/
|
||||
public class PrivacyProviderTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor for PrivacyTest.
|
||||
* @param arg0
|
||||
*/
|
||||
public PrivacyProviderTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
try {
|
||||
new PrivacyProviderTest(null).testFull();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with all kind of stanzas.
|
||||
* To create the xml string based from an xml file, replace:\n with: "\n + "
|
||||
*/
|
||||
public void testFull() {
|
||||
// Make the XML to test
|
||||
String xml = ""
|
||||
+ " <iq type='result' id='getlist2' to='romeo@example.net/orchard'> "
|
||||
+ " <query xmlns='jabber:iq:privacy'> "
|
||||
+ " <active name='testFilter'/> "
|
||||
+ " <default name='testSubscription'/> "
|
||||
+ " <list name='testFilter'> "
|
||||
+ " <item type='jid' "
|
||||
+ " value='tybalt@example.com' "
|
||||
+ " action='deny' "
|
||||
+ " order='1'/> "
|
||||
+ " <item action='allow' order='2'> "
|
||||
+ " <message/> "
|
||||
+ " <presence-in/> "
|
||||
+ " <presence-out/> "
|
||||
+ " <iq/> "
|
||||
+ " </item> "
|
||||
+ " </list> "
|
||||
+ " <list name='testSubscription'> "
|
||||
+ " <item type='subscription' "
|
||||
+ " value='both' "
|
||||
+ " action='allow' "
|
||||
+ " order='10'/> "
|
||||
+ " <item type='subscription' "
|
||||
+ " value='to' "
|
||||
+ " action='allow' "
|
||||
+ " order='11'/> "
|
||||
+ " <item type='subscription' "
|
||||
+ " value='from' "
|
||||
+ " action='allow' "
|
||||
+ " order='12'/> "
|
||||
+ " <item type='subscription' "
|
||||
+ " value='none' "
|
||||
+ " action='deny' "
|
||||
+ " order='5'> "
|
||||
+ " <message/> "
|
||||
+ " </item> "
|
||||
+ " <item action='deny' order='15'/> "
|
||||
+ " </list> "
|
||||
+ " <list name='testJID'> "
|
||||
+ " <item type='jid' "
|
||||
+ " value='juliet@example.com' "
|
||||
+ " action='allow' "
|
||||
+ " order='6'/> "
|
||||
+ " <item type='jid' "
|
||||
+ " value='benvolio@example.org/palm' "
|
||||
+ " action='deny' "
|
||||
+ " order='7'/> "
|
||||
+ " <item type='jid' "
|
||||
+ " action='allow' "
|
||||
+ " order='42'/> "
|
||||
+ " <item action='deny' order='666'/> "
|
||||
+ " </list> "
|
||||
+ " <list name='testGroup'> "
|
||||
+ " <item type='group' "
|
||||
+ " value='Enemies' "
|
||||
+ " action='deny' "
|
||||
+ " order='4'> "
|
||||
+ " <message/> "
|
||||
+ " </item> "
|
||||
+ " <item action='deny' order='666'/> "
|
||||
+ " </list> "
|
||||
+ " <list name='testEmpty'/> "
|
||||
+ " </query> "
|
||||
+ " <error type='cancel'> "
|
||||
+ " <item-not-found "
|
||||
+ " xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/> "
|
||||
+ " </error> "
|
||||
+ "</iq> ";
|
||||
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser);
|
||||
|
||||
// check if it exist
|
||||
assertNotNull(packet);
|
||||
// assertEquals(xml, packet.getChildElementXML());
|
||||
|
||||
// check the default and active names
|
||||
assertEquals("testFilter", packet.getActiveName());
|
||||
assertEquals("testSubscription", packet.getDefaultName());
|
||||
|
||||
// check the list
|
||||
assertEquals(2, packet.getPrivacyList("testFilter").size());
|
||||
assertEquals(5, packet.getPrivacyList("testSubscription").size());
|
||||
assertEquals(4, packet.getPrivacyList("testJID").size());
|
||||
assertEquals(2, packet.getPrivacyList("testGroup").size());
|
||||
assertEquals(0, packet.getPrivacyList("testEmpty").size());
|
||||
|
||||
// check each privacy item
|
||||
PrivacyItem item = packet.getItem("testGroup", 4);
|
||||
assertEquals("Enemies", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.group, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(true, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(false, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testFilter", 1);
|
||||
assertEquals("tybalt@example.com", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.jid, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testFilter", 2);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(null, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(true, item.isFilterMessage());
|
||||
assertEquals(true, item.isFilterIQ());
|
||||
assertEquals(true, item.isFilterPresence_in());
|
||||
assertEquals(true, item.isFilterPresence_out());
|
||||
assertEquals(false, item.isFilterEverything());
|
||||
|
||||
// TEST THE testSubscription LIST
|
||||
item = packet.getItem("testSubscription", 10);
|
||||
assertEquals("both", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.subscription, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testSubscription", 11);
|
||||
assertEquals("to", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.subscription, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testSubscription", 12);
|
||||
assertEquals("from", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.subscription, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testSubscription", 5);
|
||||
assertEquals("none", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.subscription, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(true, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(false, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testSubscription", 15);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(null, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
// TEST THE testJID LIST
|
||||
|
||||
item = packet.getItem("testJID", 6);
|
||||
assertEquals("juliet@example.com", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.jid, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testJID", 7);
|
||||
assertEquals("benvolio@example.org/palm", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.jid, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testJID", 42);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(PrivacyItem.Type.jid, item.getType());
|
||||
assertEquals(true, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testJID", 666);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(null, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
// TEST THE testGroup LIST
|
||||
|
||||
item = packet.getItem("testGroup", 4);
|
||||
assertEquals("Enemies", item.getValue());
|
||||
assertEquals(PrivacyItem.Type.group, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(true, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(false, item.isFilterEverything());
|
||||
|
||||
item = packet.getItem("testGroup", 666);
|
||||
assertEquals(null, item.getValue());
|
||||
assertEquals(null, item.getType());
|
||||
assertEquals(false, item.isAllow());
|
||||
assertEquals(false, item.isFilterMessage());
|
||||
assertEquals(false, item.isFilterIQ());
|
||||
assertEquals(false, item.isFilterPresence_in());
|
||||
assertEquals(false, item.isFilterPresence_out());
|
||||
assertEquals(true, item.isFilterEverything());
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with empty lists. It includes the active,
|
||||
* default and special list.
|
||||
* To create the xml string based from an xml file, replace:\n with: "\n + "
|
||||
*/
|
||||
public void testEmptyLists() {
|
||||
// Make the XML to test
|
||||
String xml = ""
|
||||
+ " <iq type='result' id='getlist1' to='romeo@example.net/orchard'> "
|
||||
+ " <query xmlns='jabber:iq:privacy'> "
|
||||
+ " <active/> "
|
||||
+ " <default name='public'/> "
|
||||
+ " <list name='public'/> "
|
||||
+ " <list name='private'/> "
|
||||
+ " <list name='special'/> "
|
||||
+ " </query> "
|
||||
+ " </iq> ";
|
||||
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser);
|
||||
|
||||
assertNotNull(packet);
|
||||
assertNotNull(packet.getChildElementXML());
|
||||
|
||||
assertEquals("public", packet.getDefaultName());
|
||||
assertEquals(null, packet.getActiveName());
|
||||
|
||||
assertEquals(0, packet.getPrivacyList("public").size());
|
||||
assertEquals(0, packet.getPrivacyList("private").size());
|
||||
assertEquals(0, packet.getPrivacyList("special").size());
|
||||
|
||||
assertEquals(true, packet.isDeclineActiveList());
|
||||
assertEquals(false, packet.isDeclineDefaultList());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with empty lists. It includes the active,
|
||||
* default and special list.
|
||||
* To create the xml string based from an xml file, replace:\n with: "\n + "
|
||||
*/
|
||||
public void testDeclineLists() {
|
||||
// Make the XML to test
|
||||
String xml = ""
|
||||
+ " <iq type='result' id='getlist1' to='romeo@example.net/orchard'> "
|
||||
+ " <query xmlns='jabber:iq:privacy'> "
|
||||
+ " <active/> "
|
||||
+ " <default/> "
|
||||
+ " </query> "
|
||||
+ " </iq> ";
|
||||
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
Privacy packet = (Privacy) (new PrivacyProvider()).parseIQ(parser);
|
||||
|
||||
assertNotNull(packet);
|
||||
|
||||
assertEquals(null, packet.getDefaultName());
|
||||
assertEquals(null, packet.getActiveName());
|
||||
|
||||
assertEquals(true, packet.isDeclineActiveList());
|
||||
assertEquals(true, packet.isDeclineDefaultList());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private XmlPullParser getParserFromXML(String xml) throws XmlPullParserException {
|
||||
MXParser parser = new MXParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(new StringReader(xml));
|
||||
return parser;
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -14,190 +14,190 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class XMPPErrorTest extends SmackTestCase {
|
||||
|
||||
public XMPPErrorTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the creation of a new xmppError locally.
|
||||
*/
|
||||
public void testLocalErrorCreation() {
|
||||
XMPPError error = new XMPPError(XMPPError.Condition.item_not_found);
|
||||
error.toXML();
|
||||
|
||||
assertEquals(error.getCondition(), "item-not-found");
|
||||
assertEquals(error.getCode(), 404);
|
||||
assertEquals(error.getType(), XMPPError.Type.CANCEL);
|
||||
assertNull(error.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the creation of a new xmppError locally.
|
||||
*/
|
||||
public void testLocalErrorWithCommentCreation() {
|
||||
String message = "Error Message";
|
||||
XMPPError error = new XMPPError(XMPPError.Condition.item_not_found, message);
|
||||
error.toXML();
|
||||
|
||||
assertEquals(error.getCondition(), "item-not-found");
|
||||
assertEquals(error.getCode(), 404);
|
||||
assertEquals(error.getType(), XMPPError.Type.CANCEL);
|
||||
assertEquals(error.getMessage(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the creation of a new xmppError locally where there is not a default defined.
|
||||
*/
|
||||
public void testUserDefinedErrorWithCommentCreation() {
|
||||
String message = "Error Message";
|
||||
XMPPError error = new XMPPError(new XMPPError.Condition("my_own_error"), message);
|
||||
error.toXML();
|
||||
|
||||
assertEquals(error.getCondition(), "my_own_error");
|
||||
assertEquals(error.getCode(), 0);
|
||||
assertNull(error.getType());
|
||||
assertEquals(error.getMessage(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with the 404 error.
|
||||
*/
|
||||
public void test404() {
|
||||
// Make the XML to test
|
||||
String xml = "<error code='404' type='cancel'>" +
|
||||
"<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"</error></iq>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError packet = parseError(parser);
|
||||
|
||||
assertNotNull(packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with the 404 error.
|
||||
*/
|
||||
public void testCancel() {
|
||||
// Make the XML to test
|
||||
String xml = "<error type='cancel'>" +
|
||||
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"</error>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError error = parseError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testMessageAndApplicationDefinedError() {
|
||||
String xml = "<error type='modify' code='404'>" +
|
||||
"<undefined-condition xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>" +
|
||||
"Some special application diagnostic information..." +
|
||||
"</text>" +
|
||||
"<special-application-condition xmlns='application-ns'/>" +
|
||||
"</error>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError error = parseError(parser);
|
||||
|
||||
String sendingXML = error.toXML();
|
||||
|
||||
assertNotNull(error);
|
||||
assertNotNull(sendingXML);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check the parser with an xml with the 404 error.
|
||||
*/
|
||||
public void testCancelWithMessage() {
|
||||
// Make the XML to test
|
||||
String xml = "<error type='cancel'>" +
|
||||
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' xml:lang='langcode'>" +
|
||||
"Some special application diagnostic information!" +
|
||||
"</text>" +
|
||||
"</error>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError error = parseError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with the 404 error.
|
||||
*/
|
||||
public void testCancelWithMessageAndApplicationError() {
|
||||
// Make the XML to test
|
||||
String xml = "<error type='cancel' code='10'>" +
|
||||
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" +
|
||||
"Some special application diagnostic information!" +
|
||||
"</text>" +
|
||||
"<application-defined-error xmlns='application-ns'/>" +
|
||||
"</error>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError error = parseError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private XMPPError parseError(XmlPullParser parser) throws Exception {
|
||||
parser.next();
|
||||
return PacketParserUtils.parseError(parser);
|
||||
}
|
||||
|
||||
private XmlPullParser getParserFromXML(String xml) throws XmlPullParserException {
|
||||
MXParser parser = new MXParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(new StringReader(xml));
|
||||
return parser;
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import java.io.StringReader;
|
||||
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
public class XMPPErrorTest extends SmackTestCase {
|
||||
|
||||
public XMPPErrorTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the creation of a new xmppError locally.
|
||||
*/
|
||||
public void testLocalErrorCreation() {
|
||||
XMPPError error = new XMPPError(XMPPError.Condition.item_not_found);
|
||||
error.toXML();
|
||||
|
||||
assertEquals(error.getCondition(), "item-not-found");
|
||||
assertEquals(error.getCode(), 404);
|
||||
assertEquals(error.getType(), XMPPError.Type.CANCEL);
|
||||
assertNull(error.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the creation of a new xmppError locally.
|
||||
*/
|
||||
public void testLocalErrorWithCommentCreation() {
|
||||
String message = "Error Message";
|
||||
XMPPError error = new XMPPError(XMPPError.Condition.item_not_found, message);
|
||||
error.toXML();
|
||||
|
||||
assertEquals(error.getCondition(), "item-not-found");
|
||||
assertEquals(error.getCode(), 404);
|
||||
assertEquals(error.getType(), XMPPError.Type.CANCEL);
|
||||
assertEquals(error.getMessage(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the creation of a new xmppError locally where there is not a default defined.
|
||||
*/
|
||||
public void testUserDefinedErrorWithCommentCreation() {
|
||||
String message = "Error Message";
|
||||
XMPPError error = new XMPPError(new XMPPError.Condition("my_own_error"), message);
|
||||
error.toXML();
|
||||
|
||||
assertEquals(error.getCondition(), "my_own_error");
|
||||
assertEquals(error.getCode(), 0);
|
||||
assertNull(error.getType());
|
||||
assertEquals(error.getMessage(), message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with the 404 error.
|
||||
*/
|
||||
public void test404() {
|
||||
// Make the XML to test
|
||||
String xml = "<error code='404' type='cancel'>" +
|
||||
"<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"</error></iq>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError packet = parseError(parser);
|
||||
|
||||
assertNotNull(packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with the 404 error.
|
||||
*/
|
||||
public void testCancel() {
|
||||
// Make the XML to test
|
||||
String xml = "<error type='cancel'>" +
|
||||
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"</error>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError error = parseError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void testMessageAndApplicationDefinedError() {
|
||||
String xml = "<error type='modify' code='404'>" +
|
||||
"<undefined-condition xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>" +
|
||||
"Some special application diagnostic information..." +
|
||||
"</text>" +
|
||||
"<special-application-condition xmlns='application-ns'/>" +
|
||||
"</error>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError error = parseError(parser);
|
||||
|
||||
String sendingXML = error.toXML();
|
||||
|
||||
assertNotNull(error);
|
||||
assertNotNull(sendingXML);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check the parser with an xml with the 404 error.
|
||||
*/
|
||||
public void testCancelWithMessage() {
|
||||
// Make the XML to test
|
||||
String xml = "<error type='cancel'>" +
|
||||
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' xml:lang='langcode'>" +
|
||||
"Some special application diagnostic information!" +
|
||||
"</text>" +
|
||||
"</error>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError error = parseError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the parser with an xml with the 404 error.
|
||||
*/
|
||||
public void testCancelWithMessageAndApplicationError() {
|
||||
// Make the XML to test
|
||||
String xml = "<error type='cancel' code='10'>" +
|
||||
"<conflict xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" +
|
||||
"<text xml:lang='en' xmlns='urn:ietf:params:xml:ns:xmpp-streams'>" +
|
||||
"Some special application diagnostic information!" +
|
||||
"</text>" +
|
||||
"<application-defined-error xmlns='application-ns'/>" +
|
||||
"</error>";
|
||||
try {
|
||||
// Create the xml parser
|
||||
XmlPullParser parser = getParserFromXML(xml);
|
||||
// Create a packet from the xml
|
||||
XMPPError error = parseError(parser);
|
||||
|
||||
assertNotNull(error);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private XMPPError parseError(XmlPullParser parser) throws Exception {
|
||||
parser.next();
|
||||
return PacketParserUtils.parseError(parser);
|
||||
}
|
||||
|
||||
private XmlPullParser getParserFromXML(String xml) throws XmlPullParserException {
|
||||
MXParser parser = new MXParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(new StringReader(xml));
|
||||
return parser;
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,4 +113,4 @@ public class CompressionTest extends SmackTestCase {
|
|||
// Close the setupConnection
|
||||
setupConnection.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,4 +81,4 @@ public class GroupChatInvitationTest extends SmackTestCase {
|
|||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,157 +1,157 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2003-2006 Jive Software.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.packet.LastActivity;
|
||||
|
||||
public class LastActivityManagerTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* This is a test to check if a LastActivity request for idle time is
|
||||
* answered and correct.
|
||||
*/
|
||||
public void testOnline() {
|
||||
XMPPConnection conn0 = getConnection(0);
|
||||
XMPPConnection conn1 = getConnection(1);
|
||||
|
||||
// Send a message as the last activity action from connection 1 to
|
||||
// connection 0
|
||||
conn1.sendPacket(new Message(getBareJID(0)));
|
||||
|
||||
// Wait 1 seconds to have some idle time
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
fail("Thread sleep interrupted");
|
||||
}
|
||||
|
||||
LastActivity lastActivity = null;
|
||||
try {
|
||||
lastActivity = LastActivityManager.getLastActivity(conn0, getFullJID(1));
|
||||
} catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail("An error occurred requesting the Last Activity");
|
||||
}
|
||||
|
||||
// Asserts that the last activity packet was received
|
||||
assertNotNull("No last activity packet", lastActivity);
|
||||
// Asserts that there is at least a 1 second of idle time
|
||||
assertTrue(
|
||||
"The last activity idle time is less than expected: " + lastActivity.getIdleTime(),
|
||||
lastActivity.getIdleTime() >= 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a test to check if a denied LastActivity response is handled correctly.
|
||||
*/
|
||||
public void testOnlinePermisionDenied() {
|
||||
XMPPConnection conn0 = getConnection(0);
|
||||
XMPPConnection conn2 = getConnection(2);
|
||||
|
||||
// Send a message as the last activity action from connection 2 to
|
||||
// connection 0
|
||||
conn2.sendPacket(new Message(getBareJID(0)));
|
||||
|
||||
// Wait 1 seconds to have some idle time
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
fail("Thread sleep interrupted");
|
||||
}
|
||||
|
||||
try {
|
||||
LastActivityManager.getLastActivity(conn0, getFullJID(2));
|
||||
fail("No error was received from the server. User was able to get info of other user not in his roster.");
|
||||
} catch (XMPPException e) {
|
||||
assertNotNull("No error was returned from the server", e.getXMPPError());
|
||||
assertEquals("Forbidden error was not returned from the server", 403,
|
||||
e.getXMPPError().getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a test to check if a LastActivity request for last logged out
|
||||
* lapsed time is answered and correct
|
||||
*/
|
||||
public void testLastLoggedOut() {
|
||||
XMPPConnection conn0 = getConnection(0);
|
||||
|
||||
LastActivity lastActivity = null;
|
||||
try {
|
||||
lastActivity = LastActivityManager.getLastActivity(conn0, getBareJID(1));
|
||||
} catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail("An error occurred requesting the Last Activity");
|
||||
}
|
||||
|
||||
assertNotNull("No last activity packet", lastActivity);
|
||||
assertTrue("The last activity idle time should be 0 since the user is logged in: " +
|
||||
lastActivity.getIdleTime(), lastActivity.getIdleTime() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a test to check if a LastActivity request for server uptime
|
||||
* is answered and correct
|
||||
*/
|
||||
public void testServerUptime() {
|
||||
XMPPConnection conn0 = getConnection(0);
|
||||
|
||||
LastActivity lastActivity = null;
|
||||
try {
|
||||
lastActivity = LastActivityManager.getLastActivity(conn0, getHost());
|
||||
} catch (XMPPException e) {
|
||||
if (e.getXMPPError().getCode() == 403) {
|
||||
//The test can not be done since the host do not allow this kind of request
|
||||
return;
|
||||
}
|
||||
e.printStackTrace();
|
||||
fail("An error occurred requesting the Last Activity");
|
||||
}
|
||||
|
||||
assertNotNull("No last activity packet", lastActivity);
|
||||
assertTrue("The last activity idle time should be greater than 0 : " +
|
||||
lastActivity.getIdleTime(), lastActivity.getIdleTime() > 0);
|
||||
}
|
||||
|
||||
public LastActivityManagerTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
try {
|
||||
getConnection(0).getRoster().createEntry(getBareJID(1), "User1", null);
|
||||
Thread.sleep(300);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* Copyright 2003-2006 Jive Software.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.packet.LastActivity;
|
||||
|
||||
public class LastActivityManagerTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* This is a test to check if a LastActivity request for idle time is
|
||||
* answered and correct.
|
||||
*/
|
||||
public void testOnline() {
|
||||
XMPPConnection conn0 = getConnection(0);
|
||||
XMPPConnection conn1 = getConnection(1);
|
||||
|
||||
// Send a message as the last activity action from connection 1 to
|
||||
// connection 0
|
||||
conn1.sendPacket(new Message(getBareJID(0)));
|
||||
|
||||
// Wait 1 seconds to have some idle time
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
fail("Thread sleep interrupted");
|
||||
}
|
||||
|
||||
LastActivity lastActivity = null;
|
||||
try {
|
||||
lastActivity = LastActivityManager.getLastActivity(conn0, getFullJID(1));
|
||||
} catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail("An error occurred requesting the Last Activity");
|
||||
}
|
||||
|
||||
// Asserts that the last activity packet was received
|
||||
assertNotNull("No last activity packet", lastActivity);
|
||||
// Asserts that there is at least a 1 second of idle time
|
||||
assertTrue(
|
||||
"The last activity idle time is less than expected: " + lastActivity.getIdleTime(),
|
||||
lastActivity.getIdleTime() >= 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a test to check if a denied LastActivity response is handled correctly.
|
||||
*/
|
||||
public void testOnlinePermisionDenied() {
|
||||
XMPPConnection conn0 = getConnection(0);
|
||||
XMPPConnection conn2 = getConnection(2);
|
||||
|
||||
// Send a message as the last activity action from connection 2 to
|
||||
// connection 0
|
||||
conn2.sendPacket(new Message(getBareJID(0)));
|
||||
|
||||
// Wait 1 seconds to have some idle time
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
fail("Thread sleep interrupted");
|
||||
}
|
||||
|
||||
try {
|
||||
LastActivityManager.getLastActivity(conn0, getFullJID(2));
|
||||
fail("No error was received from the server. User was able to get info of other user not in his roster.");
|
||||
} catch (XMPPException e) {
|
||||
assertNotNull("No error was returned from the server", e.getXMPPError());
|
||||
assertEquals("Forbidden error was not returned from the server", 403,
|
||||
e.getXMPPError().getCode());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a test to check if a LastActivity request for last logged out
|
||||
* lapsed time is answered and correct
|
||||
*/
|
||||
public void testLastLoggedOut() {
|
||||
XMPPConnection conn0 = getConnection(0);
|
||||
|
||||
LastActivity lastActivity = null;
|
||||
try {
|
||||
lastActivity = LastActivityManager.getLastActivity(conn0, getBareJID(1));
|
||||
} catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
fail("An error occurred requesting the Last Activity");
|
||||
}
|
||||
|
||||
assertNotNull("No last activity packet", lastActivity);
|
||||
assertTrue("The last activity idle time should be 0 since the user is logged in: " +
|
||||
lastActivity.getIdleTime(), lastActivity.getIdleTime() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a test to check if a LastActivity request for server uptime
|
||||
* is answered and correct
|
||||
*/
|
||||
public void testServerUptime() {
|
||||
XMPPConnection conn0 = getConnection(0);
|
||||
|
||||
LastActivity lastActivity = null;
|
||||
try {
|
||||
lastActivity = LastActivityManager.getLastActivity(conn0, getHost());
|
||||
} catch (XMPPException e) {
|
||||
if (e.getXMPPError().getCode() == 403) {
|
||||
//The test can not be done since the host do not allow this kind of request
|
||||
return;
|
||||
}
|
||||
e.printStackTrace();
|
||||
fail("An error occurred requesting the Last Activity");
|
||||
}
|
||||
|
||||
assertNotNull("No last activity packet", lastActivity);
|
||||
assertTrue("The last activity idle time should be greater than 0 : " +
|
||||
lastActivity.getIdleTime(), lastActivity.getIdleTime() > 0);
|
||||
}
|
||||
|
||||
public LastActivityManagerTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
try {
|
||||
getConnection(0).getRoster().createEntry(getBareJID(1), "User1", null);
|
||||
Thread.sleep(300);
|
||||
} catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,34 +14,34 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Test cases for getting the shared groups of a user.<p>
|
||||
*
|
||||
* Important note: This functionality is not part of the XMPP spec and it will only work
|
||||
* with Wildfire.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class SharedGroupsTest extends SmackTestCase {
|
||||
|
||||
public SharedGroupsTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public void testGetUserSharedGroups() throws XMPPException {
|
||||
List<String> groups = SharedGroupManager.getSharedGroups(getConnection(0));
|
||||
|
||||
assertNotNull("User groups was null", groups);
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Test cases for getting the shared groups of a user.<p>
|
||||
*
|
||||
* Important note: This functionality is not part of the XMPP spec and it will only work
|
||||
* with Wildfire.
|
||||
*
|
||||
* @author Gaston Dombiak
|
||||
*/
|
||||
public class SharedGroupsTest extends SmackTestCase {
|
||||
|
||||
public SharedGroupsTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public void testGetUserSharedGroups() throws XMPPException {
|
||||
List<String> groups = SharedGroupManager.getSharedGroups(getConnection(0));
|
||||
|
||||
assertNotNull("User groups was null", groups);
|
||||
}
|
||||
|
||||
protected int getMaxConnections() {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,259 +1,259 @@
|
|||
/**
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.bytestreams.ibb;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamListener;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamRequest;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamSession;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
||||
|
||||
/**
|
||||
* Test for In-Band Bytestreams with real XMPP servers.
|
||||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
public class InBandBytestreamTest extends SmackTestCase {
|
||||
|
||||
/* the amount of data transmitted in each test */
|
||||
int dataSize = 1024000;
|
||||
|
||||
public InBandBytestreamTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Target should respond with not-acceptable error if no listeners for incoming In-Band
|
||||
* Bytestream requests are registered.
|
||||
*
|
||||
* @throws XMPPException should not happen
|
||||
*/
|
||||
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
|
||||
Connection targetConnection = getConnection(0);
|
||||
|
||||
Connection initiatorConnection = getConnection(1);
|
||||
|
||||
Open open = new Open("sessionID", 1024);
|
||||
open.setFrom(initiatorConnection.getUser());
|
||||
open.setTo(targetConnection.getUser());
|
||||
|
||||
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
|
||||
open.getPacketID()));
|
||||
initiatorConnection.sendPacket(open);
|
||||
Packet result = collector.nextResult();
|
||||
|
||||
assertNotNull(result.getError());
|
||||
assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An In-Band Bytestream should be successfully established using IQ stanzas.
|
||||
*
|
||||
* @throws Exception should not happen
|
||||
*/
|
||||
public void testInBandBytestreamWithIQStanzas() throws Exception {
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
Random rand = new Random();
|
||||
final byte[] data = new byte[dataSize];
|
||||
rand.nextBytes(data);
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
InBandBytestreamManager targetByteStreamManager = InBandBytestreamManager.getByteStreamManager(targetConnection);
|
||||
|
||||
InBandBytestreamListener incomingByteStreamListener = new InBandBytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(InBandBytestreamRequest request) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
inputStream = request.accept().getInputStream();
|
||||
byte[] receivedData = new byte[dataSize];
|
||||
int totalRead = 0;
|
||||
while (totalRead < dataSize) {
|
||||
int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
|
||||
totalRead += read;
|
||||
}
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
InBandBytestreamManager initiatorByteStreamManager = InBandBytestreamManager.getByteStreamManager(initiatorConnection);
|
||||
|
||||
OutputStream outputStream = initiatorByteStreamManager.establishSession(
|
||||
targetConnection.getUser()).getOutputStream();
|
||||
|
||||
// verify stream
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An In-Band Bytestream should be successfully established using message stanzas.
|
||||
*
|
||||
* @throws Exception should not happen
|
||||
*/
|
||||
public void testInBandBytestreamWithMessageStanzas() throws Exception {
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
Random rand = new Random();
|
||||
final byte[] data = new byte[dataSize];
|
||||
rand.nextBytes(data);
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
InBandBytestreamManager targetByteStreamManager = InBandBytestreamManager.getByteStreamManager(targetConnection);
|
||||
|
||||
InBandBytestreamListener incomingByteStreamListener = new InBandBytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(InBandBytestreamRequest request) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
inputStream = request.accept().getInputStream();
|
||||
byte[] receivedData = new byte[dataSize];
|
||||
int totalRead = 0;
|
||||
while (totalRead < dataSize) {
|
||||
int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
|
||||
totalRead += read;
|
||||
}
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
InBandBytestreamManager initiatorByteStreamManager = InBandBytestreamManager.getByteStreamManager(initiatorConnection);
|
||||
initiatorByteStreamManager.setStanza(StanzaType.MESSAGE);
|
||||
|
||||
OutputStream outputStream = initiatorByteStreamManager.establishSession(
|
||||
targetConnection.getUser()).getOutputStream();
|
||||
|
||||
// verify stream
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An In-Band Bytestream should be successfully established using IQ stanzas. The established
|
||||
* session should transfer data bidirectional.
|
||||
*
|
||||
* @throws Exception should not happen
|
||||
*/
|
||||
public void testBiDirectionalInBandBytestream() throws Exception {
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
Random rand = new Random();
|
||||
final byte[] data = new byte[dataSize];
|
||||
rand.nextBytes(data);
|
||||
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
InBandBytestreamManager targetByteStreamManager = InBandBytestreamManager.getByteStreamManager(targetConnection);
|
||||
|
||||
InBandBytestreamListener incomingByteStreamListener = new InBandBytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(InBandBytestreamRequest request) {
|
||||
try {
|
||||
InBandBytestreamSession session = request.accept();
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
InputStream inputStream = session.getInputStream();
|
||||
byte[] receivedData = new byte[dataSize];
|
||||
int totalRead = 0;
|
||||
while (totalRead < dataSize) {
|
||||
int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
|
||||
totalRead += read;
|
||||
}
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
InBandBytestreamManager initiatorByteStreamManager = InBandBytestreamManager.getByteStreamManager(initiatorConnection);
|
||||
|
||||
InBandBytestreamSession session = initiatorByteStreamManager.establishSession(targetConnection.getUser());
|
||||
|
||||
// verify stream
|
||||
byte[] receivedData = new byte[dataSize];
|
||||
InputStream inputStream = session.getInputStream();
|
||||
int totalRead = 0;
|
||||
while (totalRead < dataSize) {
|
||||
int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
|
||||
totalRead += read;
|
||||
}
|
||||
|
||||
assertEquals("sent data not equal to received data", data, receivedData);
|
||||
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.bytestreams.ibb;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamListener;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamRequest;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamSession;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager.StanzaType;
|
||||
import org.jivesoftware.smackx.bytestreams.ibb.packet.Open;
|
||||
|
||||
/**
|
||||
* Test for In-Band Bytestreams with real XMPP servers.
|
||||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
public class InBandBytestreamTest extends SmackTestCase {
|
||||
|
||||
/* the amount of data transmitted in each test */
|
||||
int dataSize = 1024000;
|
||||
|
||||
public InBandBytestreamTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Target should respond with not-acceptable error if no listeners for incoming In-Band
|
||||
* Bytestream requests are registered.
|
||||
*
|
||||
* @throws XMPPException should not happen
|
||||
*/
|
||||
public void testRespondWithErrorOnInBandBytestreamRequest() throws XMPPException {
|
||||
Connection targetConnection = getConnection(0);
|
||||
|
||||
Connection initiatorConnection = getConnection(1);
|
||||
|
||||
Open open = new Open("sessionID", 1024);
|
||||
open.setFrom(initiatorConnection.getUser());
|
||||
open.setTo(targetConnection.getUser());
|
||||
|
||||
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
|
||||
open.getPacketID()));
|
||||
initiatorConnection.sendPacket(open);
|
||||
Packet result = collector.nextResult();
|
||||
|
||||
assertNotNull(result.getError());
|
||||
assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An In-Band Bytestream should be successfully established using IQ stanzas.
|
||||
*
|
||||
* @throws Exception should not happen
|
||||
*/
|
||||
public void testInBandBytestreamWithIQStanzas() throws Exception {
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
Random rand = new Random();
|
||||
final byte[] data = new byte[dataSize];
|
||||
rand.nextBytes(data);
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
InBandBytestreamManager targetByteStreamManager = InBandBytestreamManager.getByteStreamManager(targetConnection);
|
||||
|
||||
InBandBytestreamListener incomingByteStreamListener = new InBandBytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(InBandBytestreamRequest request) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
inputStream = request.accept().getInputStream();
|
||||
byte[] receivedData = new byte[dataSize];
|
||||
int totalRead = 0;
|
||||
while (totalRead < dataSize) {
|
||||
int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
|
||||
totalRead += read;
|
||||
}
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
InBandBytestreamManager initiatorByteStreamManager = InBandBytestreamManager.getByteStreamManager(initiatorConnection);
|
||||
|
||||
OutputStream outputStream = initiatorByteStreamManager.establishSession(
|
||||
targetConnection.getUser()).getOutputStream();
|
||||
|
||||
// verify stream
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An In-Band Bytestream should be successfully established using message stanzas.
|
||||
*
|
||||
* @throws Exception should not happen
|
||||
*/
|
||||
public void testInBandBytestreamWithMessageStanzas() throws Exception {
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
Random rand = new Random();
|
||||
final byte[] data = new byte[dataSize];
|
||||
rand.nextBytes(data);
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
InBandBytestreamManager targetByteStreamManager = InBandBytestreamManager.getByteStreamManager(targetConnection);
|
||||
|
||||
InBandBytestreamListener incomingByteStreamListener = new InBandBytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(InBandBytestreamRequest request) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
inputStream = request.accept().getInputStream();
|
||||
byte[] receivedData = new byte[dataSize];
|
||||
int totalRead = 0;
|
||||
while (totalRead < dataSize) {
|
||||
int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
|
||||
totalRead += read;
|
||||
}
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
InBandBytestreamManager initiatorByteStreamManager = InBandBytestreamManager.getByteStreamManager(initiatorConnection);
|
||||
initiatorByteStreamManager.setStanza(StanzaType.MESSAGE);
|
||||
|
||||
OutputStream outputStream = initiatorByteStreamManager.establishSession(
|
||||
targetConnection.getUser()).getOutputStream();
|
||||
|
||||
// verify stream
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An In-Band Bytestream should be successfully established using IQ stanzas. The established
|
||||
* session should transfer data bidirectional.
|
||||
*
|
||||
* @throws Exception should not happen
|
||||
*/
|
||||
public void testBiDirectionalInBandBytestream() throws Exception {
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
Random rand = new Random();
|
||||
final byte[] data = new byte[dataSize];
|
||||
rand.nextBytes(data);
|
||||
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
InBandBytestreamManager targetByteStreamManager = InBandBytestreamManager.getByteStreamManager(targetConnection);
|
||||
|
||||
InBandBytestreamListener incomingByteStreamListener = new InBandBytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(InBandBytestreamRequest request) {
|
||||
try {
|
||||
InBandBytestreamSession session = request.accept();
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
InputStream inputStream = session.getInputStream();
|
||||
byte[] receivedData = new byte[dataSize];
|
||||
int totalRead = 0;
|
||||
while (totalRead < dataSize) {
|
||||
int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
|
||||
totalRead += read;
|
||||
}
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
InBandBytestreamManager initiatorByteStreamManager = InBandBytestreamManager.getByteStreamManager(initiatorConnection);
|
||||
|
||||
InBandBytestreamSession session = initiatorByteStreamManager.establishSession(targetConnection.getUser());
|
||||
|
||||
// verify stream
|
||||
byte[] receivedData = new byte[dataSize];
|
||||
InputStream inputStream = session.getInputStream();
|
||||
int totalRead = 0;
|
||||
while (totalRead < dataSize) {
|
||||
int read = inputStream.read(receivedData, totalRead, dataSize - totalRead);
|
||||
totalRead += read;
|
||||
}
|
||||
|
||||
assertEquals("sent data not equal to received data", data, receivedData);
|
||||
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,337 +1,337 @@
|
|||
/**
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.bytestreams.socks5;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamListener;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamRequest;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5PacketUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
|
||||
/**
|
||||
* Test for Socks5 bytestreams with real XMPP servers.
|
||||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
public class Socks5ByteStreamTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param arg0
|
||||
*/
|
||||
public Socks5ByteStreamTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Socks5 feature should be added to the service discovery on Smack startup.
|
||||
*
|
||||
* @throws XMPPException should not happen
|
||||
*/
|
||||
public void testInitializationSocks5FeaturesAndListenerOnStartup() throws XMPPException {
|
||||
Connection connection = getConnection(0);
|
||||
|
||||
assertTrue(ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(
|
||||
Socks5BytestreamManager.NAMESPACE));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Target should respond with not-acceptable error if no listeners for incoming Socks5
|
||||
* bytestream requests are registered.
|
||||
*
|
||||
* @throws XMPPException should not happen
|
||||
*/
|
||||
public void testRespondWithErrorOnSocks5BytestreamRequest() throws XMPPException {
|
||||
Connection targetConnection = getConnection(0);
|
||||
|
||||
Connection initiatorConnection = getConnection(1);
|
||||
|
||||
Bytestream bytestreamInitiation = Socks5PacketUtils.createBytestreamInitiation(
|
||||
initiatorConnection.getUser(), targetConnection.getUser(), "session_id");
|
||||
bytestreamInitiation.addStreamHost("proxy.localhost", "127.0.0.1", 7777);
|
||||
|
||||
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
|
||||
bytestreamInitiation.getPacketID()));
|
||||
initiatorConnection.sendPacket(bytestreamInitiation);
|
||||
Packet result = collector.nextResult();
|
||||
|
||||
assertNotNull(result.getError());
|
||||
assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Socks5 bytestream should be successfully established using the local Socks5 proxy.
|
||||
*
|
||||
* @throws Exception should not happen
|
||||
*/
|
||||
public void testSocks5BytestreamWithLocalSocks5Proxy() throws Exception {
|
||||
|
||||
// setup port for local socks5 proxy
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
|
||||
SmackConfiguration.setLocalSocks5ProxyPort(7778);
|
||||
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
|
||||
socks5Proxy.start();
|
||||
|
||||
assertTrue(socks5Proxy.isRunning());
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
final byte[] data = new byte[] { 1, 2, 3 };
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
Socks5BytestreamManager targetByteStreamManager = Socks5BytestreamManager.getBytestreamManager(targetConnection);
|
||||
|
||||
Socks5BytestreamListener incomingByteStreamListener = new Socks5BytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(Socks5BytestreamRequest request) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
Socks5BytestreamSession session = request.accept();
|
||||
inputStream = session.getInputStream();
|
||||
byte[] receivedData = new byte[3];
|
||||
inputStream.read(receivedData);
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
Socks5BytestreamManager initiatorByteStreamManager = Socks5BytestreamManager.getBytestreamManager(initiatorConnection);
|
||||
|
||||
Socks5BytestreamSession session = initiatorByteStreamManager.establishSession(
|
||||
targetConnection.getUser());
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
|
||||
assertTrue(session.isDirect());
|
||||
|
||||
// verify stream
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
// reset default configuration
|
||||
SmackConfiguration.setLocalSocks5ProxyPort(7777);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Socks5 bytestream should be successfully established using a Socks5 proxy provided by the
|
||||
* XMPP server.
|
||||
* <p>
|
||||
* This test will fail if the XMPP server doesn't provide any Socks5 proxies or the Socks5 proxy
|
||||
* only allows Socks5 bytestreams in the context of a file transfer (like Openfire in default
|
||||
* configuration, see xmpp.proxy.transfer.required flag).
|
||||
*
|
||||
* @throws Exception if no Socks5 proxies found or proxy is unwilling to activate Socks5
|
||||
* bytestream
|
||||
*/
|
||||
public void testSocks5BytestreamWithRemoteSocks5Proxy() throws Exception {
|
||||
|
||||
// disable local socks5 proxy
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
|
||||
Socks5Proxy.getSocks5Proxy().stop();
|
||||
|
||||
assertFalse(Socks5Proxy.getSocks5Proxy().isRunning());
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
final byte[] data = new byte[] { 1, 2, 3 };
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
Socks5BytestreamManager targetByteStreamManager = Socks5BytestreamManager.getBytestreamManager(targetConnection);
|
||||
|
||||
Socks5BytestreamListener incomingByteStreamListener = new Socks5BytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(Socks5BytestreamRequest request) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
Socks5BytestreamSession session = request.accept();
|
||||
inputStream = session.getInputStream();
|
||||
byte[] receivedData = new byte[3];
|
||||
inputStream.read(receivedData);
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
Socks5BytestreamManager initiatorByteStreamManager = Socks5BytestreamManager.getBytestreamManager(initiatorConnection);
|
||||
|
||||
Socks5BytestreamSession session = initiatorByteStreamManager.establishSession(
|
||||
targetConnection.getUser());
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
|
||||
assertTrue(session.isMediated());
|
||||
|
||||
// verify stream
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
// reset default configuration
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
|
||||
Socks5Proxy.getSocks5Proxy().start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Socks5 bytestream should be successfully established using a Socks5 proxy provided by the
|
||||
* XMPP server. The established connection should transfer data bidirectional if the Socks5
|
||||
* proxy supports it.
|
||||
* <p>
|
||||
* Support for bidirectional Socks5 bytestream:
|
||||
* <ul>
|
||||
* <li>Openfire (3.6.4 and below) - no</li>
|
||||
* <li>ejabberd (2.0.5 and higher) - yes</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* This test will fail if the XMPP server doesn't provide any Socks5 proxies or the Socks5 proxy
|
||||
* only allows Socks5 bytestreams in the context of a file transfer (like Openfire in default
|
||||
* configuration, see xmpp.proxy.transfer.required flag).
|
||||
*
|
||||
* @throws Exception if no Socks5 proxies found or proxy is unwilling to activate Socks5
|
||||
* bytestream
|
||||
*/
|
||||
public void testBiDirectionalSocks5BytestreamWithRemoteSocks5Proxy() throws Exception {
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
|
||||
// disable local socks5 proxy
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
|
||||
Socks5Proxy.getSocks5Proxy().stop();
|
||||
|
||||
assertFalse(Socks5Proxy.getSocks5Proxy().isRunning());
|
||||
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
final byte[] data = new byte[] { 1, 2, 3 };
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
Socks5BytestreamManager targetByteStreamManager = Socks5BytestreamManager.getBytestreamManager(targetConnection);
|
||||
|
||||
Socks5BytestreamListener incomingByteStreamListener = new Socks5BytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(Socks5BytestreamRequest request) {
|
||||
try {
|
||||
Socks5BytestreamSession session = request.accept();
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
InputStream inputStream = session.getInputStream();
|
||||
byte[] receivedData = new byte[3];
|
||||
inputStream.read(receivedData);
|
||||
queue.put(receivedData);
|
||||
session.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
Socks5BytestreamManager initiatorByteStreamManager = Socks5BytestreamManager.getBytestreamManager(initiatorConnection);
|
||||
|
||||
Socks5BytestreamSession session = initiatorByteStreamManager.establishSession(targetConnection.getUser());
|
||||
|
||||
assertTrue(session.isMediated());
|
||||
|
||||
// verify stream
|
||||
final byte[] receivedData = new byte[3];
|
||||
final InputStream inputStream = session.getInputStream();
|
||||
|
||||
FutureTask<Integer> futureTask = new FutureTask<Integer>(new Callable<Integer>() {
|
||||
|
||||
public Integer call() throws Exception {
|
||||
return inputStream.read(receivedData);
|
||||
}
|
||||
});
|
||||
Thread executor = new Thread(futureTask);
|
||||
executor.start();
|
||||
|
||||
try {
|
||||
futureTask.get(2000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
catch (TimeoutException e) {
|
||||
// reset default configuration
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
|
||||
Socks5Proxy.getSocks5Proxy().start();
|
||||
|
||||
fail("Couldn't send data from target to inititator");
|
||||
}
|
||||
|
||||
assertEquals("sent data not equal to received data", data, receivedData);
|
||||
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
session.close();
|
||||
|
||||
// reset default configuration
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
|
||||
Socks5Proxy.getSocks5Proxy().start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.bytestreams.socks5;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jivesoftware.smack.Connection;
|
||||
import org.jivesoftware.smack.PacketCollector;
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.filter.PacketIDFilter;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamListener;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamRequest;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamSession;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5PacketUtils;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
|
||||
/**
|
||||
* Test for Socks5 bytestreams with real XMPP servers.
|
||||
*
|
||||
* @author Henning Staib
|
||||
*/
|
||||
public class Socks5ByteStreamTest extends SmackTestCase {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param arg0
|
||||
*/
|
||||
public Socks5ByteStreamTest(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Socks5 feature should be added to the service discovery on Smack startup.
|
||||
*
|
||||
* @throws XMPPException should not happen
|
||||
*/
|
||||
public void testInitializationSocks5FeaturesAndListenerOnStartup() throws XMPPException {
|
||||
Connection connection = getConnection(0);
|
||||
|
||||
assertTrue(ServiceDiscoveryManager.getInstanceFor(connection).includesFeature(
|
||||
Socks5BytestreamManager.NAMESPACE));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Target should respond with not-acceptable error if no listeners for incoming Socks5
|
||||
* bytestream requests are registered.
|
||||
*
|
||||
* @throws XMPPException should not happen
|
||||
*/
|
||||
public void testRespondWithErrorOnSocks5BytestreamRequest() throws XMPPException {
|
||||
Connection targetConnection = getConnection(0);
|
||||
|
||||
Connection initiatorConnection = getConnection(1);
|
||||
|
||||
Bytestream bytestreamInitiation = Socks5PacketUtils.createBytestreamInitiation(
|
||||
initiatorConnection.getUser(), targetConnection.getUser(), "session_id");
|
||||
bytestreamInitiation.addStreamHost("proxy.localhost", "127.0.0.1", 7777);
|
||||
|
||||
PacketCollector collector = initiatorConnection.createPacketCollector(new PacketIDFilter(
|
||||
bytestreamInitiation.getPacketID()));
|
||||
initiatorConnection.sendPacket(bytestreamInitiation);
|
||||
Packet result = collector.nextResult();
|
||||
|
||||
assertNotNull(result.getError());
|
||||
assertEquals(XMPPError.Condition.no_acceptable.toString(), result.getError().getCondition());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Socks5 bytestream should be successfully established using the local Socks5 proxy.
|
||||
*
|
||||
* @throws Exception should not happen
|
||||
*/
|
||||
public void testSocks5BytestreamWithLocalSocks5Proxy() throws Exception {
|
||||
|
||||
// setup port for local socks5 proxy
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
|
||||
SmackConfiguration.setLocalSocks5ProxyPort(7778);
|
||||
Socks5Proxy socks5Proxy = Socks5Proxy.getSocks5Proxy();
|
||||
socks5Proxy.start();
|
||||
|
||||
assertTrue(socks5Proxy.isRunning());
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
final byte[] data = new byte[] { 1, 2, 3 };
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
Socks5BytestreamManager targetByteStreamManager = Socks5BytestreamManager.getBytestreamManager(targetConnection);
|
||||
|
||||
Socks5BytestreamListener incomingByteStreamListener = new Socks5BytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(Socks5BytestreamRequest request) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
Socks5BytestreamSession session = request.accept();
|
||||
inputStream = session.getInputStream();
|
||||
byte[] receivedData = new byte[3];
|
||||
inputStream.read(receivedData);
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
Socks5BytestreamManager initiatorByteStreamManager = Socks5BytestreamManager.getBytestreamManager(initiatorConnection);
|
||||
|
||||
Socks5BytestreamSession session = initiatorByteStreamManager.establishSession(
|
||||
targetConnection.getUser());
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
|
||||
assertTrue(session.isDirect());
|
||||
|
||||
// verify stream
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
// reset default configuration
|
||||
SmackConfiguration.setLocalSocks5ProxyPort(7777);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Socks5 bytestream should be successfully established using a Socks5 proxy provided by the
|
||||
* XMPP server.
|
||||
* <p>
|
||||
* This test will fail if the XMPP server doesn't provide any Socks5 proxies or the Socks5 proxy
|
||||
* only allows Socks5 bytestreams in the context of a file transfer (like Openfire in default
|
||||
* configuration, see xmpp.proxy.transfer.required flag).
|
||||
*
|
||||
* @throws Exception if no Socks5 proxies found or proxy is unwilling to activate Socks5
|
||||
* bytestream
|
||||
*/
|
||||
public void testSocks5BytestreamWithRemoteSocks5Proxy() throws Exception {
|
||||
|
||||
// disable local socks5 proxy
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
|
||||
Socks5Proxy.getSocks5Proxy().stop();
|
||||
|
||||
assertFalse(Socks5Proxy.getSocks5Proxy().isRunning());
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
final byte[] data = new byte[] { 1, 2, 3 };
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
Socks5BytestreamManager targetByteStreamManager = Socks5BytestreamManager.getBytestreamManager(targetConnection);
|
||||
|
||||
Socks5BytestreamListener incomingByteStreamListener = new Socks5BytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(Socks5BytestreamRequest request) {
|
||||
InputStream inputStream;
|
||||
try {
|
||||
Socks5BytestreamSession session = request.accept();
|
||||
inputStream = session.getInputStream();
|
||||
byte[] receivedData = new byte[3];
|
||||
inputStream.read(receivedData);
|
||||
queue.put(receivedData);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
Socks5BytestreamManager initiatorByteStreamManager = Socks5BytestreamManager.getBytestreamManager(initiatorConnection);
|
||||
|
||||
Socks5BytestreamSession session = initiatorByteStreamManager.establishSession(
|
||||
targetConnection.getUser());
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
|
||||
assertTrue(session.isMediated());
|
||||
|
||||
// verify stream
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
// reset default configuration
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
|
||||
Socks5Proxy.getSocks5Proxy().start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Socks5 bytestream should be successfully established using a Socks5 proxy provided by the
|
||||
* XMPP server. The established connection should transfer data bidirectional if the Socks5
|
||||
* proxy supports it.
|
||||
* <p>
|
||||
* Support for bidirectional Socks5 bytestream:
|
||||
* <ul>
|
||||
* <li>Openfire (3.6.4 and below) - no</li>
|
||||
* <li>ejabberd (2.0.5 and higher) - yes</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* This test will fail if the XMPP server doesn't provide any Socks5 proxies or the Socks5 proxy
|
||||
* only allows Socks5 bytestreams in the context of a file transfer (like Openfire in default
|
||||
* configuration, see xmpp.proxy.transfer.required flag).
|
||||
*
|
||||
* @throws Exception if no Socks5 proxies found or proxy is unwilling to activate Socks5
|
||||
* bytestream
|
||||
*/
|
||||
public void testBiDirectionalSocks5BytestreamWithRemoteSocks5Proxy() throws Exception {
|
||||
|
||||
Connection initiatorConnection = getConnection(0);
|
||||
|
||||
// disable local socks5 proxy
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(false);
|
||||
Socks5Proxy.getSocks5Proxy().stop();
|
||||
|
||||
assertFalse(Socks5Proxy.getSocks5Proxy().isRunning());
|
||||
|
||||
Connection targetConnection = getConnection(1);
|
||||
|
||||
// test data
|
||||
final byte[] data = new byte[] { 1, 2, 3 };
|
||||
final SynchronousQueue<byte[]> queue = new SynchronousQueue<byte[]>();
|
||||
|
||||
Socks5BytestreamManager targetByteStreamManager = Socks5BytestreamManager.getBytestreamManager(targetConnection);
|
||||
|
||||
Socks5BytestreamListener incomingByteStreamListener = new Socks5BytestreamListener() {
|
||||
|
||||
public void incomingBytestreamRequest(Socks5BytestreamRequest request) {
|
||||
try {
|
||||
Socks5BytestreamSession session = request.accept();
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
InputStream inputStream = session.getInputStream();
|
||||
byte[] receivedData = new byte[3];
|
||||
inputStream.read(receivedData);
|
||||
queue.put(receivedData);
|
||||
session.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
targetByteStreamManager.addIncomingBytestreamListener(incomingByteStreamListener);
|
||||
|
||||
Socks5BytestreamManager initiatorByteStreamManager = Socks5BytestreamManager.getBytestreamManager(initiatorConnection);
|
||||
|
||||
Socks5BytestreamSession session = initiatorByteStreamManager.establishSession(targetConnection.getUser());
|
||||
|
||||
assertTrue(session.isMediated());
|
||||
|
||||
// verify stream
|
||||
final byte[] receivedData = new byte[3];
|
||||
final InputStream inputStream = session.getInputStream();
|
||||
|
||||
FutureTask<Integer> futureTask = new FutureTask<Integer>(new Callable<Integer>() {
|
||||
|
||||
public Integer call() throws Exception {
|
||||
return inputStream.read(receivedData);
|
||||
}
|
||||
});
|
||||
Thread executor = new Thread(futureTask);
|
||||
executor.start();
|
||||
|
||||
try {
|
||||
futureTask.get(2000, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
catch (TimeoutException e) {
|
||||
// reset default configuration
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
|
||||
Socks5Proxy.getSocks5Proxy().start();
|
||||
|
||||
fail("Couldn't send data from target to inititator");
|
||||
}
|
||||
|
||||
assertEquals("sent data not equal to received data", data, receivedData);
|
||||
|
||||
OutputStream outputStream = session.getOutputStream();
|
||||
|
||||
outputStream.write(data);
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
|
||||
assertEquals("received data not equal to sent data", data, queue.take());
|
||||
|
||||
session.close();
|
||||
|
||||
// reset default configuration
|
||||
SmackConfiguration.setLocalSocks5ProxyEnabled(true);
|
||||
Socks5Proxy.getSocks5Proxy().start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -108,4 +108,4 @@ public class AdHocCommandDiscoTest extends SmackTestCase {
|
|||
protected int getMaxConnections() {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,50 +14,50 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
class CarExtension implements PacketExtension
|
||||
{
|
||||
private String color;
|
||||
private int numTires;
|
||||
|
||||
public CarExtension(String col, int num)
|
||||
{
|
||||
color = col;
|
||||
numTires = num;
|
||||
}
|
||||
|
||||
public String getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getNumTires()
|
||||
{
|
||||
return numTires;
|
||||
}
|
||||
|
||||
public String getElementName()
|
||||
{
|
||||
return "car";
|
||||
}
|
||||
|
||||
public String getNamespace()
|
||||
{
|
||||
return "pubsub:test:vehicle";
|
||||
}
|
||||
|
||||
public String toXML()
|
||||
{
|
||||
return "<" + getElementName() + " xmlns='" + getNamespace() + "'><paint color='" +
|
||||
getColor() + "'/><tires num='" + getNumTires() + "'/></" + getElementName() + ">";
|
||||
}
|
||||
|
||||
}
|
||||
class CarExtension implements PacketExtension
|
||||
{
|
||||
private String color;
|
||||
private int numTires;
|
||||
|
||||
public CarExtension(String col, int num)
|
||||
{
|
||||
color = col;
|
||||
numTires = num;
|
||||
}
|
||||
|
||||
public String getColor()
|
||||
{
|
||||
return color;
|
||||
}
|
||||
|
||||
public int getNumTires()
|
||||
{
|
||||
return numTires;
|
||||
}
|
||||
|
||||
public String getElementName()
|
||||
{
|
||||
return "car";
|
||||
}
|
||||
|
||||
public String getNamespace()
|
||||
{
|
||||
return "pubsub:test:vehicle";
|
||||
}
|
||||
|
||||
public String toXML()
|
||||
{
|
||||
return "<" + getElementName() + " xmlns='" + getNamespace() + "'><paint color='" +
|
||||
getColor() + "'/><tires num='" + getNumTires() + "'/></" + getElementName() + ">";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,40 +14,40 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.packet.PacketExtension;
|
||||
import org.jivesoftware.smack.provider.PacketExtensionProvider;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class CarExtensionProvider implements PacketExtensionProvider
|
||||
{
|
||||
|
||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
|
||||
{
|
||||
String color = null;
|
||||
int numTires = 0;
|
||||
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
while (parser.next() != XmlPullParser.START_TAG);
|
||||
|
||||
if (parser.getName().equals("paint"))
|
||||
{
|
||||
color = parser.getAttributeValue(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
numTires = Integer.parseInt(parser.getAttributeValue(0));
|
||||
}
|
||||
}
|
||||
while (parser.next() != XmlPullParser.END_TAG);
|
||||
return new CarExtension(color, numTires);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public class CarExtensionProvider implements PacketExtensionProvider
|
||||
{
|
||||
|
||||
public PacketExtension parseExtension(XmlPullParser parser) throws Exception
|
||||
{
|
||||
String color = null;
|
||||
int numTires = 0;
|
||||
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
while (parser.next() != XmlPullParser.START_TAG);
|
||||
|
||||
if (parser.getName().equals("paint"))
|
||||
{
|
||||
color = parser.getAttributeValue(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
numTires = Integer.parseInt(parser.getAttributeValue(0));
|
||||
}
|
||||
}
|
||||
while (parser.next() != XmlPullParser.END_TAG);
|
||||
return new CarExtension(color, numTires);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,76 +14,76 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.packet.DiscoverItems;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo;
|
||||
import org.jivesoftware.smackx.packet.DiscoverItems;
|
||||
import org.jivesoftware.smackx.packet.DiscoverInfo.Identity;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class EntityUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testDiscoverPubsubInfo() throws Exception
|
||||
{
|
||||
DiscoverInfo supportedFeatures = getManager().getSupportedFeatures();
|
||||
assertNotNull(supportedFeatures);
|
||||
}
|
||||
|
||||
public void testDiscoverNodeInfo() throws Exception
|
||||
{
|
||||
LeafNode myNode = getManager().createNode("DiscoNode" + System.currentTimeMillis());
|
||||
DiscoverInfo info = myNode.discoverInfo();
|
||||
assertTrue(info.getIdentities().hasNext());
|
||||
Identity ident = info.getIdentities().next();
|
||||
|
||||
assertEquals("leaf", ident.getType());
|
||||
}
|
||||
|
||||
public void testDiscoverNodeItems() throws Exception
|
||||
{
|
||||
LeafNode myNode = getRandomPubnode(getManager(), true, false);
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
DiscoverItems items = myNode.discoverItems();
|
||||
|
||||
int count = 0;
|
||||
|
||||
for(Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext(); it.next(),count++);
|
||||
|
||||
assertEquals(4, count);
|
||||
}
|
||||
|
||||
public void testDiscoverSubscriptions() throws Exception
|
||||
{
|
||||
getManager().getSubscriptions();
|
||||
}
|
||||
|
||||
public void testDiscoverNodeSubscriptions() throws Exception
|
||||
{
|
||||
LeafNode myNode = getRandomPubnode(getManager(), true, true);
|
||||
myNode.subscribe(getConnection(0).getUser());
|
||||
List<Subscription> subscriptions = myNode.getSubscriptions();
|
||||
|
||||
assertTrue(subscriptions.size() < 3);
|
||||
|
||||
for (Subscription subscription : subscriptions)
|
||||
{
|
||||
assertNull(subscription.getNode());
|
||||
}
|
||||
}
|
||||
|
||||
public void testRetrieveAffiliation() throws Exception
|
||||
{
|
||||
getManager().getAffiliations();
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class EntityUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testDiscoverPubsubInfo() throws Exception
|
||||
{
|
||||
DiscoverInfo supportedFeatures = getManager().getSupportedFeatures();
|
||||
assertNotNull(supportedFeatures);
|
||||
}
|
||||
|
||||
public void testDiscoverNodeInfo() throws Exception
|
||||
{
|
||||
LeafNode myNode = getManager().createNode("DiscoNode" + System.currentTimeMillis());
|
||||
DiscoverInfo info = myNode.discoverInfo();
|
||||
assertTrue(info.getIdentities().hasNext());
|
||||
Identity ident = info.getIdentities().next();
|
||||
|
||||
assertEquals("leaf", ident.getType());
|
||||
}
|
||||
|
||||
public void testDiscoverNodeItems() throws Exception
|
||||
{
|
||||
LeafNode myNode = getRandomPubnode(getManager(), true, false);
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
myNode.send(new Item());
|
||||
DiscoverItems items = myNode.discoverItems();
|
||||
|
||||
int count = 0;
|
||||
|
||||
for(Iterator<DiscoverItems.Item> it = items.getItems(); it.hasNext(); it.next(),count++);
|
||||
|
||||
assertEquals(4, count);
|
||||
}
|
||||
|
||||
public void testDiscoverSubscriptions() throws Exception
|
||||
{
|
||||
getManager().getSubscriptions();
|
||||
}
|
||||
|
||||
public void testDiscoverNodeSubscriptions() throws Exception
|
||||
{
|
||||
LeafNode myNode = getRandomPubnode(getManager(), true, true);
|
||||
myNode.subscribe(getConnection(0).getUser());
|
||||
List<Subscription> subscriptions = myNode.getSubscriptions();
|
||||
|
||||
assertTrue(subscriptions.size() < 3);
|
||||
|
||||
for (Subscription subscription : subscriptions)
|
||||
{
|
||||
assertNull(subscription.getNode());
|
||||
}
|
||||
}
|
||||
|
||||
public void testRetrieveAffiliation() throws Exception
|
||||
{
|
||||
getManager().getAffiliations();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,69 +14,69 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smackx.pubsub.test.PubSubTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smackx.pubsub.test.PubSubTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class MultiUserSubscriptionUseCases extends PubSubTestCase
|
||||
{
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public void testGetItemsWithSingleSubscription() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(0), true, false);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
|
||||
user2Node.subscribe(getBareJID(1));
|
||||
|
||||
Collection<? extends Item> items = user2Node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
}
|
||||
|
||||
public void testGetItemsWithMultiSubscription() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(0), true, false);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
|
||||
Subscription sub1 = user2Node.subscribe(getBareJID(1));
|
||||
|
||||
Subscription sub2 = user2Node.subscribe(getBareJID(1));
|
||||
|
||||
try
|
||||
{
|
||||
user2Node.getItems();
|
||||
}
|
||||
catch (XMPPException exc)
|
||||
{
|
||||
assertEquals("bad-request", exc.getXMPPError().getCondition());
|
||||
assertEquals(XMPPError.Type.MODIFY, exc.getXMPPError().getType());
|
||||
}
|
||||
List<Item> items = user2Node.getItems(sub1.getId());
|
||||
assertTrue(items.size() == 5);
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class MultiUserSubscriptionUseCases extends PubSubTestCase
|
||||
{
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections()
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
|
||||
public void testGetItemsWithSingleSubscription() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(0), true, false);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
|
||||
user2Node.subscribe(getBareJID(1));
|
||||
|
||||
Collection<? extends Item> items = user2Node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
}
|
||||
|
||||
public void testGetItemsWithMultiSubscription() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(0), true, false);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
LeafNode user2Node = (LeafNode) getManager(1).getNode(node.getId());
|
||||
Subscription sub1 = user2Node.subscribe(getBareJID(1));
|
||||
|
||||
Subscription sub2 = user2Node.subscribe(getBareJID(1));
|
||||
|
||||
try
|
||||
{
|
||||
user2Node.getItems();
|
||||
}
|
||||
catch (XMPPException exc)
|
||||
{
|
||||
assertEquals("bad-request", exc.getXMPPError().getCondition());
|
||||
assertEquals(XMPPError.Type.MODIFY, exc.getXMPPError().getType());
|
||||
}
|
||||
List<Item> items = user2Node.getItems(sub1.getId());
|
||||
assertTrue(items.size() == 5);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,135 +14,135 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class OwnerUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testCreateInstantNode() throws Exception
|
||||
{
|
||||
LeafNode node = getManager().createNode();
|
||||
assertNotNull(node);
|
||||
assertNotNull(node.getId());
|
||||
}
|
||||
|
||||
public void testCreateNamedNode() throws Exception
|
||||
{
|
||||
String id = "TestNamedNode" + System.currentTimeMillis();
|
||||
LeafNode node = getManager().createNode(id);
|
||||
assertEquals(id, node.getId());
|
||||
}
|
||||
|
||||
public void testCreateConfiguredNode() throws Exception
|
||||
{
|
||||
// Generate reasonably unique for multiple tests
|
||||
String id = "TestConfigNode" + System.currentTimeMillis();
|
||||
|
||||
// Create and configure a node
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
form.setDeliverPayloads(false);
|
||||
form.setNotifyRetract(true);
|
||||
form.setPersistentItems(true);
|
||||
form.setPublishModel(PublishModel.open);
|
||||
|
||||
LeafNode node = (LeafNode)getManager().createNode(id, form);
|
||||
|
||||
ConfigureForm currentForm = node.getNodeConfiguration();
|
||||
assertEquals(AccessModel.open, currentForm.getAccessModel());
|
||||
assertFalse(currentForm.isDeliverPayloads());
|
||||
assertTrue(currentForm.isNotifyRetract());
|
||||
assertTrue(currentForm.isPersistItems());
|
||||
assertEquals(PublishModel.open, currentForm.getPublishModel());
|
||||
}
|
||||
|
||||
public void testCreateAndUpdateConfiguredNode() throws Exception
|
||||
{
|
||||
// Generate reasonably unique for multiple tests
|
||||
String id = "TestConfigNode2" + System.currentTimeMillis();
|
||||
|
||||
// Create and configure a node
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
form.setDeliverPayloads(false);
|
||||
form.setNotifyRetract(true);
|
||||
form.setPersistentItems(true);
|
||||
form.setPublishModel(PublishModel.open);
|
||||
|
||||
LeafNode myNode = (LeafNode)getManager().createNode(id, form);
|
||||
ConfigureForm config = myNode.getNodeConfiguration();
|
||||
|
||||
assertEquals(AccessModel.open, config.getAccessModel());
|
||||
assertFalse(config.isDeliverPayloads());
|
||||
assertTrue(config.isNotifyRetract());
|
||||
assertTrue(config.isPersistItems());
|
||||
assertEquals(PublishModel.open, config.getPublishModel());
|
||||
|
||||
ConfigureForm submitForm = new ConfigureForm(config.createAnswerForm());
|
||||
submitForm.setAccessModel(AccessModel.whitelist);
|
||||
submitForm.setDeliverPayloads(true);
|
||||
submitForm.setNotifyRetract(false);
|
||||
submitForm.setPersistentItems(false);
|
||||
submitForm.setPublishModel(PublishModel.publishers);
|
||||
myNode.sendConfigurationForm(submitForm);
|
||||
|
||||
ConfigureForm newConfig = myNode.getNodeConfiguration();
|
||||
assertEquals(AccessModel.whitelist, newConfig.getAccessModel());
|
||||
assertTrue(newConfig.isDeliverPayloads());
|
||||
assertFalse(newConfig.isNotifyRetract());
|
||||
assertFalse(newConfig.isPersistItems());
|
||||
assertEquals(PublishModel.publishers, newConfig.getPublishModel());
|
||||
}
|
||||
|
||||
public void testGetDefaultConfig() throws Exception
|
||||
{
|
||||
ConfigureForm form = getManager().getDefaultConfiguration();
|
||||
assertNotNull(form);
|
||||
}
|
||||
|
||||
public void testDeleteNode() throws Exception
|
||||
{
|
||||
LeafNode myNode = getManager().createNode();
|
||||
assertNotNull(getManager().getNode(myNode.getId()));
|
||||
|
||||
getManager(0).deleteNode(myNode.getId());
|
||||
|
||||
try
|
||||
{
|
||||
assertNull(getManager().getNode(myNode.getId()));
|
||||
fail("Node should not exist");
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testPurgeItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(), true, false);
|
||||
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
|
||||
node.deleteAllItems();
|
||||
items = node.getItems();
|
||||
|
||||
// Pubsub service may keep the last notification (in spec), so 0 or 1 may be returned on get items.
|
||||
assertTrue(items.size() < 2);
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class OwnerUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testCreateInstantNode() throws Exception
|
||||
{
|
||||
LeafNode node = getManager().createNode();
|
||||
assertNotNull(node);
|
||||
assertNotNull(node.getId());
|
||||
}
|
||||
|
||||
public void testCreateNamedNode() throws Exception
|
||||
{
|
||||
String id = "TestNamedNode" + System.currentTimeMillis();
|
||||
LeafNode node = getManager().createNode(id);
|
||||
assertEquals(id, node.getId());
|
||||
}
|
||||
|
||||
public void testCreateConfiguredNode() throws Exception
|
||||
{
|
||||
// Generate reasonably unique for multiple tests
|
||||
String id = "TestConfigNode" + System.currentTimeMillis();
|
||||
|
||||
// Create and configure a node
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
form.setDeliverPayloads(false);
|
||||
form.setNotifyRetract(true);
|
||||
form.setPersistentItems(true);
|
||||
form.setPublishModel(PublishModel.open);
|
||||
|
||||
LeafNode node = (LeafNode)getManager().createNode(id, form);
|
||||
|
||||
ConfigureForm currentForm = node.getNodeConfiguration();
|
||||
assertEquals(AccessModel.open, currentForm.getAccessModel());
|
||||
assertFalse(currentForm.isDeliverPayloads());
|
||||
assertTrue(currentForm.isNotifyRetract());
|
||||
assertTrue(currentForm.isPersistItems());
|
||||
assertEquals(PublishModel.open, currentForm.getPublishModel());
|
||||
}
|
||||
|
||||
public void testCreateAndUpdateConfiguredNode() throws Exception
|
||||
{
|
||||
// Generate reasonably unique for multiple tests
|
||||
String id = "TestConfigNode2" + System.currentTimeMillis();
|
||||
|
||||
// Create and configure a node
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
form.setDeliverPayloads(false);
|
||||
form.setNotifyRetract(true);
|
||||
form.setPersistentItems(true);
|
||||
form.setPublishModel(PublishModel.open);
|
||||
|
||||
LeafNode myNode = (LeafNode)getManager().createNode(id, form);
|
||||
ConfigureForm config = myNode.getNodeConfiguration();
|
||||
|
||||
assertEquals(AccessModel.open, config.getAccessModel());
|
||||
assertFalse(config.isDeliverPayloads());
|
||||
assertTrue(config.isNotifyRetract());
|
||||
assertTrue(config.isPersistItems());
|
||||
assertEquals(PublishModel.open, config.getPublishModel());
|
||||
|
||||
ConfigureForm submitForm = new ConfigureForm(config.createAnswerForm());
|
||||
submitForm.setAccessModel(AccessModel.whitelist);
|
||||
submitForm.setDeliverPayloads(true);
|
||||
submitForm.setNotifyRetract(false);
|
||||
submitForm.setPersistentItems(false);
|
||||
submitForm.setPublishModel(PublishModel.publishers);
|
||||
myNode.sendConfigurationForm(submitForm);
|
||||
|
||||
ConfigureForm newConfig = myNode.getNodeConfiguration();
|
||||
assertEquals(AccessModel.whitelist, newConfig.getAccessModel());
|
||||
assertTrue(newConfig.isDeliverPayloads());
|
||||
assertFalse(newConfig.isNotifyRetract());
|
||||
assertFalse(newConfig.isPersistItems());
|
||||
assertEquals(PublishModel.publishers, newConfig.getPublishModel());
|
||||
}
|
||||
|
||||
public void testGetDefaultConfig() throws Exception
|
||||
{
|
||||
ConfigureForm form = getManager().getDefaultConfiguration();
|
||||
assertNotNull(form);
|
||||
}
|
||||
|
||||
public void testDeleteNode() throws Exception
|
||||
{
|
||||
LeafNode myNode = getManager().createNode();
|
||||
assertNotNull(getManager().getNode(myNode.getId()));
|
||||
|
||||
getManager(0).deleteNode(myNode.getId());
|
||||
|
||||
try
|
||||
{
|
||||
assertNull(getManager().getNode(myNode.getId()));
|
||||
fail("Node should not exist");
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testPurgeItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getRandomPubnode(getManager(), true, false);
|
||||
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
node.send(new Item());
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
|
||||
node.deleteAllItems();
|
||||
items = node.getItems();
|
||||
|
||||
// Pubsub service may keep the last notification (in spec), so 0 or 1 may be returned on get items.
|
||||
assertTrue(items.size() < 2);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,153 +14,153 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.XMPPError.Condition;
|
||||
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.packet.XMPPError.Condition;
|
||||
import org.jivesoftware.smackx.pubsub.packet.PubSubNamespace;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class PublisherUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testSendNodeTrNot() throws Exception
|
||||
{
|
||||
getPubnode(false, false).send();
|
||||
}
|
||||
|
||||
public void testSendNodeTrPay_WithOutPayload() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(false, true);
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item());
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testSendNodeTrPay_WithPayload() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(false, true);
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendNodePerNot() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
node.send(new Item());
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendPerPay_WithPayload() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendPerPay_NoPayload() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
try
|
||||
{
|
||||
node.send(new Item());
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
|
||||
node.deleteItem("1");
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
|
||||
assertEquals(3, items.size());
|
||||
}
|
||||
|
||||
public void testPersistItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
|
||||
assertTrue(items.size() == 4);
|
||||
}
|
||||
|
||||
public void testItemOverwritten() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("test", null, "<test/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("test2", null, "<test2/>")));
|
||||
|
||||
List<? extends Item> items = node.getItems();
|
||||
assertEquals(1, items.size());
|
||||
assertEquals("1", items.get(0).getId());
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class PublisherUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testSendNodeTrNot() throws Exception
|
||||
{
|
||||
getPubnode(false, false).send();
|
||||
}
|
||||
|
||||
public void testSendNodeTrPay_WithOutPayload() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(false, true);
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item());
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testSendNodeTrPay_WithPayload() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(false, true);
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendNodePerNot() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
node.send(new Item());
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendPerPay_WithPayload() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
node.send(new PayloadItem<SimplePayload>(null,
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Lord of the Rings</title></book>")));
|
||||
node.send(new PayloadItem<SimplePayload>("test" + System.currentTimeMillis(),
|
||||
new SimplePayload("book", "pubsub:test:book", "<book xmlns='pubsub:test:book'><title>Two Towers</title></book>")));
|
||||
}
|
||||
|
||||
public void testSendPerPay_NoPayload() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
try
|
||||
{
|
||||
node.send(new Item());
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
node.send(new Item("test" + System.currentTimeMillis()));
|
||||
fail("Exception should be thrown when there is no payload");
|
||||
}
|
||||
catch (XMPPException e) {
|
||||
XMPPError err = e.getXMPPError();
|
||||
assertTrue(err.getType().equals(XMPPError.Type.MODIFY));
|
||||
assertTrue(err.getCondition().equals(Condition.bad_request.toString()));
|
||||
assertNotNull(err.getExtension("payload-required", PubSubNamespace.ERROR.getXmlns()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
|
||||
node.deleteItem("1");
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
|
||||
assertEquals(3, items.size());
|
||||
}
|
||||
|
||||
public void testPersistItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
|
||||
assertTrue(items.size() == 4);
|
||||
}
|
||||
|
||||
public void testItemOverwritten() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("test", null, "<test/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("test2", null, "<test2/>")));
|
||||
|
||||
List<? extends Item> items = node.getItems();
|
||||
assertEquals(1, items.size());
|
||||
assertEquals("1", items.get(0).getId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,267 +14,267 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.FormField;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.FormField;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class SubscriberUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testSubscribe() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
|
||||
assertEquals(getJid(), sub.getJid());
|
||||
assertNotNull(sub.getId());
|
||||
assertEquals(node.getId(), sub.getNode());
|
||||
assertEquals(Subscription.State.subscribed, sub.getState());
|
||||
}
|
||||
|
||||
public void testSubscribeBadJid() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
|
||||
try
|
||||
{
|
||||
node.subscribe("this@over.here");
|
||||
fail();
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testSubscribeWithOptions() throws Exception
|
||||
{
|
||||
SubscribeForm form = new SubscribeForm(FormType.submit);
|
||||
form.setDeliverOn(true);
|
||||
Calendar expire = Calendar.getInstance();
|
||||
expire.set(2020, 1, 1);
|
||||
form.setExpiry(expire.getTime());
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid(), form);
|
||||
}
|
||||
|
||||
public void testSubscribeConfigRequired() throws Exception
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
|
||||
// Openfire specific field - nothing in the spec yet
|
||||
FormField required = new FormField("pubsub#subscription_required");
|
||||
required.setType(FormField.TYPE_BOOLEAN);
|
||||
form.addField(required);
|
||||
form.setAnswer("pubsub#subscription_required", true);
|
||||
LeafNode node = (LeafNode)getManager().createNode("Pubnode" + System.currentTimeMillis(), form);
|
||||
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
|
||||
assertEquals(getJid(), sub.getJid());
|
||||
assertNotNull(sub.getId());
|
||||
assertEquals(node.getId(), sub.getNode());
|
||||
assertEquals(true, sub.isConfigRequired());
|
||||
}
|
||||
|
||||
public void testUnsubscribe() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid());
|
||||
Collection<Subscription> subs = node.getSubscriptions();
|
||||
|
||||
node.unsubscribe(getJid());
|
||||
Collection<Subscription> afterSubs = node.getSubscriptions();
|
||||
assertEquals(subs.size()-1, afterSubs.size());
|
||||
}
|
||||
|
||||
public void testUnsubscribeWithMultipleNoSubId() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getBareJID(0));
|
||||
node.subscribe(getBareJID(0));
|
||||
node.subscribe(getBareJID(0));
|
||||
|
||||
try
|
||||
{
|
||||
node.unsubscribe(getBareJID(0));
|
||||
fail("Unsubscribe with no subid should fail");
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testUnsubscribeWithMultipleWithSubId() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid());
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
node.subscribe(getJid());
|
||||
node.unsubscribe(getJid(), sub.getId());
|
||||
}
|
||||
|
||||
public void testGetOptions() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
SubscribeForm form = node.getSubscriptionOptions(getJid(), sub.getId());
|
||||
assertNotNull(form);
|
||||
}
|
||||
|
||||
// public void testSubscribeWithConfig() throws Exception
|
||||
// {
|
||||
// LeafNode node = getPubnode(false, false);
|
||||
//
|
||||
// Subscription sub = node.subscribe(getBareJID(0));
|
||||
//
|
||||
// assertEquals(getBareJID(0), sub.getJid());
|
||||
// assertNotNull(sub.getId());
|
||||
// assertEquals(node.getId(), sub.getNode());
|
||||
// assertEquals(true, sub.isConfigRequired());
|
||||
// }
|
||||
//
|
||||
public void testGetItems() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
runNodeTests(node);
|
||||
}
|
||||
|
||||
private void runNodeTests(LeafNode node) throws Exception
|
||||
{
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
|
||||
long curTime = System.currentTimeMillis();
|
||||
node.send(new Item("1-" + curTime));
|
||||
node.send(new Item("2-" + curTime));
|
||||
node.send(new Item("3-" + curTime));
|
||||
node.send(new Item("4-" + curTime));
|
||||
node.send(new Item("5-" + curTime));
|
||||
|
||||
items = node.getItems();
|
||||
assertTrue(items.size() == 10);
|
||||
|
||||
LeafNode payloadNode = getPubnode(true, true);
|
||||
|
||||
Map<String , String> idPayload = new HashMap<String, String>();
|
||||
idPayload.put("6-" + curTime, "<a/>");
|
||||
idPayload.put("7-" + curTime, "<a href=\"/up/here\"/>");
|
||||
idPayload.put("8-" + curTime, "<entity>text<inner></inner></entity>");
|
||||
idPayload.put("9-" + curTime, "<entity><inner><text></text></inner></entity>");
|
||||
|
||||
for (Map.Entry<String, String> payload : idPayload.entrySet())
|
||||
{
|
||||
payloadNode.send(new PayloadItem<SimplePayload>(payload.getKey(), new SimplePayload("a", "pubsub:test", payload.getValue())));
|
||||
}
|
||||
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("6-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test'/>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("7-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href=\'/up/here\'/>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("8-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'>text<inner>a</inner></entity>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("9-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>")));
|
||||
|
||||
List<PayloadItem<SimplePayload>> payloadItems = payloadNode.getItems();
|
||||
Map<String, PayloadItem<SimplePayload>> idMap = new HashMap<String, PayloadItem<SimplePayload>>();
|
||||
|
||||
for (PayloadItem<SimplePayload> payloadItem : payloadItems)
|
||||
{
|
||||
idMap.put(payloadItem.getId(), payloadItem);
|
||||
}
|
||||
|
||||
assertEquals(4, payloadItems.size());
|
||||
|
||||
PayloadItem<SimplePayload> testItem = idMap.get("6-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<a xmlns='pubsub:test'/>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("7-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href=\'/up/here\'/>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("8-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<entity xmlns='pubsub:test'>text<inner>a</inner></entity>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("9-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>", testItem.getPayload().toXML());
|
||||
}
|
||||
|
||||
public void testGetSpecifiedItems() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='1'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("2", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='2'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("3", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='3'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("4", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='4'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("5", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='5'/>")));
|
||||
|
||||
Collection<String> ids = new ArrayList<String>(3);
|
||||
ids.add("1");
|
||||
ids.add("3");
|
||||
ids.add("4");
|
||||
|
||||
List<PayloadItem<SimplePayload>> items = node.getItems(ids);
|
||||
assertEquals(3, items.size());
|
||||
assertEquals("1", items.get(0).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='1'/>", items.get(0).getPayload().toXML());
|
||||
assertEquals( "3", items.get(1).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='3'/>", items.get(1).getPayload().toXML());
|
||||
assertEquals("4", items.get(2).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='4'/>", items.get(2).getPayload().toXML());
|
||||
}
|
||||
|
||||
public void testGetLastNItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
node.send(new Item("5"));
|
||||
|
||||
List<Item> items = node.getItems(2);
|
||||
assertEquals(2, items.size());
|
||||
assertTrue(listContainsId("4", items));
|
||||
assertTrue(listContainsId("5", items));
|
||||
}
|
||||
|
||||
private static boolean listContainsId(String id, List<Item> items)
|
||||
{
|
||||
for (Item item : items)
|
||||
{
|
||||
if (item.getId().equals(id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getJid()
|
||||
{
|
||||
return getConnection(0).getUser();
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public class SubscriberUseCases extends SingleUserTestCase
|
||||
{
|
||||
public void testSubscribe() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
|
||||
assertEquals(getJid(), sub.getJid());
|
||||
assertNotNull(sub.getId());
|
||||
assertEquals(node.getId(), sub.getNode());
|
||||
assertEquals(Subscription.State.subscribed, sub.getState());
|
||||
}
|
||||
|
||||
public void testSubscribeBadJid() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
|
||||
try
|
||||
{
|
||||
node.subscribe("this@over.here");
|
||||
fail();
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testSubscribeWithOptions() throws Exception
|
||||
{
|
||||
SubscribeForm form = new SubscribeForm(FormType.submit);
|
||||
form.setDeliverOn(true);
|
||||
Calendar expire = Calendar.getInstance();
|
||||
expire.set(2020, 1, 1);
|
||||
form.setExpiry(expire.getTime());
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid(), form);
|
||||
}
|
||||
|
||||
public void testSubscribeConfigRequired() throws Exception
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
|
||||
// Openfire specific field - nothing in the spec yet
|
||||
FormField required = new FormField("pubsub#subscription_required");
|
||||
required.setType(FormField.TYPE_BOOLEAN);
|
||||
form.addField(required);
|
||||
form.setAnswer("pubsub#subscription_required", true);
|
||||
LeafNode node = (LeafNode)getManager().createNode("Pubnode" + System.currentTimeMillis(), form);
|
||||
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
|
||||
assertEquals(getJid(), sub.getJid());
|
||||
assertNotNull(sub.getId());
|
||||
assertEquals(node.getId(), sub.getNode());
|
||||
assertEquals(true, sub.isConfigRequired());
|
||||
}
|
||||
|
||||
public void testUnsubscribe() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid());
|
||||
Collection<Subscription> subs = node.getSubscriptions();
|
||||
|
||||
node.unsubscribe(getJid());
|
||||
Collection<Subscription> afterSubs = node.getSubscriptions();
|
||||
assertEquals(subs.size()-1, afterSubs.size());
|
||||
}
|
||||
|
||||
public void testUnsubscribeWithMultipleNoSubId() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getBareJID(0));
|
||||
node.subscribe(getBareJID(0));
|
||||
node.subscribe(getBareJID(0));
|
||||
|
||||
try
|
||||
{
|
||||
node.unsubscribe(getBareJID(0));
|
||||
fail("Unsubscribe with no subid should fail");
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testUnsubscribeWithMultipleWithSubId() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
node.subscribe(getJid());
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
node.subscribe(getJid());
|
||||
node.unsubscribe(getJid(), sub.getId());
|
||||
}
|
||||
|
||||
public void testGetOptions() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(false, false);
|
||||
Subscription sub = node.subscribe(getJid());
|
||||
SubscribeForm form = node.getSubscriptionOptions(getJid(), sub.getId());
|
||||
assertNotNull(form);
|
||||
}
|
||||
|
||||
// public void testSubscribeWithConfig() throws Exception
|
||||
// {
|
||||
// LeafNode node = getPubnode(false, false);
|
||||
//
|
||||
// Subscription sub = node.subscribe(getBareJID(0));
|
||||
//
|
||||
// assertEquals(getBareJID(0), sub.getJid());
|
||||
// assertNotNull(sub.getId());
|
||||
// assertEquals(node.getId(), sub.getNode());
|
||||
// assertEquals(true, sub.isConfigRequired());
|
||||
// }
|
||||
//
|
||||
public void testGetItems() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
runNodeTests(node);
|
||||
}
|
||||
|
||||
private void runNodeTests(LeafNode node) throws Exception
|
||||
{
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
node.send((Item)null);
|
||||
|
||||
Collection<? extends Item> items = node.getItems();
|
||||
assertTrue(items.size() == 5);
|
||||
|
||||
long curTime = System.currentTimeMillis();
|
||||
node.send(new Item("1-" + curTime));
|
||||
node.send(new Item("2-" + curTime));
|
||||
node.send(new Item("3-" + curTime));
|
||||
node.send(new Item("4-" + curTime));
|
||||
node.send(new Item("5-" + curTime));
|
||||
|
||||
items = node.getItems();
|
||||
assertTrue(items.size() == 10);
|
||||
|
||||
LeafNode payloadNode = getPubnode(true, true);
|
||||
|
||||
Map<String , String> idPayload = new HashMap<String, String>();
|
||||
idPayload.put("6-" + curTime, "<a/>");
|
||||
idPayload.put("7-" + curTime, "<a href=\"/up/here\"/>");
|
||||
idPayload.put("8-" + curTime, "<entity>text<inner></inner></entity>");
|
||||
idPayload.put("9-" + curTime, "<entity><inner><text></text></inner></entity>");
|
||||
|
||||
for (Map.Entry<String, String> payload : idPayload.entrySet())
|
||||
{
|
||||
payloadNode.send(new PayloadItem<SimplePayload>(payload.getKey(), new SimplePayload("a", "pubsub:test", payload.getValue())));
|
||||
}
|
||||
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("6-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test'/>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("7-" + curTime, new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href=\'/up/here\'/>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("8-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'>text<inner>a</inner></entity>")));
|
||||
payloadNode.send(new PayloadItem<SimplePayload>("9-" + curTime, new SimplePayload("entity", "pubsub:test", "<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>")));
|
||||
|
||||
List<PayloadItem<SimplePayload>> payloadItems = payloadNode.getItems();
|
||||
Map<String, PayloadItem<SimplePayload>> idMap = new HashMap<String, PayloadItem<SimplePayload>>();
|
||||
|
||||
for (PayloadItem<SimplePayload> payloadItem : payloadItems)
|
||||
{
|
||||
idMap.put(payloadItem.getId(), payloadItem);
|
||||
}
|
||||
|
||||
assertEquals(4, payloadItems.size());
|
||||
|
||||
PayloadItem<SimplePayload> testItem = idMap.get("6-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<a xmlns='pubsub:test'/>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("7-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href=\'/up/here\'/>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("8-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<entity xmlns='pubsub:test'>text<inner>a</inner></entity>", testItem.getPayload().toXML());
|
||||
|
||||
testItem = idMap.get("9-" + curTime);
|
||||
assertNotNull(testItem);
|
||||
assertXMLEqual("<entity xmlns='pubsub:test'><inner><text>b</text></inner></entity>", testItem.getPayload().toXML());
|
||||
}
|
||||
|
||||
public void testGetSpecifiedItems() throws Exception
|
||||
{
|
||||
LeafNode node = getPubnode(true, true);
|
||||
|
||||
node.send(new PayloadItem<SimplePayload>("1", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='1'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("2", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='2'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("3", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='3'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("4", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='4'/>")));
|
||||
node.send(new PayloadItem<SimplePayload>("5", new SimplePayload("a", "pubsub:test", "<a xmlns='pubsub:test' href='5'/>")));
|
||||
|
||||
Collection<String> ids = new ArrayList<String>(3);
|
||||
ids.add("1");
|
||||
ids.add("3");
|
||||
ids.add("4");
|
||||
|
||||
List<PayloadItem<SimplePayload>> items = node.getItems(ids);
|
||||
assertEquals(3, items.size());
|
||||
assertEquals("1", items.get(0).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='1'/>", items.get(0).getPayload().toXML());
|
||||
assertEquals( "3", items.get(1).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='3'/>", items.get(1).getPayload().toXML());
|
||||
assertEquals("4", items.get(2).getId());
|
||||
assertXMLEqual("<a xmlns='pubsub:test' href='4'/>", items.get(2).getPayload().toXML());
|
||||
}
|
||||
|
||||
public void testGetLastNItems() throws XMPPException
|
||||
{
|
||||
LeafNode node = getPubnode(true, false);
|
||||
|
||||
node.send(new Item("1"));
|
||||
node.send(new Item("2"));
|
||||
node.send(new Item("3"));
|
||||
node.send(new Item("4"));
|
||||
node.send(new Item("5"));
|
||||
|
||||
List<Item> items = node.getItems(2);
|
||||
assertEquals(2, items.size());
|
||||
assertTrue(listContainsId("4", items));
|
||||
assertTrue(listContainsId("5", items));
|
||||
}
|
||||
|
||||
private static boolean listContainsId(String id, List<Item> items)
|
||||
{
|
||||
for (Item item : items)
|
||||
{
|
||||
if (item.getId().equals(id))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String getJid()
|
||||
{
|
||||
return getConnection(0).getUser();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,27 +14,27 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.test.SingleUserTestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class TestAPI extends SingleUserTestCase
|
||||
{
|
||||
public void testGetNonexistentNode()
|
||||
{
|
||||
try
|
||||
{
|
||||
getManager().getNode("" + System.currentTimeMillis());
|
||||
assertTrue(false);
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class TestAPI extends SingleUserTestCase
|
||||
{
|
||||
public void testGetNonexistentNode()
|
||||
{
|
||||
try
|
||||
{
|
||||
getManager().getNode("" + System.currentTimeMillis());
|
||||
assertTrue(false);
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -14,121 +14,121 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
package org.jivesoftware.smackx.pubsub;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class TestMessageContent extends TestCase
|
||||
{
|
||||
String payloadXmlWithNS = "<book xmlns='pubsub:test:book'><author name='Stephen King'/></book>";
|
||||
|
||||
public void testItemWithId()
|
||||
{
|
||||
Item item = new Item("123");
|
||||
assertEquals("<item id='123'/>", item.toXML());
|
||||
assertEquals("item", item.getElementName());
|
||||
assertNull(item.getNamespace());
|
||||
}
|
||||
|
||||
public void testItemWithNoId()
|
||||
{
|
||||
Item item = new Item();
|
||||
assertEquals("<item/>", item.toXML());
|
||||
|
||||
Item itemNull = new Item(null);
|
||||
assertEquals("<item/>", itemNull.toXML());
|
||||
}
|
||||
|
||||
public void testSimplePayload()
|
||||
{
|
||||
SimplePayload payloadNS = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
|
||||
assertEquals(payloadXmlWithNS, payloadNS.toXML());
|
||||
|
||||
String payloadXmlWithNoNS = "<book><author name='Stephen King'/></book>";
|
||||
SimplePayload payloadNoNS = new SimplePayload("book", null, "<book><author name='Stephen King'/></book>");
|
||||
|
||||
assertEquals(payloadXmlWithNoNS, payloadNoNS.toXML());
|
||||
|
||||
}
|
||||
|
||||
public void testPayloadItemWithId()
|
||||
{
|
||||
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("123", payload);
|
||||
|
||||
String xml = "<item id='123'>" + payloadXmlWithNS + "</item>";
|
||||
assertEquals(xml, item.toXML());
|
||||
assertEquals("item", item.getElementName());
|
||||
}
|
||||
|
||||
public void testPayloadItemWithNoId()
|
||||
{
|
||||
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, payload);
|
||||
|
||||
String xml = "<item>" + payloadXmlWithNS + "</item>";
|
||||
assertEquals(xml, item.toXML());
|
||||
}
|
||||
|
||||
public void testPayloadItemWithIdNoPayload()
|
||||
{
|
||||
try
|
||||
{
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("123", null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testPayloadItemWithNoIdNoPayload()
|
||||
{
|
||||
try
|
||||
{
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testRetractItem()
|
||||
{
|
||||
RetractItem item = new RetractItem("1234");
|
||||
|
||||
assertEquals("<retract id='1234'/>", item.toXML());
|
||||
assertEquals("retract", item.getElementName());
|
||||
|
||||
try
|
||||
{
|
||||
new RetractItem(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetItemsRequest()
|
||||
{
|
||||
GetItemsRequest request = new GetItemsRequest("testId");
|
||||
assertEquals("<items node='testId'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", 5);
|
||||
assertEquals("<items node='testId' max_items='5'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", "qwerty");
|
||||
assertEquals("<items node='testId' subid='qwerty'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", "qwerty", 5);
|
||||
assertEquals("<items node='testId' subid='qwerty' max_items='5'/>", request.toXML());
|
||||
}
|
||||
}
|
||||
*/
|
||||
public class TestMessageContent extends TestCase
|
||||
{
|
||||
String payloadXmlWithNS = "<book xmlns='pubsub:test:book'><author name='Stephen King'/></book>";
|
||||
|
||||
public void testItemWithId()
|
||||
{
|
||||
Item item = new Item("123");
|
||||
assertEquals("<item id='123'/>", item.toXML());
|
||||
assertEquals("item", item.getElementName());
|
||||
assertNull(item.getNamespace());
|
||||
}
|
||||
|
||||
public void testItemWithNoId()
|
||||
{
|
||||
Item item = new Item();
|
||||
assertEquals("<item/>", item.toXML());
|
||||
|
||||
Item itemNull = new Item(null);
|
||||
assertEquals("<item/>", itemNull.toXML());
|
||||
}
|
||||
|
||||
public void testSimplePayload()
|
||||
{
|
||||
SimplePayload payloadNS = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
|
||||
assertEquals(payloadXmlWithNS, payloadNS.toXML());
|
||||
|
||||
String payloadXmlWithNoNS = "<book><author name='Stephen King'/></book>";
|
||||
SimplePayload payloadNoNS = new SimplePayload("book", null, "<book><author name='Stephen King'/></book>");
|
||||
|
||||
assertEquals(payloadXmlWithNoNS, payloadNoNS.toXML());
|
||||
|
||||
}
|
||||
|
||||
public void testPayloadItemWithId()
|
||||
{
|
||||
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("123", payload);
|
||||
|
||||
String xml = "<item id='123'>" + payloadXmlWithNS + "</item>";
|
||||
assertEquals(xml, item.toXML());
|
||||
assertEquals("item", item.getElementName());
|
||||
}
|
||||
|
||||
public void testPayloadItemWithNoId()
|
||||
{
|
||||
SimplePayload payload = new SimplePayload("book", "pubsub:test:book", payloadXmlWithNS);
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, payload);
|
||||
|
||||
String xml = "<item>" + payloadXmlWithNS + "</item>";
|
||||
assertEquals(xml, item.toXML());
|
||||
}
|
||||
|
||||
public void testPayloadItemWithIdNoPayload()
|
||||
{
|
||||
try
|
||||
{
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>("123", null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testPayloadItemWithNoIdNoPayload()
|
||||
{
|
||||
try
|
||||
{
|
||||
PayloadItem<SimplePayload> item = new PayloadItem<SimplePayload>(null, null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testRetractItem()
|
||||
{
|
||||
RetractItem item = new RetractItem("1234");
|
||||
|
||||
assertEquals("<retract id='1234'/>", item.toXML());
|
||||
assertEquals("retract", item.getElementName());
|
||||
|
||||
try
|
||||
{
|
||||
new RetractItem(null);
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetItemsRequest()
|
||||
{
|
||||
GetItemsRequest request = new GetItemsRequest("testId");
|
||||
assertEquals("<items node='testId'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", 5);
|
||||
assertEquals("<items node='testId' max_items='5'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", "qwerty");
|
||||
assertEquals("<items node='testId' subid='qwerty'/>", request.toXML());
|
||||
|
||||
request = new GetItemsRequest("testId", "qwerty", 5);
|
||||
assertEquals("<items node='testId' subid='qwerty' max_items='5'/>", request.toXML());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,79 +14,79 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub.test;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.pubsub.AccessModel;
|
||||
import org.jivesoftware.smackx.pubsub.ConfigureForm;
|
||||
import org.jivesoftware.smackx.pubsub.FormType;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
package org.jivesoftware.smackx.pubsub.test;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.test.SmackTestCase;
|
||||
import org.jivesoftware.smackx.pubsub.AccessModel;
|
||||
import org.jivesoftware.smackx.pubsub.ConfigureForm;
|
||||
import org.jivesoftware.smackx.pubsub.FormType;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
abstract public class PubSubTestCase extends SmackTestCase
|
||||
{
|
||||
private PubSubManager[] manager;
|
||||
|
||||
public PubSubTestCase(String arg0)
|
||||
{
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public PubSubTestCase()
|
||||
{
|
||||
super("PubSub Test Case");
|
||||
}
|
||||
|
||||
protected LeafNode getRandomPubnode(PubSubManager pubMgr, boolean persistItems, boolean deliverPayload) throws XMPPException
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setPersistentItems(persistItems);
|
||||
form.setDeliverPayloads(deliverPayload);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
return (LeafNode)pubMgr.createNode("/test/Pubnode" + System.currentTimeMillis(), form);
|
||||
}
|
||||
|
||||
protected LeafNode getPubnode(PubSubManager pubMgr, boolean persistItems, boolean deliverPayload, String nodeId) throws XMPPException
|
||||
{
|
||||
LeafNode node = null;
|
||||
|
||||
try
|
||||
{
|
||||
node = (LeafNode)pubMgr.getNode(nodeId);
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setPersistentItems(persistItems);
|
||||
form.setDeliverPayloads(deliverPayload);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
node = (LeafNode)pubMgr.createNode(nodeId, form);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
protected PubSubManager getManager(int idx)
|
||||
{
|
||||
if (manager == null)
|
||||
{
|
||||
manager = new PubSubManager[getMaxConnections()];
|
||||
|
||||
for(int i=0; i<manager.length; i++)
|
||||
{
|
||||
manager[i] = new PubSubManager(getConnection(i), getService());
|
||||
}
|
||||
}
|
||||
return manager[idx];
|
||||
}
|
||||
|
||||
protected String getService()
|
||||
{
|
||||
return "pubsub." + getServiceName();
|
||||
}
|
||||
}
|
||||
*/
|
||||
abstract public class PubSubTestCase extends SmackTestCase
|
||||
{
|
||||
private PubSubManager[] manager;
|
||||
|
||||
public PubSubTestCase(String arg0)
|
||||
{
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
public PubSubTestCase()
|
||||
{
|
||||
super("PubSub Test Case");
|
||||
}
|
||||
|
||||
protected LeafNode getRandomPubnode(PubSubManager pubMgr, boolean persistItems, boolean deliverPayload) throws XMPPException
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setPersistentItems(persistItems);
|
||||
form.setDeliverPayloads(deliverPayload);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
return (LeafNode)pubMgr.createNode("/test/Pubnode" + System.currentTimeMillis(), form);
|
||||
}
|
||||
|
||||
protected LeafNode getPubnode(PubSubManager pubMgr, boolean persistItems, boolean deliverPayload, String nodeId) throws XMPPException
|
||||
{
|
||||
LeafNode node = null;
|
||||
|
||||
try
|
||||
{
|
||||
node = (LeafNode)pubMgr.getNode(nodeId);
|
||||
}
|
||||
catch (XMPPException e)
|
||||
{
|
||||
ConfigureForm form = new ConfigureForm(FormType.submit);
|
||||
form.setPersistentItems(persistItems);
|
||||
form.setDeliverPayloads(deliverPayload);
|
||||
form.setAccessModel(AccessModel.open);
|
||||
node = (LeafNode)pubMgr.createNode(nodeId, form);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
protected PubSubManager getManager(int idx)
|
||||
{
|
||||
if (manager == null)
|
||||
{
|
||||
manager = new PubSubManager[getMaxConnections()];
|
||||
|
||||
for(int i=0; i<manager.length; i++)
|
||||
{
|
||||
manager[i] = new PubSubManager(getConnection(i), getService());
|
||||
}
|
||||
}
|
||||
return manager[idx];
|
||||
}
|
||||
|
||||
protected String getService()
|
||||
{
|
||||
return "pubsub." + getServiceName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,33 +14,33 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smackx.pubsub.test;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
package org.jivesoftware.smackx.pubsub.test;
|
||||
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.pubsub.LeafNode;
|
||||
import org.jivesoftware.smackx.pubsub.PubSubManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class SingleUserTestCase extends PubSubTestCase
|
||||
{
|
||||
protected PubSubManager getManager()
|
||||
{
|
||||
return getManager(0);
|
||||
}
|
||||
|
||||
protected LeafNode getPubnode(boolean persistItems, boolean deliverPayload) throws XMPPException
|
||||
{
|
||||
return getRandomPubnode(getManager(), persistItems, deliverPayload);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
public class SingleUserTestCase extends PubSubTestCase
|
||||
{
|
||||
protected PubSubManager getManager()
|
||||
{
|
||||
return getManager(0);
|
||||
}
|
||||
|
||||
protected LeafNode getPubnode(boolean persistItems, boolean deliverPayload) throws XMPPException
|
||||
{
|
||||
return getRandomPubnode(getManager(), persistItems, deliverPayload);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaxConnections()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue