aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/java/com/juick/json/MessageSerializer.java13
-rw-r--r--src/test/java/com/juick/tests/SerializationTests.java15
2 files changed, 17 insertions, 11 deletions
diff --git a/src/test/java/com/juick/json/MessageSerializer.java b/src/test/java/com/juick/json/MessageSerializer.java
index ebc3b0b0..38596a1a 100644
--- a/src/test/java/com/juick/json/MessageSerializer.java
+++ b/src/test/java/com/juick/json/MessageSerializer.java
@@ -18,6 +18,7 @@
package com.juick.json;
import com.juick.Message;
+import com.juick.Photo;
import com.juick.Tag;
import org.json.JSONArray;
import org.json.JSONException;
@@ -79,7 +80,12 @@ public class MessageSerializer extends JSONSerializer<Message> {
}
if (json.has("photo")) {
- jmsg.Photo = json.getJSONObject("photo").getString("small");
+ JSONObject obj = json.getJSONObject("photo");
+ Photo photo = new Photo();
+ photo.setSmall(obj.getString("small"));
+ photo.setMedium(obj.getString("medium"));
+ photo.setThumbnail(obj.getString("thumbnail"));
+ jmsg.setPhoto(photo);
}
return jmsg;
@@ -123,8 +129,9 @@ public class MessageSerializer extends JSONSerializer<Message> {
if (msg.Place != null) {
json.put("place", placeSerializer.serialize(msg.Place));
}
- if (msg.AttachmentType != null) {
- String fname = msg.getMid() + (msg.getRid() > 0 ? "-" + msg.getRid() : "") + "." + msg.AttachmentType;
+ if (msg.getAttachmentType() != null) {
+ json.put("attach", msg.getAttachmentType());
+ String fname = msg.getMid() + (msg.getRid() > 0 ? "-" + msg.getRid() : "") + "." + msg.getAttachmentType();
JSONObject photo = new JSONObject();
String protocol = getUriScheme() == URIScheme.Plain ? "http:" : "https:";
photo.put("thumbnail", protocol + "//i.juick.com/ps/" + fname);
diff --git a/src/test/java/com/juick/tests/SerializationTests.java b/src/test/java/com/juick/tests/SerializationTests.java
index dd2812c7..61b86c5f 100644
--- a/src/test/java/com/juick/tests/SerializationTests.java
+++ b/src/test/java/com/juick/tests/SerializationTests.java
@@ -49,17 +49,10 @@ public class SerializationTests {
user.setName("ugnich");
user.setUid(1);
user.setFullName("Anton Ugnich");
- UserSerializer userSerializer = new UserSerializer();
- JSONObject handmadeJson = userSerializer.serialize(user);
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
- User jacksonUser = mapper.readValue(handmadeJson.toString(), User.class);
- assertEquals("jackson should deserialize ugnich json", user, jacksonUser);
- String jacksonString = mapper.writeValueAsString(user);
- JSONObject jacksonJson = new JSONObject(jacksonString);
- assertEquals("jackson should serialize as ugnich", handmadeJson.length(), jacksonJson.length());
Message msg = new Message();
msg.setMid(1);
msg.setUser(user);
@@ -67,11 +60,16 @@ public class SerializationTests {
msg.setDate(new Date());
msg.getTags().add(new Tag("test"));
msg.getTags().add(new Tag("json"));
+ msg.setAttachmentType("png");
MessageSerializer messageSerializer = new MessageSerializer();
JSONObject handmadeJsonMessage = messageSerializer.serialize(msg);
Message jacksonMessage = mapper.readValue(handmadeJsonMessage.toString(), Message.class);
assertEquals("jackson should deserialize ugnich json", msg, jacksonMessage);
String jacksonStringMessage = mapper.writeValueAsString(jacksonMessage);
+ assertEquals("jackson message should have an attachment url",
+ "http://i.juick.com/photos-1024/1.png", jacksonMessage.getAttachmentURL());
+ assertEquals("jackson message should have image previews",
+ "http://i.juick.com/photos-1024/1.png", jacksonMessage.getPhoto().getMedium());
JSONObject jacksonJsonMessage = new JSONObject(jacksonStringMessage);
assertEquals("jackson should serialize as ugnich", handmadeJsonMessage.length(), jacksonJsonMessage.length());
@@ -91,6 +89,7 @@ public class SerializationTests {
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(new InputSource(new StringReader(xmlString)));
assertEquals("jaxb should marshal as ugnich", 4, doc.getDocumentElement().getChildNodes().getLength());
- assertEquals("jaxb should marshal as ugnich", 7, doc.getDocumentElement().getAttributes().getLength());
+ assertEquals("jaxb should marshal as ugnich", 8, doc.getDocumentElement().getAttributes().getLength());
+ assertEquals("xmpp message should have an attach attribute", "png", doc.getDocumentElement().getAttribute("attach"));
}
} \ No newline at end of file