-
Notifications
You must be signed in to change notification settings - Fork 887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sint] new presence subscription tests #481
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
...rc/main/java/org/jivesoftware/smack/subscription/LowLevelSubscriptionIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/** | ||
* | ||
* 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.jivesoftware.smack.AbstractXMPPConnection; | ||
import org.jivesoftware.smack.filter.AndFilter; | ||
import org.jivesoftware.smack.filter.FromMatchesFilter; | ||
import org.jivesoftware.smack.filter.PresenceTypeFilter; | ||
import org.jivesoftware.smack.filter.StanzaExtensionFilter; | ||
import org.jivesoftware.smack.filter.StanzaFilter; | ||
import org.jivesoftware.smack.packet.Presence; | ||
import org.jivesoftware.smack.packet.StandardExtensionElement; | ||
|
||
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; | ||
|
||
/** | ||
* Integration tests that verify that sent presence subscription requests are received as intended. | ||
* | ||
* @author Guus der Kinderen, [email protected] | ||
*/ | ||
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. | ||
* | ||
* @param conOne Connection used to receive subscription request. | ||
* @param conTwo Conenction used to send subscription request. | ||
* @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. | ||
* | ||
* @param conOne Connection used to receive subscription request. | ||
* @param conTwo Conenction used to send subscription request. | ||
* @see <a href="https://igniterealtime.atlassian.net/browse/OF-2244">Openfire issue OF-2244</a> | ||
* @throws Exception on anything unexpected or undesired. | ||
*/ | ||
@SmackIntegrationTest | ||
public void testSubscriptionRequestOfflineWithExtension(final AbstractXMPPConnection conOne, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dito |
||
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); | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
...n-test/src/main/java/org/jivesoftware/smack/subscription/SubscriptionIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** | ||
* | ||
* Copyright 2021-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.jivesoftware.smack.filter.AndFilter; | ||
import org.jivesoftware.smack.filter.FromMatchesFilter; | ||
import org.jivesoftware.smack.filter.PresenceTypeFilter; | ||
import org.jivesoftware.smack.filter.StanzaExtensionFilter; | ||
import org.jivesoftware.smack.filter.StanzaFilter; | ||
import org.jivesoftware.smack.packet.Presence; | ||
import org.jivesoftware.smack.packet.StandardExtensionElement; | ||
|
||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest; | ||
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; | ||
|
||
/** | ||
* Integration tests that verify that sent presence subscription requests are received as intended. | ||
* | ||
* @author Guus der Kinderen, [email protected] | ||
*/ | ||
public class SubscriptionIntegrationTest extends AbstractSmackIntegrationTest { | ||
|
||
public SubscriptionIntegrationTest(SmackIntegrationTestEnvironment environment) { | ||
super(environment); | ||
} | ||
|
||
/** | ||
* This test verifies that a subscription request is received. | ||
* | ||
* @throws Exception on anything unexpected or undesired. | ||
*/ | ||
@SmackIntegrationTest | ||
public void testSubscriptionRequest() throws Exception { | ||
IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); | ||
|
||
final Presence subscriptionRequest = conTwo.getStanzaFactory().buildPresenceStanza() | ||
.ofType(Presence.Type.subscribe) | ||
.to(conOne.getUser()) | ||
.build(); | ||
|
||
final SimpleResultSyncPoint received = new SimpleResultSyncPoint(); | ||
|
||
final StanzaFilter resultFilter = new AndFilter( | ||
PresenceTypeFilter.SUBSCRIBE, | ||
FromMatchesFilter.createBare(conTwo.getUser()) | ||
); | ||
|
||
conOne.addAsyncStanzaListener(p -> received.signal(), resultFilter); | ||
|
||
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. | ||
* | ||
* @throws Exception on anything unexpected or undesired. | ||
*/ | ||
@SmackIntegrationTest | ||
public void testSubscriptionRequestWithExtension() throws Exception { | ||
IntegrationTestRosterUtil.ensureBothAccountsAreNotInEachOthersRoster(conOne, conTwo); | ||
|
||
final Presence subscriptionRequest = conTwo.getStanzaFactory().buildPresenceStanza() | ||
.ofType(Presence.Type.subscribe) | ||
.to(conOne.getUser()) | ||
.addExtension(new StandardExtensionElement("test", "org.example.test")) | ||
.build(); | ||
|
||
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); | ||
|
||
conTwo.sendStanza(subscriptionRequest); | ||
received.waitForResult(timeout); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
smack-integration-test/src/main/java/org/jivesoftware/smack/subscription/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* | ||
* Copyright 2021 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. | ||
*/ | ||
|
||
/** | ||
* Integration Tests for presence subscription exchange. | ||
*/ | ||
package org.jivesoftware.smack.subscription; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct me if I am wrong (for this and all potential following statements), but this seems to test primarily a server functionality (i.e., that a presence subscription test send while the recipient is offline, is delivered once the recipient comes online).
As such, it is probably not a good fit for Smack and instead for smack-sinttest-server-extensions