aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/java/com/juick/tests/ApiTests.java4
-rw-r--r--src/test/java/com/juick/tests/JsonTests.java25
-rw-r--r--src/test/java/com/juick/tests/MessageTests.java4
3 files changed, 28 insertions, 5 deletions
diff --git a/src/test/java/com/juick/tests/ApiTests.java b/src/test/java/com/juick/tests/ApiTests.java
index 5c6cddf3..533b2428 100644
--- a/src/test/java/com/juick/tests/ApiTests.java
+++ b/src/test/java/com/juick/tests/ApiTests.java
@@ -81,7 +81,7 @@ public class ApiTests {
assertEquals(1, rid);
Message msg3 = MessagesQueries.getMessage(jdbc, mid2);
assertEquals(1, msg3.Replies);
- assertEquals("weather", msg3.Tags.get(0));
+ assertEquals("weather", msg3.Tags.get(0).getName());
assertEquals(ugnich.getUID(), UserQueries.checkPassword(jdbc, ugnich.getUName(), "x"));
assertEquals(-1, UserQueries.checkPassword(jdbc, ugnich.getUName(), "xy"));
SubscriptionsQueries.subscribeMessage(jdbc, msg.getMID(), ugnich.getUID());
@@ -105,7 +105,7 @@ public class ApiTests {
assertEquals("text should match", "yoyo",
MessagesQueries.getMessage(jdbc, mid).getText());
assertEquals("tag should match", "yo",
- MessagesQueries.getMessageTags(jdbc, mid).get(0).Name);
+ MessagesQueries.getMessageTags(jdbc, mid).get(0).getName());
assertNotEquals("should not be error", "Error", protocol.getReply(user, "#" + mid).getDescription());
assertEquals("should be PONG", "PONG", protocol.getReply(user, " ping \n ").getDescription());
int readerUid = UserQueries.createUser(jdbc, "dummyReader", "dummySecret");
diff --git a/src/test/java/com/juick/tests/JsonTests.java b/src/test/java/com/juick/tests/JsonTests.java
index babcc6c7..ab0d6283 100644
--- a/src/test/java/com/juick/tests/JsonTests.java
+++ b/src/test/java/com/juick/tests/JsonTests.java
@@ -1,9 +1,15 @@
package com.juick.tests;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.Message;
+import com.juick.User;
import com.juick.json.MessageSerializer;
+import com.juick.json.UserSerializer;
+import org.json.JSONObject;
import org.junit.Test;
+import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
@@ -24,6 +30,23 @@ public class JsonTests {
} catch (ParseException e) {
e.printStackTrace();
}
-
+ }
+ @Test
+ public void serializersTest() throws IOException {
+ User user = new User();
+ user.setUName("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());
}
} \ No newline at end of file
diff --git a/src/test/java/com/juick/tests/MessageTests.java b/src/test/java/com/juick/tests/MessageTests.java
index 5dceccc0..3e391a67 100644
--- a/src/test/java/com/juick/tests/MessageTests.java
+++ b/src/test/java/com/juick/tests/MessageTests.java
@@ -26,8 +26,8 @@ public class MessageTests {
IOException, SAXException {
Message msg = new Message();
msg.parseTags("test test" + (char) 0xA0 + "2 test3");
- assertEquals("First tag must be", "test", msg.Tags.get(0));
- assertEquals("Third tag must be", "test3", msg.Tags.get(2));
+ assertEquals("First tag must be", "test", msg.Tags.get(0).getName());
+ assertEquals("Third tag must be", "test3", msg.Tags.get(2).getName());
assertEquals("Count of tags must be", 3, msg.Tags.size());
Date currentDate = new Date();
msg.setDate(currentDate);