From fb954173ef19ddaa056af8c8e881d851a47ed8f7 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Sun, 26 Nov 2023 13:06:25 +0100 Subject: [PATCH] [sint] split off low-level tests --- .../LowLevelSubscriptionIntegrationTest.java | 114 ++++++++++++++++++ .../SubscriptionIntegrationTest.java | 73 ----------- 2 files changed, 114 insertions(+), 73 deletions(-) create mode 100644 smack-integration-test/src/main/java/org/jivesoftware/smack/subscription/LowLevelSubscriptionIntegrationTest.java diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smack/subscription/LowLevelSubscriptionIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smack/subscription/LowLevelSubscriptionIntegrationTest.java new file mode 100644 index 0000000000..67ea3d6c6b --- /dev/null +++ b/smack-integration-test/src/main/java/org/jivesoftware/smack/subscription/LowLevelSubscriptionIntegrationTest.java @@ -0,0 +1,114 @@ +/** + * Copyright 2023 Guus der Kinderen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jivesoftware.smack.subscription; + +import org.igniterealtime.smack.inttest.AbstractSmackLowLevelIntegrationTest; +import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment; +import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest; +import org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil; +import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint; +import org.jivesoftware.smack.AbstractXMPPConnection; +import org.jivesoftware.smack.filter.*; +import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.packet.StandardExtensionElement; + +/** + * Integration tests that verify that sent presence subscription requests are received as intended. + * + * @author Guus der Kinderen, guus.der.kinderen@gmail.com + */ +public class LowLevelSubscriptionIntegrationTest extends AbstractSmackLowLevelIntegrationTest +{ + public LowLevelSubscriptionIntegrationTest(SmackIntegrationTestEnvironment environment) { + super(environment); + } + + /** + * This test verifies that a subscription request is received, in a scenario where the intended recipient was + * offline when the request was made. + * + * @throws Exception on anything unexpected or undesired. + */ + @SmackIntegrationTest + public void testSubscriptionRequestOffline(final AbstractXMPPConnection conOne, + final AbstractXMPPConnection conTwo) throws Exception + { + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); + + final Presence subscriptionRequest = conTwo.getStanzaFactory().buildPresenceStanza() + .ofType(Presence.Type.subscribe) + .to(conOne.getUser().asBareJid()) + .build(); + + conOne.disconnect(); + + conTwo.sendStanza(subscriptionRequest); + + conOne.connect(); + + final SimpleResultSyncPoint received = new SimpleResultSyncPoint(); + + final StanzaFilter resultFilter = new AndFilter( + PresenceTypeFilter.SUBSCRIBE, + FromMatchesFilter.createBare(conTwo.getUser()) + ); + + conOne.addAsyncStanzaListener(p -> received.signal(), resultFilter); + + conOne.login(); + received.waitForResult(timeout); + } + + /** + * When a subscription request is made, the stanza can have additional extension elements. This test verifies that + * such extension elements are received, in a scenario where the intended recipient was offline when the request + * was made. + * + * @see Openfire issue OF-2244 + * @throws Exception on anything unexpected or undesired. + */ + @SmackIntegrationTest + public void testSubscriptionRequestOfflineWithExtension(final AbstractXMPPConnection conOne, + final AbstractXMPPConnection conTwo) throws Exception + { + IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); + + final Presence subscriptionRequest = conTwo.getStanzaFactory().buildPresenceStanza() + .ofType(Presence.Type.subscribe) + .to(conOne.getUser().asBareJid()) + .addExtension(new StandardExtensionElement("test", "org.example.test")) + .build(); + + conOne.disconnect(); + + conTwo.sendStanza(subscriptionRequest); + + conOne.connect(); + + final SimpleResultSyncPoint received = new SimpleResultSyncPoint(); + + final StanzaFilter resultFilter = new AndFilter( + PresenceTypeFilter.SUBSCRIBE, + FromMatchesFilter.createBare(conTwo.getUser()), + new StanzaExtensionFilter("test", "org.example.test") + ); + + conOne.addAsyncStanzaListener(p -> received.signal(), resultFilter); + + conOne.login(); + received.waitForResult(timeout); + } +} diff --git a/smack-integration-test/src/main/java/org/jivesoftware/smack/subscription/SubscriptionIntegrationTest.java b/smack-integration-test/src/main/java/org/jivesoftware/smack/subscription/SubscriptionIntegrationTest.java index 7551adbafa..d0373a878c 100644 --- a/smack-integration-test/src/main/java/org/jivesoftware/smack/subscription/SubscriptionIntegrationTest.java +++ b/smack-integration-test/src/main/java/org/jivesoftware/smack/subscription/SubscriptionIntegrationTest.java @@ -16,7 +16,6 @@ */ package org.jivesoftware.smack.subscription; -import org.jivesoftware.smack.AbstractXMPPConnection; import org.jivesoftware.smack.filter.AndFilter; import org.jivesoftware.smack.filter.FromMatchesFilter; import org.jivesoftware.smack.filter.PresenceTypeFilter; @@ -69,40 +68,6 @@ public void testSubscriptionRequest() throws Exception { received.waitForResult(timeout); } - /** - * This test verifies that a subscription request is received, in a scenario where the intended recipient was - * offline when the request was made. - * - * @throws Exception on anything unexpected or undesired. - */ - @SmackIntegrationTest - public void testSubscriptionRequestOffline() throws Exception { - IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); - - ((AbstractXMPPConnection) conOne).disconnect(); - - final Presence subscriptionRequest = conTwo.getStanzaFactory().buildPresenceStanza() - .ofType(Presence.Type.subscribe) - .to(conOne.getUser()) - .build(); - - conTwo.sendStanza(subscriptionRequest); - - ((AbstractXMPPConnection) conOne).connect(); - - final SimpleResultSyncPoint received = new SimpleResultSyncPoint(); - - final StanzaFilter resultFilter = new AndFilter( - PresenceTypeFilter.SUBSCRIBE, - FromMatchesFilter.createBare(conTwo.getUser()) - ); - - conOne.addAsyncStanzaListener(p -> received.signal(), resultFilter); - - ((AbstractXMPPConnection) conOne).login(); - received.waitForResult(timeout); - } - /** * When a subscription request is made, the stanza can have additional extension elements. This test verifies that * such extension elements are received. @@ -132,42 +97,4 @@ public void testSubscriptionRequestWithExtension() throws Exception { conTwo.sendStanza(subscriptionRequest); received.waitForResult(timeout); } - - /** - * When a subscription request is made, the stanza can have additional extension elements. This test verifies that - * such extension elements are received, in a scenario where the intended recipient was offline when the request - * was made. - * - * @see Openfire issue OF-2244 - * @throws Exception on anything unexpected or undesired. - */ - @SmackIntegrationTest - public void testSubscriptionRequestOfflineWithExtension() throws Exception { - IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); - - ((AbstractXMPPConnection) conOne).disconnect(); - - final Presence subscriptionRequest = conTwo.getStanzaFactory().buildPresenceStanza() - .ofType(Presence.Type.subscribe) - .to(conOne.getUser()) - .addExtension(new StandardExtensionElement("test", "org.example.test")) - .build(); - - conTwo.sendStanza(subscriptionRequest); - - ((AbstractXMPPConnection) conOne).connect(); - - final SimpleResultSyncPoint received = new SimpleResultSyncPoint(); - - final StanzaFilter resultFilter = new AndFilter( - PresenceTypeFilter.SUBSCRIBE, - FromMatchesFilter.createBare(conTwo.getUser()), - new StanzaExtensionFilter("test", "org.example.test") - ); - - conOne.addAsyncStanzaListener(p -> received.signal(), resultFilter); - - ((AbstractXMPPConnection) conOne).login(); - received.waitForResult(timeout); - } }