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 --- juick-core/build.gradle | 1 + juick-core/src/main/java/com/juick/Tag.java | 12 ++++---- .../src/test/java/com/juick/MessageTest.java | 34 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/juick-core/build.gradle b/juick-core/build.gradle index c145a504..27fe03ba 100644 --- a/juick-core/build.gradle +++ b/juick-core/build.gradle @@ -13,6 +13,7 @@ dependencies { testCompile "com.fasterxml.jackson.core:jackson-databind:${rootProject.jacksonVersion}" testCompile "junit:junit:${rootProject.junitVersion}" testCompile "org.hamcrest:hamcrest-all:${rootProject.hamcrestVersion}" + testCompile "rocks.xmpp:xmpp-core-client:0.7.4" } compileJava.options.encoding = 'UTF-8' diff --git a/juick-core/src/main/java/com/juick/Tag.java b/juick-core/src/main/java/com/juick/Tag.java index 7f839242..29e5c767 100644 --- a/juick-core/src/main/java/com/juick/Tag.java +++ b/juick-core/src/main/java/com/juick/Tag.java @@ -18,10 +18,7 @@ package com.juick; import com.fasterxml.jackson.annotation.JsonValue; -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlRootElement; -import javax.xml.bind.annotation.XmlValue; +import javax.xml.bind.annotation.*; import java.util.Comparator; import java.util.Objects; @@ -29,11 +26,14 @@ import java.util.Objects; * @author Ugnich Anton */ @XmlRootElement(name = "tag", namespace = "http://juick.com/message") -@XmlAccessorType(XmlAccessType.PROPERTY) +@XmlAccessorType(XmlAccessType.FIELD) public class Tag implements Comparable { + @XmlValue private String name; + @XmlTransient public int TID = 0; + @XmlTransient public int SynonymID = 0; public Tag() { @@ -50,7 +50,7 @@ public class Tag implements Comparable { (o instanceof Tag) && Objects.equals(name, ((Tag) o).name); } - @XmlValue + @XmlTransient @JsonValue public String getName() { return name; 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