aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--juick-core/build.gradle1
-rw-r--r--juick-core/src/main/java/com/juick/Tag.java12
-rw-r--r--juick-core/src/test/java/com/juick/MessageTest.java34
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<Tag> {
+ @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<Tag> {
(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 = "<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"));
+ }
}