pubSubManager = managers.get(pubSubService); if (pubSubManager == null) { pubSubManager = new PubSubManager(connection, pubSubService); managers.put(pubSubService, pubSubManager);
@Test public void deleteNodeTest() throws InterruptedException, SmackException, IOException, XMPPException { ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); PubSubManager mgr = new PubSubManager(con, DUMMY_PUBSUB_SERVICE); mgr.deleteNode("foo@bar.org"); PubSub pubSubDeleteRequest = con.getSentPacket(); assertEquals("http://jabber.org/protocol/pubsub#owner", pubSubDeleteRequest.getChildElementNamespace()); assertEquals("pubsub", pubSubDeleteRequest.getChildElementName()); } }
@Test(expected = SmackException.class) public void getConfigFormWithTimeout() throws XMPPException, SmackException, InterruptedException { ThreadedDummyConnection con = new ThreadedDummyConnection(); PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE); DiscoverInfo info = new DiscoverInfo(); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); con.addIQReply(info); Node node = mgr.getNode("princely_musings"); SmackConfiguration.setDefaultReplyTimeout(100); con.setTimeout(); node.getNodeConfiguration(); }
XMPPConnection connection = ConnectionUtils.createMockedConnection(protocol, JidTestUtil.FULL_JID_1_RESOURCE_1); PubSubManager mgr = new PubSubManager(connection, JidTestUtil.PUBSUB_EXAMPLE_ORG); Node testNode = new LeafNode(mgr, "princely_musings");
@Test public void modifySubscriptionsAsOwnerTest() throws InterruptedException, SmackException, IOException, XMPPException, Exception { ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); PubSubManager mgr = new PubSubManager(con, JidTestUtil.PUBSUB_EXAMPLE_ORG); Node testNode = new LeafNode(mgr, "princely_musings"); List<Subscription> ChangeSubs = Arrays.asList( new Subscription(JidCreate.from("romeo@montague.org"), Subscription.State.subscribed), new Subscription(JidCreate.from("juliet@capulet.org"), Subscription.State.none) ); testNode.modifySubscriptionsAsOwner(ChangeSubs); PubSub request = con.getSentPacket(); assertEquals("http://jabber.org/protocol/pubsub#owner", request.getChildElementNamespace()); assertEquals("pubsub", request.getChildElementName()); XmlPullParser parser = TestUtils.getIQParser(request.toXML(null).toString()); PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser); SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS_OWNER); List<Subscription> subscriptions = subElem.getSubscriptions(); assertEquals(2, subscriptions.size()); Subscription sub1 = subscriptions.get(0); assertEquals("romeo@montague.org", sub1.getJid().toString()); assertEquals(Subscription.State.subscribed, sub1.getState()); Subscription sub2 = subscriptions.get(1); assertEquals("juliet@capulet.org", sub2.getJid().toString()); assertEquals(Subscription.State.none, sub2.getState()); }
@Test public void getConfigFormWithInsufficientPrivileges() throws XMPPException, SmackException, IOException, InterruptedException { ThreadedDummyConnection con = ThreadedDummyConnection.newInstance(); PubSubManager mgr = new PubSubManager(con, PubSubManagerTest.DUMMY_PUBSUB_SERVICE); DiscoverInfo info = new DiscoverInfo(); info.setType(Type.result); info.setFrom(PubSubManagerTest.DUMMY_PUBSUB_SERVICE); Identity ident = new Identity("pubsub", null, "leaf"); info.addIdentity(ident); con.addIQReply(info); Node node = mgr.getNode("princely_musings"); PubSub errorIq = new PubSub(); errorIq.setType(Type.error); errorIq.setFrom(PubSubManagerTest.DUMMY_PUBSUB_SERVICE); StanzaError.Builder error = StanzaError.getBuilder(Condition.forbidden); errorIq.setError(error); con.addIQReply(errorIq); try { node.getNodeConfiguration(); fail(); } catch (XMPPErrorException e) { Assert.assertEquals(StanzaError.Type.AUTH, e.getStanzaError().getType()); } }
manager = new PubSubManager(xmppCon, PUBSUB_SERVER_PREFIX + server); } catch (XMPPException e) { logger.error("Unable to connect to XMPP server: " + e); manager = new PubSubManager(xmppCon, PUBSUB_SERVER_PREFIX + server); } catch (XMPPException e) { logger.error("Unable to connect to XMPP server: " + e);