Example #1
0
 @Test
 public void testToJSON() throws IOException, Exception {
   String testData = UnitTestUtils.readFile("/resources/testData1.json");
   JSONObject obj = (JSONObject) JSONValue.parse(testData);
   LogEntry entry = new LogEntry(obj);
   JSONObject test = entry.toJSON();
   assertEquals(obj.get("message"), test.get("message"));
   assertEquals(obj.get("@version"), test.get("@version"));
   //		assertEquals(DateFormat.getDateInstance().format(entry.getTimestamp()),
   // test.get("@timestamp"));
   assertEquals(obj.get("host"), test.get("host"));
   assertEquals(obj.get("path"), test.get("path"));
   assertEquals(obj.get("type"), test.get("type"));
 }
Example #2
0
 @Test
 public void testFromJSON() throws IOException, Exception {
   SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
   Date test = format.parse("2013-01-04T11:09:16.171Z");
   String testData = UnitTestUtils.readFile("/resources/testData1.json");
   JSONObject obj = (JSONObject) JSONValue.parse(testData);
   LogEntry entry = new LogEntry(obj);
   assertEquals("1", entry.getVersion());
   assertEquals(0, entry.getTags().size());
   assertEquals(0, entry.getFields().size());
   assertEquals(test, entry.getTimestamp());
   assertEquals("hdp01.localdomain", entry.getHost());
   assertEquals("/var/log/messages", entry.getPath());
   assertNotNull(entry.getMessage());
   assertEquals("syslog", entry.getType());
 }