1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00

Replace XPP3 by XmlPullParser interface wrapping StAX and XPP3

Introducing Smack's own XmlPullParser interface which tries to stay as
compatible as possible to XPP3. The interface is used to either wrap
StAX's XMLStreamReader if Smack is used on Java SE, and XPP3's
XmlPullParser if Smack is used on on Android.

Fixes SMACK-591.

Also introduce JUnit 5 and non-strict javadoc projects.
This commit is contained in:
Florian Schmaus 2019-05-06 22:06:13 +02:00
parent b3646abecd
commit 4133eb175c
414 changed files with 3855 additions and 2041 deletions

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2014 Vyacheslav Blinov, 2017-2018 Florian Schmaus
* Copyright 2014 Vyacheslav Blinov, 2017-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,12 +16,9 @@
*/
package org.jivesoftware.smack.sm.provider;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.util.List;
@ -31,11 +28,11 @@ import org.jivesoftware.smack.packet.StanzaError;
import org.jivesoftware.smack.packet.StanzaErrorTextElement;
import org.jivesoftware.smack.sm.packet.StreamManagement;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smack.xml.XmlPullParserException;
import com.jamesmurty.utils.XMLBuilder;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.junit.jupiter.api.Test;
public class ParseStreamManagementTest {
private static final Properties outputProperties = initOutputProperties();
@ -58,11 +55,11 @@ public class ParseStreamManagementTest {
StreamManagement.Enabled enabledPacket = ParseStreamManagement.enabled(
PacketParserUtils.getParserFor(enabledStanza));
assertThat(enabledPacket, is(notNullValue()));
assertThat(enabledPacket.getId(), equalTo(stanzaID));
assertThat(enabledPacket.getLocation(), equalTo(location));
assertThat(enabledPacket.isResumeSet(), equalTo(resume));
assertThat(enabledPacket.getMaxResumptionTime(), equalTo(max));
assertNotNull(enabledPacket);
assertEquals(enabledPacket.getId(), stanzaID);
assertEquals(location, enabledPacket.getLocation());
assertEquals(resume, enabledPacket.isResumeSet());
assertEquals(max, enabledPacket.getMaxResumptionTime());
}
@ -84,7 +81,7 @@ public class ParseStreamManagementTest {
StreamManagement.Failed failedPacket = ParseStreamManagement.failed(
PacketParserUtils.getParserFor(failedStanza));
assertThat(failedPacket, is(notNullValue()));
assertNotNull(failedPacket);
assertTrue(failedPacket.getStanzaErrorCondition() == null);
}
@ -100,7 +97,7 @@ public class ParseStreamManagementTest {
StreamManagement.Failed failedPacket = ParseStreamManagement.failed(
PacketParserUtils.getParserFor(failedStanza));
assertThat(failedPacket, is(notNullValue()));
assertNotNull(failedPacket);
assertTrue(failedPacket.getStanzaErrorCondition() == errorCondition);
}
@ -142,9 +139,9 @@ public class ParseStreamManagementTest {
StreamManagement.Resumed resumedPacket = ParseStreamManagement.resumed(
PacketParserUtils.getParserFor(resumedStanza));
assertThat(resumedPacket, is(notNullValue()));
assertThat(resumedPacket.getHandledCount(), equalTo(handledPackets));
assertThat(resumedPacket.getPrevId(), equalTo(previousID));
assertNotNull(resumedPacket);
assertEquals(handledPackets, resumedPacket.getHandledCount());
assertEquals(previousID, resumedPacket.getPrevId());
}
@Test
@ -159,8 +156,8 @@ public class ParseStreamManagementTest {
StreamManagement.AckAnswer acknowledgementPacket = ParseStreamManagement.ackAnswer(
PacketParserUtils.getParserFor(ackStanza));
assertThat(acknowledgementPacket, is(notNullValue()));
assertThat(acknowledgementPacket.getHandledCount(), equalTo(handledPackets));
assertNotNull(acknowledgementPacket);
assertEquals(handledPackets, acknowledgementPacket.getHandledCount());
}
private static Properties initOutputProperties() {

View file

@ -16,24 +16,31 @@
*/
package org.jivesoftware.smack.tcp;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.lang.reflect.Field;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.atomic.AtomicReference;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.SmackException.NotConnectedException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.tcp.XMPPTCPConnection.PacketWriter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.jxmpp.stringprep.XmppStringprepException;
public class PacketWriterTest {
private static final Reader DUMMY_READER = new StringReader("");
private volatile boolean shutdown;
private volatile boolean prematureUnblocked;
@ -47,10 +54,22 @@ public class PacketWriterTest {
* @throws BrokenBarrierException
* @throws NotConnectedException
* @throws XmppStringprepException
* @throws SecurityException
* @throws NoSuchFieldException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*/
@Test
public void shouldBlockAndUnblockTest() throws InterruptedException, BrokenBarrierException, NotConnectedException, XmppStringprepException {
public void shouldBlockAndUnblockTest() throws InterruptedException, BrokenBarrierException, NotConnectedException, XmppStringprepException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
XMPPTCPConnection connection = new XMPPTCPConnection("user", "pass", "example.org");
// Get the protected "Reader reader" field from AbstractXMPPConnection and set it to a dummy Reader,
// as otherwise it will be null when we perform the writer threads init() which will make the StAX parser
// to throw an exception.
Field readerField = AbstractXMPPConnection.class.getDeclaredField("reader");
readerField.setAccessible(true);
readerField.set(connection, DUMMY_READER);
final PacketWriter pw = connection.packetWriter;
BlockingStringWriter blockingStringWriter = new BlockingStringWriter();
connection.setWriter(blockingStringWriter);
@ -85,6 +104,7 @@ public class PacketWriterTest {
}
catch (BrokenBarrierException | InterruptedException e) {
unexpectedThreadExceptionReference.set(e);
}
try {
@ -126,7 +146,7 @@ public class PacketWriterTest {
fail("Unexpected thread exception: " + unexpectedThreadException);
}
assertNotNull("Did not encounter expected exception on sendStreamElement()", expectedThreadExceptionReference.get());
assertNotNull(expectedThreadExceptionReference.get(), "Did not encounter expected exception on sendStreamElement()");
}
finally {
blockingStringWriter.unblock();

View file

@ -16,11 +16,11 @@
*/
package org.jivesoftware.smack.tcp;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class TcpInitializerTest {