mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-08 12:01:09 +01:00
Add support for XEP-0333: Chat Markers
Fixes SMACK-736
This commit is contained in:
parent
5372c1bcf4
commit
6d74d0383c
15 changed files with 795 additions and 0 deletions
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
*
|
||||
* 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.chat_markers;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.AcknowledgedExtension;
|
||||
import org.jivesoftware.smackx.chat_markers.provider.AcknowledgedProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class AcknowledgedExtensionTest {
|
||||
|
||||
String acknowledgedMessageStanza = "<message to='northumberland@shakespeare.lit/westminster' id='message-2'>"
|
||||
+ "<acknowledged xmlns='urn:xmpp:chat-markers:0' id='message-1'/>" + "</message>";
|
||||
|
||||
String acknowledgedExtension = "<acknowledged xmlns='urn:xmpp:chat-markers:0' id='message-1'/>";
|
||||
|
||||
@Test
|
||||
public void checkDisplayedExtension() throws Exception {
|
||||
Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster"));
|
||||
message.setStanzaId("message-2");
|
||||
message.addExtension(new ChatMarkersElements.AcknowledgedExtension("message-1"));
|
||||
Assert.assertEquals(acknowledgedMessageStanza, message.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkDisplayedProvider() throws Exception {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(acknowledgedExtension);
|
||||
AcknowledgedExtension acknowledgedExtension1 = new AcknowledgedProvider().parse(parser);
|
||||
Assert.assertEquals("message-1", acknowledgedExtension1.getId());
|
||||
|
||||
Message message = (Message) PacketParserUtils.parseStanza(acknowledgedMessageStanza);
|
||||
AcknowledgedExtension acknowledgedExtension2 = AcknowledgedExtension.from(message);
|
||||
Assert.assertEquals("message-1", acknowledgedExtension2.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
*
|
||||
* 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.chat_markers;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.DisplayedExtension;
|
||||
import org.jivesoftware.smackx.chat_markers.provider.DisplayedProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class DisplayedExtensionTest {
|
||||
|
||||
String displayedMessageStanza = "<message to='northumberland@shakespeare.lit/westminster' id='message-2'>"
|
||||
+ "<displayed xmlns='urn:xmpp:chat-markers:0' id='message-1'/>" + "</message>";
|
||||
|
||||
String displayedExtension = "<displayed xmlns='urn:xmpp:chat-markers:0' id='message-1'/>";
|
||||
|
||||
@Test
|
||||
public void checkDisplayedExtension() throws Exception {
|
||||
Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster"));
|
||||
message.setStanzaId("message-2");
|
||||
message.addExtension(new ChatMarkersElements.DisplayedExtension("message-1"));
|
||||
Assert.assertEquals(displayedMessageStanza, message.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkDisplayedProvider() throws Exception {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(displayedExtension);
|
||||
DisplayedExtension displayedExtension1 = new DisplayedProvider().parse(parser);
|
||||
Assert.assertEquals("message-1", displayedExtension1.getId());
|
||||
|
||||
Message message = (Message) PacketParserUtils.parseStanza(displayedMessageStanza);
|
||||
DisplayedExtension displayedExtension2 = DisplayedExtension.from(message);
|
||||
Assert.assertEquals("message-1", displayedExtension2.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* 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.chat_markers;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.MarkableExtension;
|
||||
import org.jivesoftware.smackx.chat_markers.provider.MarkableProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class MarkableExtensionTest {
|
||||
|
||||
String markableMessageStanza = "<message to='ingrichard@royalty.england.lit/throne' id='message-1'>"
|
||||
+ "<body>My lord, dispatch; read o'er these articles.</body>"
|
||||
+ "<markable xmlns='urn:xmpp:chat-markers:0'/>" + "</message>";
|
||||
|
||||
String markableExtension = "<markable xmlns='urn:xmpp:chat-markers:0'/>";
|
||||
|
||||
@Test
|
||||
public void checkMarkableExtension() throws Exception {
|
||||
Message message = new Message(JidCreate.from("ingrichard@royalty.england.lit/throne"));
|
||||
message.setStanzaId("message-1");
|
||||
message.setBody("My lord, dispatch; read o'er these articles.");
|
||||
message.addExtension(new ChatMarkersElements.MarkableExtension());
|
||||
Assert.assertEquals(markableMessageStanza, message.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkMarkableProvider() throws Exception {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(markableExtension);
|
||||
MarkableExtension markableExtension1 = new MarkableProvider().parse(parser);
|
||||
Assert.assertEquals(markableExtension, markableExtension1.toXML().toString());
|
||||
|
||||
Message message = (Message) PacketParserUtils.parseStanza(markableMessageStanza);
|
||||
MarkableExtension markableExtension2 = MarkableExtension.from(message);
|
||||
Assert.assertEquals(markableExtension, markableExtension2.toXML().toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/**
|
||||
*
|
||||
* 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.chat_markers;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements;
|
||||
import org.jivesoftware.smackx.chat_markers.element.ChatMarkersElements.ReceivedExtension;
|
||||
import org.jivesoftware.smackx.chat_markers.provider.ReceivedProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class ReceivedExtensionTest {
|
||||
|
||||
String receivedMessageStanza = "<message to='northumberland@shakespeare.lit/westminster' id='message-2'>"
|
||||
+ "<received xmlns='urn:xmpp:chat-markers:0' id='message-1'/>" + "</message>";
|
||||
|
||||
String receivedExtension = "<received xmlns='urn:xmpp:chat-markers:0' id='message-1'/>";
|
||||
|
||||
@Test
|
||||
public void checkReceivedExtension() throws Exception {
|
||||
Message message = new Message(JidCreate.from("northumberland@shakespeare.lit/westminster"));
|
||||
message.setStanzaId("message-2");
|
||||
message.addExtension(new ChatMarkersElements.ReceivedExtension("message-1"));
|
||||
Assert.assertEquals(receivedMessageStanza, message.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkReceivedProvider() throws Exception {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(receivedExtension);
|
||||
ReceivedExtension receivedExtension1 = new ReceivedProvider().parse(parser);
|
||||
Assert.assertEquals("message-1", receivedExtension1.getId());
|
||||
|
||||
Message message = (Message) PacketParserUtils.parseStanza(receivedMessageStanza);
|
||||
ReceivedExtension receivedExtension2 = ReceivedExtension.from(message);
|
||||
Assert.assertEquals("message-1", receivedExtension2.getId());
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue