Codota Logo
TestUtils
Code IndexAdd Codota to your IDE (free)

How to use
TestUtils
in
org.jivesoftware.smack.test.util

Best Java code snippets using org.jivesoftware.smack.test.util.TestUtils (Showing top 20 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
StringBuilder s =
  • Codota Iconnew StringBuilder()
  • Codota Iconnew StringBuilder(32)
  • Codota IconString str;new StringBuilder(str)
  • Smart code suggestions by Codota
}
origin: igniterealtime/Smack

  /**
   * @param output
   * @return
   * @throws XmlPullParserException
   * @throws IOException
   */
  private static XmlPullParser getParser(String output) throws XmlPullParserException, IOException {
    return TestUtils.getParser(output, "validate");
  }
}
origin: igniterealtime/Smack

public static <EE extends ExtensionElement> EE parseExtensionElement(String elementString)
        throws Exception {
  return parseExtensionElement(getParser(elementString));
}
origin: igniterealtime/Smack

  @Test
  public void parseTest() throws Exception {
    // @formatter:off
    final String capsExtensionString =
      "<c xmlns='http://jabber.org/protocol/caps'"
      + " hash='sha-1'"
      + " node='http://foo.example.org/bar'"
      + " ver='QgayPKawpkPSDYmwt/WM94uA1u0='/>";
    // @formatter:on
    CapsExtension capsExtension = TestUtils.parseExtensionElement(capsExtensionString);
    assertNotNull(capsExtension);
  }
}
origin: igniterealtime/Smack

    .append("</query>")
    .append("</iq>");
final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
final IQ rosterPush = PacketParserUtils.parseIQ(parser);
initRoster();
origin: igniterealtime/Smack

  @Test
  public void headersInMessageTest() throws Exception {
    // @formatter:off
    final String messageStanza =
     "<message xmlns='jabber:client' from='romeo@shakespeare.lit/orchard' to='juliet@capulet.com' type='chat'>" +
      "<body>Wherefore are thou?!?</body>" +
      "<headers xmlns='http://jabber.org/protocol/shim'>" +
       "<header name='Urgency'>high</header>" +
      "</headers>" +
     "</message>";
    // @formatter:on
    XmlPullParser parser = TestUtils.getMessageParser(messageStanza);
    Message message = PacketParserUtils.parseMessage(parser);
    HeadersExtension headers = HeadersExtension.from(message);
    Header header = headers.getHeaders().get(0);
    assertEquals("Urgency", header.getName());
    assertEquals("high", header.getValue());
  }
}
origin: igniterealtime/Smack

@Test
public void testParseOxEmeElement() throws Exception {
  ExplicitMessageEncryptionElement eme = TestUtils.parseExtensionElement(OX_EME_ELEMENT);
  assertEquals(ExplicitMessageEncryptionProtocol.openpgpV0, eme.getProtocol());
}
origin: igniterealtime/Smack

    .append("</query>")
    .append("</iq>");
final XmlPullParser parser = TestUtils.getIQParser(sb.toString());
final IQ rosterPush = PacketParserUtils.parseIQ(parser);
initRoster();
origin: igniterealtime/Smack

@Test
public void consumeUnparsedInput() throws Exception {
  final String MESSAGE_EXCEPTION_ELEMENT =
          "<" + ThrowException.ELEMENT + " xmlns='" + ThrowException.NAMESPACE + "'>" +
            "<nothingInHere>" +
            "</nothingInHere>" +
          "</" + ThrowException.ELEMENT + ">";
  XmlPullParser parser = TestUtils.getMessageParser(
      "<message from='user@server.example' to='francisco@denmark.lit' id='foo'>" +
        MESSAGE_EXCEPTION_ELEMENT +
        EXTENSION2 +
      "</message>");
  int parserDepth = parser.getDepth();
  CharSequence content = null;
  try {
    PacketParserUtils.parseMessage(parser);
  } catch (Exception e) {
    content = PacketParserUtils.parseContentDepth(parser, parserDepth, false);
  }
  assertThat(MESSAGE_EXCEPTION_ELEMENT + EXTENSION2 + "</message>", equalsCharSequence(content));
}
origin: igniterealtime/Smack

public static XmlPullParser getMessageParser(String stanza) {
  return getParser(stanza, "message");
}
origin: igniterealtime/Smack

  @Test
  public void testParseUnknownEmeElement() throws Exception {
    ExplicitMessageEncryptionElement eme = TestUtils.parseExtensionElement(UNKNOWN_EME_ELEMENT);
    assertEquals(UNKNOWN_NAMESPACE, eme.getEncryptionNamespace());
    assertEquals(UNKNOWN_NAME, eme.getName());
  }
}
origin: igniterealtime/Smack

  @Test
  public void subscriptionsOwnerResultTest() throws Exception {
    // @formatter:off
    final String resultStanza =
     "<iq from='pubsub.example.org' to='julia@example.org/Smack' id='HaT4m-13' type='result'>" +
      "<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>" +
       "<subscriptions node='test'>" +
        "<subscription jid='foo@example.org/Smack' subscription='subscribed' subid='58C1A6F99F2A7'/>" +
        "<subscription jid='julia@example.org/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_OWNER);
    List<Subscription> subscriptions = subElem.getSubscriptions();
    assertEquals(2, subscriptions.size());

    Subscription sub1 = subscriptions.get(0);
    assertThat("foo@example.org/Smack", equalsCharSequence(sub1.getJid()));
    assertEquals(Subscription.State.subscribed, sub1.getState());
    assertEquals("58C1A6F99F2A7", sub1.getId());

    Subscription sub2 = subscriptions.get(1);
    assertThat("julia@example.org/Smack", equalsCharSequence(sub2.getJid()));
    assertEquals(Subscription.State.subscribed, sub2.getState());
    assertEquals("58C18F8917321", sub2.getId());
  }
}
origin: igniterealtime/Smack

/**
 * RFC6121 5.2.3 explicitly disallows mixed content in <body/> elements. Make sure that we throw
 * an exception if we encounter such an element.
 *
 * @throws Exception
 */
@Test(expected = XmlPullParserException.class)
public void invalidMessageBodyContainingTagTest() throws Exception {
  String control = XMLBuilder.create("message")
    .namespace(StreamOpen.CLIENT_NAMESPACE)
    .a("from", "romeo@montague.lit/orchard")
    .a("to", "juliet@capulet.lit/balcony")
    .a("id", "zid615d9")
    .a("type", "chat")
    .a("xml:lang", "en")
    .e("body")
      .a("xmlns", "http://www.w3.org/1999/xhtml")
      .e("span")
        .a("style", "font-weight: bold;")
        .t("Bad Message Body")
    .asString(outputProperties);
  Message message = PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
  fail("Should throw exception. Instead got message: " + message.toXML(null).toString());
}
origin: igniterealtime/Smack

public static XmlPullParser getIQParser(String stanza) {
  return getParser(stanza, "iq");
}
origin: igniterealtime/Smack

    "</x>";
DataForm dataForm = TestUtils.parseExtensionElement(formFieldUsingNamespacePrefix);
origin: igniterealtime/Smack

@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());
}
origin: igniterealtime/Smack

public static XmlPullParser getPresenceParser(String stanza) {
  return getParser(stanza, "presence");
}
origin: igniterealtime/Smack

public static XmlPullParser getParser(String string) {
  return getParser(string, null);
}
origin: igniterealtime/Smack

public static XmlPullParser getParser(String string, String startTag) {
  return getParser(new StringReader(string), startTag);
}
origin: igniterealtime/Smack

  @Test(expected = XmlPullParserException.class)
  public void unknownMoodValueExceptionTest() throws Exception {
    String xml =
        "<mood xmlns='http://jabber.org/protocol/mood'>" +
          "<unknown/>" +
        "</mood>";
    XmlPullParser parser = TestUtils.getParser(xml);
    MoodElement element = MoodProvider.INSTANCE.parse(parser);
  }
}
origin: igniterealtime/Smack

@Test
public void parseContentDepthTest() throws Exception {
  final String stanza = "<iq type='result' to='foo@bar.com' from='baz.com' id='42'/>";
  XmlPullParser parser = TestUtils.getParser(stanza, "iq");
  CharSequence content = PacketParserUtils.parseContent(parser);
  assertEquals("", content.toString());
}
org.jivesoftware.smack.test.utilTestUtils

Most used methods

  • getParser
  • parseExtensionElement
  • getIQParser
  • getMessageParser

Popular in Java

  • Start an intent from android
  • startActivity (Activity)
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • getResourceAsStream (ClassLoader)
    Returns a stream for the resource with the specified name. See #getResource(String) for a descriptio
  • Point (java.awt)
    A point representing a location in (x, y) coordinate space, specified in integer precision.
  • Thread (java.lang)
    A thread is a thread of execution in a program. The Java Virtual Machine allows an application to ha
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Notification (javax.management)
  • JLabel (javax.swing)
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now