mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 14:22:05 +01:00
Improve PubSubIntegrationTest
Ensuring that the node has no items in transientNotificationOnlyNodeWithoutItemTest() is not right. An implementation is free to create an item with an ID and return it. The item is just not guaranteed to be persistent. Also add a dummy payload to transientNotificationOnlyNodeWithItemTest().
This commit is contained in:
parent
df5899e72b
commit
aec648c34b
2 changed files with 22 additions and 11 deletions
|
@ -23,6 +23,8 @@ dependencies {
|
||||||
// (ab)uses @Before from org.junit
|
// (ab)uses @Before from org.junit
|
||||||
compile "org.junit.vintage:junit-vintage-engine:$junitVersion"
|
compile "org.junit.vintage:junit-vintage-engine:$junitVersion"
|
||||||
compile 'junit:junit:4.12'
|
compile 'junit:junit:4.12'
|
||||||
|
// Add Junit 5 API for e.g. assertThrows()
|
||||||
|
implementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||||||
testCompile "org.jxmpp:jxmpp-jid:$jxmppVersion:tests"
|
testCompile "org.jxmpp:jxmpp-jid:$jxmppVersion:tests"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,14 +18,13 @@ package org.jivesoftware.smackx.pubsub;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackConfiguration;
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
import org.jivesoftware.smack.XMPPException.XMPPErrorException;
|
||||||
|
import org.jivesoftware.smack.packet.StandardExtensionElement;
|
||||||
import org.jivesoftware.smack.packet.StanzaError;
|
import org.jivesoftware.smack.packet.StanzaError;
|
||||||
|
|
||||||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
||||||
|
@ -69,8 +68,6 @@ public class PubSubIntegrationTest extends AbstractSmackIntegrationTest {
|
||||||
try {
|
try {
|
||||||
LeafNode leafNode = (LeafNode) node;
|
LeafNode leafNode = (LeafNode) node;
|
||||||
leafNode.publish();
|
leafNode.publish();
|
||||||
List<Item> items = leafNode.getItems();
|
|
||||||
assertTrue(items.isEmpty());
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
pubSubManagerOne.deleteNode(nodename);
|
pubSubManagerOne.deleteNode(nodename);
|
||||||
|
@ -95,6 +92,7 @@ public class PubSubIntegrationTest extends AbstractSmackIntegrationTest {
|
||||||
public void transientNotificationOnlyNodeWithItemTest() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
public void transientNotificationOnlyNodeWithItemTest() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
|
||||||
final String nodename = "sinttest-transient-notificationonly-withitem-nodename-" + testRunId;
|
final String nodename = "sinttest-transient-notificationonly-withitem-nodename-" + testRunId;
|
||||||
final String itemId = "sinttest-transient-notificationonly-withitem-itemid-" + testRunId;
|
final String itemId = "sinttest-transient-notificationonly-withitem-itemid-" + testRunId;
|
||||||
|
|
||||||
ConfigureForm defaultConfiguration = pubSubManagerOne.getDefaultConfiguration();
|
ConfigureForm defaultConfiguration = pubSubManagerOne.getDefaultConfiguration();
|
||||||
ConfigureForm config = new ConfigureForm(defaultConfiguration.createAnswerForm());
|
ConfigureForm config = new ConfigureForm(defaultConfiguration.createAnswerForm());
|
||||||
// Configure the node as "Notification-Only Node".
|
// Configure the node as "Notification-Only Node".
|
||||||
|
@ -102,12 +100,23 @@ public class PubSubIntegrationTest extends AbstractSmackIntegrationTest {
|
||||||
// Configure the node as "transient" (set persistent_items to 'false')
|
// Configure the node as "transient" (set persistent_items to 'false')
|
||||||
config.setPersistentItems(false);
|
config.setPersistentItems(false);
|
||||||
Node node = pubSubManagerOne.createNode(nodename, config);
|
Node node = pubSubManagerOne.createNode(nodename, config);
|
||||||
|
|
||||||
|
// Add a dummy payload. If there is no payload, but just an item ID, then ejabberd will *not* return an error,
|
||||||
|
// which I believe to be non-compliant behavior (although, granted, the XEP is not very clear about this). A user
|
||||||
|
// which sends an empty item with ID to an node that is configured to be notification-only and transient probably
|
||||||
|
// does something wrong, as the item's ID will never appear anywhere. Hence it would be nice if the user would be
|
||||||
|
// made aware of this issue by returning an error. Sadly ejabberd does not do so.
|
||||||
|
// See also https://github.com/processone/ejabberd/issues/2864#issuecomment-500741915
|
||||||
|
final StandardExtensionElement dummyPayload = StandardExtensionElement.builder("dummy-payload",
|
||||||
|
SmackConfiguration.SMACK_URL_STRING).setText(testRunId).build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
XMPPErrorException e = assertThrows(XMPPErrorException.class, () -> {
|
||||||
LeafNode leafNode = (LeafNode) node;
|
LeafNode leafNode = (LeafNode) node;
|
||||||
leafNode.publish(new Item(itemId));
|
|
||||||
fail("An exception should have been thrown.");
|
Item item = new PayloadItem<>(itemId, dummyPayload);
|
||||||
}
|
leafNode.publish(item);
|
||||||
catch (XMPPErrorException e) {
|
});
|
||||||
assertEquals(StanzaError.Type.MODIFY, e.getStanzaError().getType());
|
assertEquals(StanzaError.Type.MODIFY, e.getStanzaError().getType());
|
||||||
assertNotNull(e.getStanzaError().getExtension("item-forbidden", "http://jabber.org/protocol/pubsub#errors"));
|
assertNotNull(e.getStanzaError().getExtension("item-forbidden", "http://jabber.org/protocol/pubsub#errors"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue