diff options
author | Vitaly Takmazov | 2017-09-15 03:19:29 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-09-15 03:25:35 +0300 |
commit | 763e71486aa51900de47a20fbbe2c5b0bf6193c5 (patch) | |
tree | 5228aa01025365df84e0564240abb6adfb0f55be /juick-core/src/test | |
parent | 49daea46cd6a56680a316996f37f9e1036d4f727 (diff) |
core: fix tags deserialization
Diffstat (limited to 'juick-core/src/test')
-rw-r--r-- | juick-core/src/test/java/com/juick/MessageTest.java | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/juick-core/src/test/java/com/juick/MessageTest.java b/juick-core/src/test/java/com/juick/MessageTest.java index f313935e..b420edfa 100644 --- a/juick-core/src/test/java/com/juick/MessageTest.java +++ b/juick-core/src/test/java/com/juick/MessageTest.java @@ -20,6 +20,15 @@ package com.juick; import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Test; +import rocks.xmpp.addr.Jid; +import rocks.xmpp.core.XmppException; +import rocks.xmpp.core.session.Extension; +import rocks.xmpp.core.session.XmppSession; +import rocks.xmpp.core.session.XmppSessionConfiguration; + +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.StringReader; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; @@ -180,4 +189,29 @@ public class MessageTest { assertThat(StringUtils.countMatches(message.getTagsString(), "*test"), equalTo(1)); assertThat(StringUtils.countMatches(message.getTagsString(), "*ab"), equalTo(1)); } + @Test + public void tagsShouldBeDeserializedFromXml() throws JAXBException { + XmppSessionConfiguration configuration = XmppSessionConfiguration.builder() + .extensions(Extension.of(com.juick.Message.class)) + .build(); + XmppSession xmpp = new XmppSession("juick.com", configuration) { + @Override + public void connect(Jid from) throws XmppException { + + } + + @Override + public Jid getConnectedResource() { + return null; + } + }; + String tag = "<tag xmlns='http://juick.com/message'>yo</tag>"; + String xml = "<message xmlns='jabber:client' from='juick@juick.com' type='chat'><body>yo</body><juick mid='1' ts='2017-09-14' uid='1' uname='ugnich' xmlns='http://juick.com/message'><body>yo</body><user uid='1' uname='ugnich' xmlns='http://juick.com/user'/><tag>yo</tag><tag>people</tag></juick></message>"; + Unmarshaller unmarshaller = xmpp.createUnmarshaller(); + rocks.xmpp.core.stanza.model.Message xmppMessage = (rocks.xmpp.core.stanza.model.Message) unmarshaller.unmarshal(new StringReader(xml)); + Tag xmlTag = (Tag) unmarshaller.unmarshal(new StringReader(tag)); + assertThat(xmlTag.getName(), equalTo("yo")); + Message juickMessage = xmppMessage.getExtension(Message.class); + assertThat(juickMessage.getTags().get(0).getName(), equalTo("yo")); + } } |