2016-10-31 17:48:22 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright © 2016 Fernando Ramirez
|
|
|
|
*
|
|
|
|
* 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.push_notifications;
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
2019-05-07 22:58:02 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
2019-10-24 15:45:08 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
2019-05-06 22:06:13 +02:00
|
|
|
|
2016-10-31 17:48:22 +01:00
|
|
|
import org.jivesoftware.smack.packet.Message;
|
|
|
|
import org.jivesoftware.smack.util.PacketParserUtils;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2016-10-31 17:48:22 +01:00
|
|
|
import org.jivesoftware.smackx.push_notifications.element.PushNotificationsElements.RemoteDisablingExtension;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
import org.junit.jupiter.api.Test;
|
2016-10-31 17:48:22 +01:00
|
|
|
import org.jxmpp.jid.impl.JidCreate;
|
|
|
|
|
|
|
|
public class RemoteDisablingPushNotificationsTest {
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final String remoteDisablingExample = "<message from='push-5.client.example' to='user@example.com'>"
|
2016-10-31 17:48:22 +01:00
|
|
|
+ "<pubsub xmlns='http://jabber.org/protocol/pubsub' node='yxs32uqsflafdk3iuqo'>"
|
|
|
|
+ "<affiliation jid='user@example.com' affiliation='none' />" + "</pubsub>" + "</message>";
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final String wrongRemoteDisabling1 = "<message from='push-5.client.example' to='user@example.com'>"
|
2016-10-31 17:48:22 +01:00
|
|
|
+ "<pubsub xmlns='http://jabber.org/protocol/pubsub' node='yxs32uqsflafdk3iuqo'>"
|
|
|
|
+ "<affiliation jid='user@example.com'/>" + "</pubsub>" + "</message>";
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final String wrongRemoteDisabling2 = "<message from='push-5.client.example' to='user@example.com'>"
|
2016-10-31 17:48:22 +01:00
|
|
|
+ "<pubsub xmlns='http://jabber.org/protocol/pubsub' node='yxs32uqsflafdk3iuqo'>"
|
|
|
|
+ "<affiliation jid='user@example.com' affiliation='member' />" + "</pubsub>" + "</message>";
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
private static final String wrongRemoteDisabling3 = "<message from='push-5.client.example' to='user@example.com'>"
|
2016-10-31 17:48:22 +01:00
|
|
|
+ "<pubsub xmlns='http://jabber.org/protocol/pubsub'>" + "</pubsub>" + "</message>";
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkRemoteDisablingPushNotificationsParse() throws Exception {
|
2017-12-13 23:10:11 +01:00
|
|
|
Message message = PacketParserUtils.parseStanza(remoteDisablingExample);
|
2016-10-31 17:48:22 +01:00
|
|
|
RemoteDisablingExtension remoteDisablingExtension = RemoteDisablingExtension.from(message);
|
|
|
|
|
2019-05-06 22:06:13 +02:00
|
|
|
assertEquals("yxs32uqsflafdk3iuqo", remoteDisablingExtension.getNode());
|
|
|
|
assertEquals(JidCreate.from("user@example.com"), remoteDisablingExtension.getUserJid());
|
2016-10-31 17:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void checkWrongRemoteDisablighPushNotifications() throws Exception {
|
2019-10-24 15:45:08 +02:00
|
|
|
assertThrows(IOException.class, () -> PacketParserUtils.parseStanza(wrongRemoteDisabling1));
|
2016-10-31 17:48:22 +01:00
|
|
|
|
2019-10-24 15:45:08 +02:00
|
|
|
assertThrows(IOException.class, () -> PacketParserUtils.parseStanza(wrongRemoteDisabling2));
|
2016-10-31 17:48:22 +01:00
|
|
|
|
2019-05-07 22:58:02 +02:00
|
|
|
Message message3 = PacketParserUtils.parseStanza(wrongRemoteDisabling3);
|
|
|
|
assertNotNull(message3);
|
2016-10-31 17:48:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|