public static void assertSimilar(CharSequence expected, CharSequence actual) throws SAXException, IOException { assertXmlSimilar(expected, actual); }
message.addBody(lang2, messageBody2); message.addBody(lang3, messageBody3); XmlUnitUtils.assertSimilar(control, message.toXML(StreamOpen.CLIENT_NAMESPACE));
@Test public void checkAddAdditionalFieldsStanza() throws Exception { FormField field1 = new FormField("urn:example:xmpp:free-text-search"); field1.setType(FormField.Type.text_single); field1.addValue("Hi"); FormField field2 = new FormField("urn:example:xmpp:stanza-content"); field2.setType(FormField.Type.jid_single); field2.addValue("Hi2"); MamQueryArgs mamQueryArgs = MamQueryArgs.builder() .withAdditionalFormField(field1) .withAdditionalFormField(field2) .build(); DataForm dataForm = mamQueryArgs.getDataForm(); String dataFormResult = dataForm.toXML(null).toString(); assertXmlSimilar(additionalFieldsStanza, dataFormResult); }
@Test public void ensureNoEmptyLangInDescriptiveText() throws Exception { final String text = "Dummy descriptive text"; Map<String, String> texts = new HashMap<>(); texts.put("", text); StanzaError error = StanzaError .getBuilder(StanzaError.Condition.internal_server_error) .setDescriptiveTexts(texts) .build(); final String errorXml = XMLBuilder .create(StanzaError.ERROR).a("type", "cancel").up() .element("internal-server-error", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).up() .element("text", StanzaError.ERROR_CONDITION_AND_TEXT_NAMESPACE).t(text).up() .asString(); XmlUnitUtils.assertSimilar(errorXml, error.toXML(StreamOpen.CLIENT_NAMESPACE)); }
@Test public void parseSASLFailureExtended() throws FactoryConfigurationError, TransformerException, ParserConfigurationException, XmlPullParserException, IOException, SAXException { // @formatter:off final String saslFailureString = XMLBuilder.create(SASLFailure.ELEMENT, SaslStreamElements.NAMESPACE) .e(SASLError.account_disabled.toString()) .up() .e("text").a("xml:lang", "en") .t("Call 212-555-1212 for assistance.") .up() .e("text").a("xml:lang", "de") .t("Bitte wenden sie sich an (04321) 123-4444") .up() .e("text") .t("Wusel dusel") .asString(); // @formatter:on XmlPullParser parser = TestUtils.getParser(saslFailureString, SASLFailure.ELEMENT); SASLFailure saslFailure = PacketParserUtils.parseSASLFailure(parser); XmlUnitUtils.assertSimilar(saslFailureString, saslFailure.toXML(StreamOpen.CLIENT_NAMESPACE)); }
@Test public void multipleMessageBodiesParsingTest() 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") // TODO: Remove the following xml:lang once Smack's serialization toXml() API is aware of a potential // scoping xml:lang value. The out message stanza already declares an xml:lang with the exact same // value, hence this statement is redundant. .a("xml:lang", "en") .t("This is a test of the emergency broadcast system, 1.") .up() .e("body") .a("xml:lang", "ru") .t("This is a test of the emergency broadcast system, 2.") .up() .e("body") .a("xml:lang", "sp") .t("This is a test of the emergency broadcast system, 3.") .asString(outputProperties); Stanza message = PacketParserUtils.parseStanza(control); XmlUnitUtils.assertSimilar(control, message.toXML(null)); }