当前位置: 首页>>代码示例>>Java>>正文


Java PacketParserUtils.parseIQ方法代码示例

本文整理汇总了Java中org.jivesoftware.smack.util.PacketParserUtils.parseIQ方法的典型用法代码示例。如果您正苦于以下问题:Java PacketParserUtils.parseIQ方法的具体用法?Java PacketParserUtils.parseIQ怎么用?Java PacketParserUtils.parseIQ使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jivesoftware.smack.util.PacketParserUtils的用法示例。


在下文中一共展示了PacketParserUtils.parseIQ方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSimpleRosterPush

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
/**
 * Test a simple roster push according to the example in
 * <a href="http://xmpp.org/internet-drafts/draft-ietf-xmpp-3921bis-03.html#roster-syntax-actions-push"
 *     >RFC3921bis-03: Roster Push</a>.
 */
@Test
public void testSimpleRosterPush() throws Throwable {
    final String contactJID = "[email protected]";
    assertNotNull("Can't get the roster from the provided connection!", roster);
    final StringBuilder sb = new StringBuilder();
    sb.append("<iq id=\"rostertest1\" type=\"set\" ")
            .append("to=\"").append(connection.getUser()).append("\">")
            .append("<query xmlns=\"jabber:iq:roster\">")
            .append("<item jid=\"").append(contactJID).append("\"/>")
            .append("</query>")
            .append("</iq>");
    final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
    final IQ rosterPush = PacketParserUtils.parseIQ(parser);
    initRoster();
    rosterListener.reset();

    // Simulate receiving the roster push
    connection.processPacket(rosterPush);
    rosterListener.waitUntilInvocationOrTimeout();

    // Verify the roster entry of the new contact
    final RosterEntry addedEntry = roster.getEntry(contactJID);
    assertNotNull("The new contact wasn't added to the roster!", addedEntry);
    assertTrue("The roster listener wasn't invoked for the new contact!",
            rosterListener.getAddedAddresses().contains(contactJID));
    assertSame("Setup wrong default subscription status!",
            ItemType.none,
            addedEntry.getType());
    assertSame("The new contact shouldn't be member of any group!",
            0,
            addedEntry.getGroups().size());

    // Verify the unchanged roster items
    verifyRomeosEntry(roster.getEntry("[email protected]"));
    verifyMercutiosEntry(roster.getEntry("[email protected]"));
    verifyBenvoliosEntry(roster.getEntry("[email protected]"));
    assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:44,代码来源:RosterTest.java

示例2: subscriptionsOwnerResultTest

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
@Test
public void subscriptionsOwnerResultTest() throws Exception {
    // @formatter:off
    final String resultStanza = 
      "<iq from='pubsub.example.org' to='[email protected]/Smack' id='HaT4m-13' type='result'>" +
        "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>" + 
          "<subscriptions node='test'>" + 
            "<subscription jid='[email protected]/Smack' subscription='subscribed' subid='58C1A6F99F2A7'/>" +
            "<subscription jid='[email protected]/Smack' subscription='subscribed' subid='58C18F8917321'/>" +
          "</subscriptions>" +
        "</pubsub>" +
      "</iq>";
    // @formatter:on
    XmlPullParser parser = TestUtils.getIQParser(resultStanza);
    PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser);
    SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS);
    List<Subscription> subscriptions = subElem.getSubscriptions();
    assertEquals(2, subscriptions.size());

    Subscription sub1 = subscriptions.get(0);
    assertEquals("[email protected]/Smack", sub1.getJid());
    assertEquals(Subscription.State.subscribed, sub1.getState());
    assertEquals("58C1A6F99F2A7", sub1.getId());

    Subscription sub2 = subscriptions.get(1);
    assertEquals("[email protected]/Smack", sub2.getJid());
    assertEquals(Subscription.State.subscribed, sub2.getState());
    assertEquals("58C18F8917321", sub2.getId());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:30,代码来源:PubSubProviderTest.java

示例3: testEmptyGroupRosterPush

import org.jivesoftware.smack.util.PacketParserUtils; //导入方法依赖的package包/类
/**
 * Test processing a roster push with an empty group is equivalent with providing
 * no group.
 * 
 * @see <a href="http://www.igniterealtime.org/issues/browse/SMACK-294">SMACK-294</a>
 */
@Test
public void testEmptyGroupRosterPush() throws Throwable {
    final String contactJID = "[email protected]";
    assertNotNull("Can't get the roster from the provided connection!", roster);
    final StringBuilder sb = new StringBuilder();
    sb.append("<iq id=\"rostertest2\" type=\"set\" ")
            .append("to=\"").append(connection.getUser()).append("\">")
            .append("<query xmlns=\"jabber:iq:roster\">")
            .append("<item jid=\"").append(contactJID).append("\">")
            .append("<group></group>")
            .append("</item>")
            .append("</query>")
            .append("</iq>");
    final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
    final IQ rosterPush = PacketParserUtils.parseIQ(parser);
    initRoster();
    rosterListener.reset();

    // Simulate receiving the roster push
    connection.processPacket(rosterPush);
    rosterListener.waitUntilInvocationOrTimeout();

    // Verify the roster entry of the new contact
    final RosterEntry addedEntry = roster.getEntry(contactJID);
    assertNotNull("The new contact wasn't added to the roster!", addedEntry);
    assertTrue("The roster listener wasn't invoked for the new contact!",
            rosterListener.getAddedAddresses().contains(contactJID));
    assertSame("Setup wrong default subscription status!",
            ItemType.none,
            addedEntry.getType());
    assertSame("The new contact shouldn't be member of any group!",
            0,
            addedEntry.getGroups().size());

    // Verify the unchanged roster items
    verifyRomeosEntry(roster.getEntry("[email protected]"));
    verifyMercutiosEntry(roster.getEntry("[email protected]"));
    verifyBenvoliosEntry(roster.getEntry("[email protected]"));
    assertSame("Wrong number of roster entries.", 4, roster.getEntries().size());
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:47,代码来源:RosterTest.java


注:本文中的org.jivesoftware.smack.util.PacketParserUtils.parseIQ方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。