2015-01-01 14:56:12 +01:00
|
|
|
/**
|
|
|
|
*
|
2018-03-21 14:47:22 +01:00
|
|
|
* Copyright 2014-2018 Florian Schmaus
|
2015-01-01 14:56:12 +01:00
|
|
|
*
|
|
|
|
* 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.smackx.pubsub.provider;
|
|
|
|
|
2018-03-21 14:47:22 +01:00
|
|
|
import static org.jivesoftware.smack.test.util.CharSequenceEquals.equalsCharSequence;
|
2015-01-01 14:56:12 +01:00
|
|
|
import static org.junit.Assert.assertEquals;
|
2018-03-21 14:47:22 +01:00
|
|
|
import static org.junit.Assert.assertThat;
|
2015-01-01 14:56:12 +01:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.test.util.TestUtils;
|
|
|
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-01-01 14:56:12 +01:00
|
|
|
import org.jivesoftware.smackx.pubsub.PubSubElementType;
|
|
|
|
import org.jivesoftware.smackx.pubsub.Subscription;
|
|
|
|
import org.jivesoftware.smackx.pubsub.SubscriptionsExtension;
|
|
|
|
import org.jivesoftware.smackx.pubsub.packet.PubSub;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2015-01-01 14:56:12 +01:00
|
|
|
import org.junit.Test;
|
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
|
|
|
|
|
|
|
public class PubSubProviderTest {
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void subscriptionsOwnerResultTest() throws Exception {
|
|
|
|
// @formatter:off
|
2018-05-09 23:06:12 +02:00
|
|
|
final String resultStanza =
|
2015-01-01 14:56:12 +01:00
|
|
|
"<iq from='pubsub.example.org' to='julia@example.org/Smack' id='HaT4m-13' type='result'>" +
|
2018-05-09 23:06:12 +02:00
|
|
|
"<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>" +
|
|
|
|
"<subscriptions node='test'>" +
|
2015-01-01 14:56:12 +01:00
|
|
|
"<subscription jid='foo@example.org/Smack' subscription='subscribed' subid='58C1A6F99F2A7'/>" +
|
|
|
|
"<subscription jid='julia@example.org/Smack' subscription='subscribed' subid='58C18F8917321'/>" +
|
|
|
|
"</subscriptions>" +
|
|
|
|
"</pubsub>" +
|
|
|
|
"</iq>";
|
|
|
|
// @formatter:on
|
|
|
|
XmlPullParser parser = TestUtils.getIQParser(resultStanza);
|
2015-01-08 11:01:35 +01:00
|
|
|
PubSub pubsubResult = (PubSub) PacketParserUtils.parseIQ(parser);
|
2018-04-19 11:05:43 +02:00
|
|
|
SubscriptionsExtension subElem = pubsubResult.getExtension(PubSubElementType.SUBSCRIPTIONS_OWNER);
|
2015-01-01 14:56:12 +01:00
|
|
|
List<Subscription> subscriptions = subElem.getSubscriptions();
|
|
|
|
assertEquals(2, subscriptions.size());
|
|
|
|
|
|
|
|
Subscription sub1 = subscriptions.get(0);
|
2018-03-21 14:47:22 +01:00
|
|
|
assertThat("foo@example.org/Smack", equalsCharSequence(sub1.getJid()));
|
2015-01-01 14:56:12 +01:00
|
|
|
assertEquals(Subscription.State.subscribed, sub1.getState());
|
|
|
|
assertEquals("58C1A6F99F2A7", sub1.getId());
|
|
|
|
|
|
|
|
Subscription sub2 = subscriptions.get(1);
|
2018-03-21 14:47:22 +01:00
|
|
|
assertThat("julia@example.org/Smack", equalsCharSequence(sub2.getJid()));
|
2015-01-01 14:56:12 +01:00
|
|
|
assertEquals(Subscription.State.subscribed, sub2.getState());
|
|
|
|
assertEquals("58C18F8917321", sub2.getId());
|
|
|
|
}
|
|
|
|
}
|