mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-10-31 17:25:58 +01:00
Do not check exception message in PacketParserUtilsTest
as it may be localized. This also makes PacketParserUtilsTest to use Junit5. Fixes SMACK-874.
This commit is contained in:
parent
fda9408cf3
commit
658905e1ba
1 changed files with 28 additions and 47 deletions
|
@ -22,15 +22,13 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import javax.xml.parsers.FactoryConfigurationError;
|
import javax.xml.parsers.FactoryConfigurationError;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
@ -50,8 +48,9 @@ import org.jivesoftware.smack.xml.XmlPullParser;
|
||||||
import org.jivesoftware.smack.xml.XmlPullParserException;
|
import org.jivesoftware.smack.xml.XmlPullParserException;
|
||||||
|
|
||||||
import com.jamesmurty.utils.XMLBuilder;
|
import com.jamesmurty.utils.XMLBuilder;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.EnumSource;
|
import org.junit.jupiter.params.provider.EnumSource;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
@ -428,7 +427,7 @@ public class PacketParserUtilsTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Re-enable once we throw an exception on duplicate body elements.
|
// TODO: Re-enable once we throw an exception on duplicate body elements.
|
||||||
@Ignore
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
public void duplicateMessageBodiesTest()
|
public void duplicateMessageBodiesTest()
|
||||||
throws FactoryConfigurationError, XmlPullParserException, IOException, Exception {
|
throws FactoryConfigurationError, XmlPullParserException, IOException, Exception {
|
||||||
|
@ -460,7 +459,7 @@ public class PacketParserUtilsTest {
|
||||||
assertXmlNotSimilar(control, message.toXML().toString());
|
assertXmlNotSimilar(control, message.toXML().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Ignore
|
@Disabled
|
||||||
@Test
|
@Test
|
||||||
public void duplicateMessageBodiesTest2()
|
public void duplicateMessageBodiesTest2()
|
||||||
throws FactoryConfigurationError, XmlPullParserException, IOException, Exception {
|
throws FactoryConfigurationError, XmlPullParserException, IOException, Exception {
|
||||||
|
@ -679,7 +678,7 @@ public class PacketParserUtilsTest {
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
@Test(expected = XmlPullParserException.class)
|
@Test
|
||||||
public void invalidMessageBodyContainingTagTest() throws Exception {
|
public void invalidMessageBodyContainingTagTest() throws Exception {
|
||||||
String control = XMLBuilder.create("message")
|
String control = XMLBuilder.create("message")
|
||||||
.namespace(StreamOpen.CLIENT_NAMESPACE)
|
.namespace(StreamOpen.CLIENT_NAMESPACE)
|
||||||
|
@ -695,14 +694,14 @@ public class PacketParserUtilsTest {
|
||||||
.t("Bad Message Body")
|
.t("Bad Message Body")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
Message message = PacketParserUtils.parseMessage(TestUtils.getMessageParser(control));
|
assertThrows(XmlPullParserException.class, () ->
|
||||||
|
PacketParserUtils.parseMessage(TestUtils.getMessageParser(control))
|
||||||
fail("Should throw exception. Instead got message: " + message.toXML().toString());
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void invalidXMLInMessageBody() throws Exception {
|
public void invalidXMLInMessageBody() throws Exception {
|
||||||
String validControl = XMLBuilder.create("message")
|
final String validControl = XMLBuilder.create("message")
|
||||||
.namespace(StreamOpen.CLIENT_NAMESPACE)
|
.namespace(StreamOpen.CLIENT_NAMESPACE)
|
||||||
.a("from", "romeo@montague.lit/orchard")
|
.a("from", "romeo@montague.lit/orchard")
|
||||||
.a("to", "juliet@capulet.lit/balcony")
|
.a("to", "juliet@capulet.lit/balcony")
|
||||||
|
@ -713,41 +712,20 @@ public class PacketParserUtilsTest {
|
||||||
.t("Good Message Body")
|
.t("Good Message Body")
|
||||||
.asString(outputProperties);
|
.asString(outputProperties);
|
||||||
|
|
||||||
// XPP3 writes "end tag", StAX writes "end-tag".
|
assertThrows(XmlPullParserException.class, () -> {
|
||||||
Supplier<Stream<String>> expectedContentOfExceptionMessage = () -> Stream.of("end tag", "end-tag");
|
|
||||||
|
|
||||||
String invalidControl = validControl.replace("Good Message Body", "Bad </span> Body");
|
String invalidControl = validControl.replace("Good Message Body", "Bad </span> Body");
|
||||||
|
|
||||||
try {
|
|
||||||
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||||
fail("Exception should be thrown");
|
});
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
String exceptionMessage = e.getMessage();
|
|
||||||
boolean expectedContentFound = expectedContentOfExceptionMessage.get().anyMatch((expected) -> exceptionMessage.contains(expected));
|
|
||||||
assertTrue(expectedContentFound);
|
|
||||||
}
|
|
||||||
|
|
||||||
invalidControl = validControl.replace("Good Message Body", "Bad </body> Body");
|
assertThrows(XmlPullParserException.class, () -> {
|
||||||
|
String invalidControl = validControl.replace("Good Message Body", "Bad </body> Body");
|
||||||
try {
|
|
||||||
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||||
fail("Exception should be thrown");
|
});
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
String exceptionMessage = e.getMessage();
|
|
||||||
boolean expectedContentFound = expectedContentOfExceptionMessage.get().anyMatch((expected) -> exceptionMessage.contains(expected));
|
|
||||||
assertTrue(expectedContentFound);
|
|
||||||
}
|
|
||||||
|
|
||||||
invalidControl = validControl.replace("Good Message Body", "Bad </message> Body");
|
assertThrows(XmlPullParserException.class, () -> {
|
||||||
|
String invalidControl = validControl.replace("Good Message Body", "Bad </message> Body");
|
||||||
try {
|
|
||||||
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
PacketParserUtils.parseMessage(PacketParserUtils.getParserFor(invalidControl));
|
||||||
fail("Exception should be thrown");
|
});
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
String exceptionMessage = e.getMessage();
|
|
||||||
boolean expectedContentFound = expectedContentOfExceptionMessage.get().anyMatch((expected) -> exceptionMessage.contains(expected));
|
|
||||||
assertTrue(expectedContentFound);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -891,15 +869,18 @@ public class PacketParserUtilsTest {
|
||||||
return otherLanguage;
|
return otherLanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test
|
||||||
public void descriptiveTextNullLangPassedMap() throws Exception {
|
public void descriptiveTextNullLangPassedMap() throws Exception {
|
||||||
final String text = "Dummy descriptive text";
|
final String text = "Dummy descriptive text";
|
||||||
Map<String, String> texts = new HashMap<>();
|
Map<String, String> texts = new HashMap<>();
|
||||||
texts.put(null, text);
|
texts.put(null, text);
|
||||||
|
|
||||||
|
assertThrows(IllegalArgumentException.class, () ->
|
||||||
StanzaError
|
StanzaError
|
||||||
.getBuilder(StanzaError.Condition.internal_server_error)
|
.getBuilder(StanzaError.Condition.internal_server_error)
|
||||||
.setDescriptiveTexts(texts)
|
.setDescriptiveTexts(texts)
|
||||||
.build();
|
.build()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in a new issue