mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-12-06 13:11:08 +01: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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue