mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 01:29:38 +02:00
Get descriptive text from error without lang
A stanza with <error><text>Some text</text></error>, i.e. without a xml:lang attribute, did not return the value 'Some text' in getDescriptiveText(). Insert the empty string as key when the attribute is not present while parsing the xml. When writing, omit the attribute if the key is the empty string.
This commit is contained in:
parent
1d943aed20
commit
699145ee5f
4 changed files with 63 additions and 2 deletions
|
@ -25,7 +25,9 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.xml.parsers.FactoryConfigurationError;
|
||||
|
@ -35,6 +37,7 @@ import javax.xml.transform.TransformerException;
|
|||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Presence;
|
||||
import org.jivesoftware.smack.packet.Stanza;
|
||||
import org.jivesoftware.smack.packet.XMPPError;
|
||||
import org.jivesoftware.smack.sasl.SASLError;
|
||||
import org.jivesoftware.smack.sasl.packet.SaslStreamElements;
|
||||
import org.jivesoftware.smack.sasl.packet.SaslStreamElements.SASLFailure;
|
||||
|
@ -867,4 +870,44 @@ public class PacketParserUtilsTest {
|
|||
return otherLanguage;
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void descriptiveTextNullLangPassedMap() throws Exception {
|
||||
final String text = "Dummy descriptive text";
|
||||
Map<String, String> texts = new HashMap<>();
|
||||
texts.put(null, text);
|
||||
XMPPError
|
||||
.getBuilder(XMPPError.Condition.internal_server_error)
|
||||
.setDescriptiveTexts(texts)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureNoEmptyLangInDescriptiveText() throws Exception {
|
||||
final String text = "Dummy descriptive text";
|
||||
Map<String, String> texts = new HashMap<>();
|
||||
texts.put("", text);
|
||||
XMPPError error = XMPPError
|
||||
.getBuilder(XMPPError.Condition.internal_server_error)
|
||||
.setDescriptiveTexts(texts)
|
||||
.build();
|
||||
final String errorXml = XMLBuilder
|
||||
.create(XMPPError.ERROR).a("type", "cancel").up()
|
||||
.element("internal-server-error", XMPPError.NAMESPACE).up()
|
||||
.element("text", XMPPError.NAMESPACE).t(text).up()
|
||||
.asString();
|
||||
XmlUnitUtils.assertSimilar(errorXml, error.toXML());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ensureNoNullLangInParsedDescriptiveTexts() throws Exception {
|
||||
final String text = "Dummy descriptive text";
|
||||
final String errorXml = XMLBuilder
|
||||
.create(XMPPError.ERROR).a("type", "cancel").up()
|
||||
.element("internal-server-error", XMPPError.NAMESPACE).up()
|
||||
.element("text", XMPPError.NAMESPACE).t(text).up()
|
||||
.asString();
|
||||
XmlPullParser parser = TestUtils.getParser(errorXml);
|
||||
XMPPError error = PacketParserUtils.parseError(parser).build();
|
||||
assertEquals(text, error.getDescriptiveText());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue