From 763e71486aa51900de47a20fbbe2c5b0bf6193c5 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Fri, 15 Sep 2017 03:19:29 +0300
Subject: core: fix tags deserialization
---
.../src/test/java/com/juick/MessageTest.java | 34 ++++++++++++++++++++++
1 file changed, 34 insertions(+)
(limited to 'juick-core/src/test')
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 = "yo";
+ String xml = "yoyoyopeople";
+ 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"));
+ }
}
--
cgit v1.2.3