From 8e2e555c4f23269dc70cdcc258be201dec8f42ee Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Fri, 15 May 2020 11:58:02 +0200 Subject: [PATCH] Additional Pubsub integration tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For XEP-0060 § 8.4.1: Assert that the server send a notification to subscribers when deleting a node that exists. --- .../smackx/pubsub/PubSubIntegrationTest.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smackx/pubsub/PubSubIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smackx/pubsub/PubSubIntegrationTest.java index 03cb5ebe8..5cf148c2f 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smackx/pubsub/PubSubIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smackx/pubsub/PubSubIntegrationTest.java @@ -945,4 +945,48 @@ public class PubSubIntegrationTest extends AbstractSmackIntegrationTest { // Delete an non existent node assertFalse( pubSubManagerOne.deleteNode(nodename), "The server should have returned a error, but did not." ); } + + /** + * Assert that the server send a notification to subscribers when deleting a + * node that exist + * + *

+ * From XEP-0060 § 8.4.1: + *

+ *
In order to delete a node, a node owner MUST send a node + * deletion request, consisting of a <delete/> element whose 'node' + * attribute specifies the NodeID of the node to be deleted
+ * + * @throws NoResponseException if there was no response from + * the remote entity. + * @throws NotConnectedException if the XMPP connection is not + * connected. + * @throws InterruptedException if the calling thread was + * interrupted. + * @throws PubSubException.NotAPubSubNodeException if the node cannot be + * accessed. + */ + @SmackIntegrationTest + public void deleteNodeAndNotifySubscribersTest() throws NoResponseException, ExecutionException, + NotConnectedException, InterruptedException, PubSubException.NotAPubSubNodeException { + final String nodename = "sinttest-delete-node-that-exist-" + testRunId; + final String needle = ""; + try { + LeafNode node = pubSubManagerOne.createNode(nodename); + final Node subscriberNode = pubSubManagerTwo.getNode(nodename); + final EntityBareJid subscriber = conTwo.getUser().asEntityBareJid(); + subscriberNode.subscribe(subscriber); + final CompletableFuture result = new CompletableFuture<>(); + conTwo.addAsyncStanzaListener(result::complete, stanza -> stanza.toXML("").toString().contains(needle)); + + // Delete an existent node + pubSubManagerOne.deleteNode(nodename); + + assertNotNull(result.get(conOne.getReplyTimeout(), TimeUnit.MILLISECONDS)); + } catch (XMPPErrorException e) { + assertEquals(StanzaError.Condition.item_not_found, e.getStanzaError().getCondition()); + } catch (TimeoutException e) { + throw new AssertionError("The expected delete notification was not received by the subscriber.", e); + } + } }