mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Add support for SASL failure 'text' elements
- Also move toString() into TopLevelStreamElement. - Fix SASLFailure toXML xmlnsAttribute(NAMESPACE) - Improve SASLFailure parsing - And introduce XmlUnitUtils
This commit is contained in:
parent
59d3f55003
commit
646a4a6f90
9 changed files with 160 additions and 47 deletions
|
@ -200,12 +200,6 @@ public class PacketCollectorTest
|
|||
setPacketID(String.valueOf(i));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return toXML();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toXML()
|
||||
{
|
||||
|
|
|
@ -21,8 +21,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
|
||||
import org.jivesoftware.smack.test.util.XmlUnitUtils;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
|
@ -150,9 +149,7 @@ public class MessageTest {
|
|||
message.addBody(null, messageBody1);
|
||||
message.addBody(lang2, messageBody2);
|
||||
message.addBody(lang3, messageBody3);
|
||||
Diff xmlDiff = new Diff(control, message.toXML().toString());
|
||||
xmlDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
|
||||
assertTrue(xmlDiff.similar());
|
||||
XmlUnitUtils.assertSimilar(control, message.toXML());
|
||||
|
||||
Collection<String> languages = message.getBodyLanguages();
|
||||
List<String> controlLanguages = new ArrayList<String>();
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2014 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.test.util;
|
||||
|
||||
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
public class XmlUnitUtils {
|
||||
|
||||
public static void assertSimilar(CharSequence expected, CharSequence actual) throws SAXException, IOException {
|
||||
Diff diff = new Diff(expected.toString(), actual.toString());
|
||||
diff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
|
||||
assertXMLEqual(diff, true);
|
||||
}
|
||||
|
||||
}
|
|
@ -32,12 +32,14 @@ import javax.xml.parsers.FactoryConfigurationError;
|
|||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.custommonkey.xmlunit.Diff;
|
||||
import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Packet;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.sasl.SASLError;
|
||||
import org.jivesoftware.smack.sasl.packet.SaslStreamElements;
|
||||
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure;
|
||||
import org.jivesoftware.smack.test.util.TestUtils;
|
||||
import org.jivesoftware.smack.test.util.XmlUnitUtils;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -745,11 +747,9 @@ public class PacketParserUtilsTest {
|
|||
.a("xml:lang", "sp")
|
||||
.t("This is a test of the emergency broadcast system, 3.")
|
||||
.asString(outputProperties);
|
||||
|
||||
|
||||
Packet message = PacketParserUtils.parseStanza(control);
|
||||
Diff xmlDiff = new Diff(control, message.toXML().toString());
|
||||
xmlDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
|
||||
assertTrue(xmlDiff.similar());
|
||||
XmlUnitUtils.assertSimilar(control, message.toXML());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -813,6 +813,41 @@ public class PacketParserUtilsTest {
|
|||
assertXMLEqual(stanza, result.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseSASLFailureSimple() throws FactoryConfigurationError, SAXException, IOException,
|
||||
TransformerException, ParserConfigurationException, XmlPullParserException {
|
||||
// @formatter:off
|
||||
final String saslFailureString = XMLBuilder.create(SASLFailure.ELEMENT, SaslStreamElements.NAMESPACE)
|
||||
.e(SASLError.account_disabled.toString())
|
||||
.asString();
|
||||
// @formatter:on
|
||||
XmlPullParser parser = TestUtils.getParser(saslFailureString, SASLFailure.ELEMENT);
|
||||
SASLFailure saslFailure = PacketParserUtils.parseSASLFailure(parser);
|
||||
assertXMLEqual(saslFailureString, saslFailure.toString());
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
private String determineNonDefaultLanguage() {
|
||||
String otherLanguage = "jp";
|
||||
Locale[] availableLocales = Locale.getAvailableLocales();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue