aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/juick/tests/MessageTests.java
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-05-23 14:06:51 +0300
committerGravatar Vitaly Takmazov2017-05-23 15:50:31 +0300
commit4c6f3ba0d539f63a83c18e20ed4219bdef849b81 (patch)
tree184ad8afcaa21ec4eeb7b06bb4f751548e710028 /src/test/java/com/juick/tests/MessageTests.java
parent237739950a305b13c9f29e3ca25c2e835d563a3f (diff)
drop ugnich json
Diffstat (limited to 'src/test/java/com/juick/tests/MessageTests.java')
-rw-r--r--src/test/java/com/juick/tests/MessageTests.java39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/test/java/com/juick/tests/MessageTests.java b/src/test/java/com/juick/tests/MessageTests.java
index 6bc291e2..89dd440e 100644
--- a/src/test/java/com/juick/tests/MessageTests.java
+++ b/src/test/java/com/juick/tests/MessageTests.java
@@ -1,31 +1,34 @@
package com.juick.tests;
-import static org.junit.Assert.assertEquals;
-
-import com.juick.json.MessageSerializer;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.juick.Message;
import com.juick.util.DateFormattersHolder;
-import com.juick.xmpp.extensions.JuickMessage;
import org.apache.commons.lang3.CharEncoding;
import org.json.JSONObject;
import org.junit.Test;
-
-import com.juick.Message;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringWriter;
import java.text.ParseException;
import java.util.Date;
+import static org.junit.Assert.assertEquals;
+
public class MessageTests {
@Test
public void messageParserSerializer() throws ParseException, ParserConfigurationException,
- IOException, SAXException {
+ IOException, SAXException, JAXBException {
Message msg = new Message();
msg.parseTags("test test" + (char) 0xA0 + "2 test3");
assertEquals("First tag must be", "test", msg.getTags().get(0).getName());
@@ -33,15 +36,23 @@ public class MessageTests {
assertEquals("Count of tags must be", 3, msg.getTags().size());
Date currentDate = new Date();
msg.setDate(currentDate);
- MessageSerializer serializer = new MessageSerializer();
- JSONObject jsonMessage = serializer.serialize(msg);
+ ObjectMapper serializer = new ObjectMapper();
+ String jsonMessage = serializer.writeValueAsString(msg);
+ JSONObject jsonObject = new JSONObject(jsonMessage);
assertEquals("date should be in timestamp field", DateFormattersHolder.getMessageFormatterInstance().format(currentDate),
- jsonMessage.getString("timestamp"));
- JuickMessage xmppMessage = new JuickMessage(msg);
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ jsonObject.getString("timestamp"));
+
+ JAXBContext context = JAXBContext
+ .newInstance(Message.class);
+ Marshaller m = context.createMarshaller();
+
+ StringWriter sw = new StringWriter();
+ m.marshal(msg, sw);
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
- Document doc = db.parse(new ByteArrayInputStream(xmppMessage.toString().getBytes(CharEncoding.UTF_8)));
+ Document doc = db.parse(new ByteArrayInputStream(sw.toString().getBytes(CharEncoding.UTF_8)));
Node juickNode = doc.getElementsByTagName("juick").item(0);
NamedNodeMap attrs = juickNode.getAttributes();
assertEquals("date should be in ts field", DateFormattersHolder.getMessageFormatterInstance().format(currentDate),