SyslogWireExtractor implements Extractor, SyslogConsts { public static Event extractEvent(DataInputStream in) throws EventExtractException { return format.extract(in); }  byte[] toBytes(Event e); static Event extractEvent(DataInputStream in); Event extract(DataInputStream in); static byte[] formatEventToBytes(Event e);  }
@Test public void testNewExtractor() throws EventExtractException { String msg = "This is a test"; String entry = "<13>" + msg + "\n"; DataInputStream in = new DataInputStream(new ByteArrayInputStream(entry .getBytes())); Event e = SyslogWireExtractor.extractEvent(in); Assert.assertEquals(1, e.get(SyslogConsts.SYSLOG_FACILITY)[0]); Assert.assertEquals(5, e.get(SyslogConsts.SYSLOG_SEVERITY)[0]); Assert.assertTrue(Arrays.equals(msg.getBytes(), e.getBody())); }
@Test public void testNewFail() { String msg = "this will fail"; Event e = null; try { DataInputStream in = new DataInputStream(new ByteArrayInputStream(msg .getBytes())); e = SyslogWireExtractor.extractEvent(in); System.out.println(e); } catch (EventExtractException e1) { System.out.println("expected:" + e1); return; } Assert.fail("Should have thrown exception"); }