use of org.jivesoftware.smack.PrivacyListManager in project Smack by igniterealtime.
the class PrivacyTest method testCreateAndUpdateList.
/**
* Check when a client set a new list and then update its content.
*/
public void testCreateAndUpdateList() {
try {
String listName = "testCreateAndUpdateList";
String user = "tybalt@example.com";
PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0));
PrivacyClient client = new PrivacyClient(privacyManager);
privacyManager.addListener(client);
// Add the list that will be set as the active
ArrayList<PrivacyItem> items = new ArrayList<PrivacyItem>();
PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.name(), true, 1);
item.setValue(getConnection(0).getUser());
items.add(item);
privacyManager.createPrivacyList(listName, items);
Thread.sleep(500);
// Remove the existing item and add a new one.
items.remove(item);
item = new PrivacyItem(PrivacyItem.Type.jid.name(), false, 2);
item.setValue(user);
item.setFilterPresence_out(true);
item.setFilterPresence_in(true);
item.setFilterMessage(true);
items.add(item);
// Update the list on server
privacyManager.updatePrivacyList(listName, items);
Thread.sleep(500);
// Assert the list composition.
PrivacyList list = privacyManager.getPrivacyList(listName);
assertEquals(1, list.getItems().size());
// Assert the privacy item composition
PrivacyItem receivedItem = list.getItems().get(0);
assertEquals(2, receivedItem.getOrder());
assertEquals(PrivacyItem.Type.jid, receivedItem.getType());
assertEquals(false, receivedItem.isAllow());
assertEquals(user, receivedItem.getValue());
assertEquals(false, receivedItem.isFilterEverything());
assertEquals(true, receivedItem.isFilterMessage());
assertEquals(true, receivedItem.isFilterPresence_in());
assertEquals(true, receivedItem.isFilterPresence_out());
assertEquals(true, client.wasModified());
privacyManager.deletePrivacyList(listName);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.jivesoftware.smack.PrivacyListManager in project Smack by igniterealtime.
the class PrivacyTest method testDenyActiveList.
/**
* Check when a client denies the use of the active list.
*/
public void testDenyActiveList() {
try {
PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0));
PrivacyClient client = new PrivacyClient(privacyManager);
privacyManager.addListener(client);
privacyManager.declineActiveList();
Thread.sleep(500);
try {
// The list should not exist and an error will be raised
privacyManager.getActiveList();
} catch (XMPPException xmppException) {
assertEquals(404, xmppException.getXMPPError().getCode());
}
assertEquals(null, null);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of org.jivesoftware.smack.PrivacyListManager in project Smack by igniterealtime.
the class PrivacyTest method testRemoveList.
/**
* Check when a client add a new list and then remove it.
*/
public void testRemoveList() {
try {
String listName = "testRemoveList";
PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0));
PrivacyClient client = new PrivacyClient(privacyManager);
privacyManager.addListener(client);
// Add the list that will be set as the Default
ArrayList<PrivacyItem> items = new ArrayList<PrivacyItem>();
PrivacyItem item = new PrivacyItem(PrivacyItem.Type.jid.name(), true, 1);
item.setValue(getConnection(0).getUser());
items.add(item);
privacyManager.createPrivacyList(listName, items);
Thread.sleep(500);
// Set the Default list
privacyManager.setDefaultListName(listName);
Thread.sleep(500);
privacyManager.deletePrivacyList(listName);
Thread.sleep(500);
try {
// The list should not exist and an error will be raised
privacyManager.getPrivacyList(listName);
} catch (XMPPException xmppException) {
assertEquals(404, xmppException.getXMPPError().getCode());
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations