/** * Check when a client denies the use of a default list. */ public void testDenyDefaultList() { try { PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0)); PrivacyClient client = new PrivacyClient(privacyManager); privacyManager.addListener(client); privacyManager.declineDefaultList(); Thread.sleep(500); try { // The list should not exist and an error will be raised privacyManager.getDefaultList(); } catch (XMPPException xmppException) { assertEquals(404, xmppException.getXMPPError().getCode()); } assertEquals(null, null); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
/** * 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()); } }
/** * Constructor. * @param con The connection to adapt * @param login The login to use * @param password The password to use * @param service the background service associated with the connection. */ public XmppConnectionAdapter(final XMPPConnection con, final String login, final String password, final BeemService service) { mAdaptee = con; PrivacyListManager.getInstanceFor(mAdaptee); mLogin = login; mPassword = password; mService = service; Context ctx = mService.getApplicationContext(); if (ctx instanceof BeemApplication) { mApplication = (BeemApplication) ctx; } mPref = mService.getServicePreference(); try { mPreviousPriority = Integer.parseInt(mPref.getString(BeemApplication.CONNECTION_PRIORITY_KEY, "0")); } catch (NumberFormatException ex) { mPreviousPriority = 0; } mResource = mPref.getString(BeemApplication.CONNECTION_RESOURCE_KEY, "Beem"); }
/** * Check when a client set a new active list. */ public void testCreateActiveList() { try { String listName = "testCreateActiveList"; 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); // Set the active list privacyManager.setActiveListName(listName); Thread.sleep(500); // Assert the list composition. assertEquals(listName, privacyManager.getActiveList().toString()); List<PrivacyItem> privacyItems = privacyManager.getPrivacyList(listName).getItems(); assertEquals(1, privacyItems.size()); // Assert the privacy item composition PrivacyItem receivedItem = privacyItems.get(0); assertEquals(1, receivedItem.getOrder()); assertEquals(PrivacyItem.Type.jid, receivedItem.getType()); assertEquals(true, receivedItem.isAllow()); privacyManager.deletePrivacyList(listName); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
/** * Check when a client set a new default list. */ public void testCreateDefaultList() { try { String listName = "testCreateDefaultList"; 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); // Assert the list composition. assertEquals(listName, privacyManager.getDefaultList().toString()); List<PrivacyItem> privacyItems = privacyManager.getPrivacyList(listName).getItems(); assertEquals(1, privacyItems.size()); // Assert the privacy item composition PrivacyItem receivedItem = privacyItems.get(0); assertEquals(1, receivedItem.getOrder()); assertEquals(PrivacyItem.Type.jid, receivedItem.getType()); assertEquals(true, receivedItem.isAllow()); privacyManager.deletePrivacyList(listName); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
/** * 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()); } }
/** * Creating PrivacyListManager instance */ private PrivacyManager() { XMPPConnection conn = SparkManager.getConnection(); if (conn == null) { Log.error("Privacy plugin: Connection not initialized."); } _active = checkIfPrivacyIsSupported(conn); if (_active) { privacyManager = PrivacyListManager.getInstanceFor(conn); initializePrivacyLists(); } }
/** * Check when a client set more than one list. */ public void testCreateTwoLists() { try { String listName1 = "1testCreateTwoLists"; String listName2 = "2testCreateTwoLists"; String groupName = "testCreateTwoListsGroup"; PrivacyListManager privacyManager = PrivacyListManager.getInstanceFor(getConnection(0)); PrivacyClient client = new PrivacyClient(privacyManager); privacyManager.addListener(client); // Add a list 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(listName1, items); Thread.sleep(500); // Add the another list ArrayList<PrivacyItem> itemsList2 = new ArrayList<PrivacyItem>(); item = new PrivacyItem(PrivacyItem.Type.group.name(), false, 2); item.setValue(groupName); item.setFilterMessage(true); itemsList2.add(item); privacyManager.createPrivacyList(listName2, itemsList2); Thread.sleep(500); // Assert the list composition. PrivacyList[] privacyLists = privacyManager.getPrivacyLists(); PrivacyList receivedList1 = null; PrivacyList receivedList2 = null; for (PrivacyList privacyList : privacyLists) { if (listName1.equals(privacyList.toString())) { receivedList1 = privacyList; } if (listName2.equals(privacyList.toString())) { receivedList2 = privacyList; } } PrivacyItem receivedItem; // Assert on the list 1 assertNotNull(receivedList1); assertEquals(1, receivedList1.getItems().size()); receivedItem = receivedList1.getItems().get(0); assertEquals(1, receivedItem.getOrder()); assertEquals(PrivacyItem.Type.jid, receivedItem.getType()); assertEquals(true, receivedItem.isAllow()); assertEquals(getConnection(0).getUser(), receivedItem.getValue()); // Assert on the list 2 assertNotNull(receivedList2); assertEquals(1, receivedList2.getItems().size()); receivedItem = receivedList2.getItems().get(0); assertEquals(2, receivedItem.getOrder()); assertEquals(PrivacyItem.Type.group, receivedItem.getType()); assertEquals(groupName, receivedItem.getValue()); assertEquals(false, receivedItem.isAllow()); assertEquals(groupName, receivedItem.getValue()); assertEquals(false, receivedItem.isFilterEverything()); assertEquals(true, receivedItem.isFilterMessage()); assertEquals(false, receivedItem.isFilterPresence_in()); assertEquals(false, receivedItem.isFilterPresence_out()); privacyManager.deletePrivacyList(listName1); privacyManager.deletePrivacyList(listName2); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
public PrivacyClient(PrivacyListManager manager) { super(); }
/** * Constructor. * @param privacyListManager the privacy list manager */ public PrivacyListManagerAdapter(final PrivacyListManager privacyListManager) { mPrivacyListManager = privacyListManager; mPrivacyListManager.addListener(mPrivacyListListener); }
/** * Get <code>org.jivesoftware.smack.PrivacyListManager</code> instance * * @return PrivacyListManager */ public PrivacyListManager getPrivacyListManager() { return privacyManager; }