@Test public void testGetLastEvent_AssertRecordContent() { FileAuditor auditor = new FileAuditor(auditFile); AuditEvent event1 = new AuditEvent("Category" + UUID.randomUUID(), "type"); AuditEvent event2 = new AuditEvent("Category" + UUID.randomUUID(), "type"); auditor.audit(PRINCIPAL, event1); auditor.audit(PRINCIPAL, event2); assertNotNull(auditor.getLastEvent()); CompositeData lastMessage = auditor.getLastEvent(); assertEquals(event2.getName(), lastMessage.get("Event Name")); assertEquals(event2.getType(), lastMessage.get("Event Type")); assertTrue(lastMessage.get("Event Id").toString().length() > 0); assertTrue(lastMessage.get("Event Time").toString().length() > 0); assertNotNull(lastMessage.get("Contexts")); }
@Override public synchronized CompositeData getLastEvent() { if (eventType == null) return null; CompositeData retVal = null; long currentPosition = -1; try { currentPosition = auditFile.getFilePointer(); retVal = getEvent(currentPosition); } catch (IOException e) { } finally { try { if (currentPosition > -1) auditFile.seek(currentPosition); } catch (IOException e) {} } return retVal; }
FileAuditor extends AbstractAuditor implements AuditorMBean { @Override public synchronized CompositeData getLastEvent() { if (eventType == null) return null; CompositeData retVal = null; long currentPosition = -1; try { currentPosition = auditFile.getFilePointer(); retVal = getEvent(currentPosition); } catch (IOException e) { } finally { try { if (currentPosition > -1) auditFile.seek(currentPosition); } catch (IOException e) {} } return retVal; } }
FileAuditor extends AbstractAuditor implements AuditorMBean { @Override public synchronized CompositeData getLastEvent() { if (eventType == null) return null; CompositeData retVal = null; long currentPosition = -1; try { currentPosition = auditFile.getFilePointer(); retVal = getEvent(currentPosition); } catch (IOException e) { } finally { try { if (currentPosition > -1) auditFile.seek(currentPosition); } catch (IOException e) {} } return retVal; } @Inject  FileAuditor(@AuditFile File auditFile); }
FileAuditor extends AbstractAuditor implements AuditorMBean { @Override public synchronized CompositeData getLastEvent() { if (eventType == null) return null; CompositeData retVal = null; long currentPosition = -1; try { currentPosition = auditFile.getFilePointer(); retVal = getEvent(currentPosition); } catch (IOException e) { } finally { try { if (currentPosition > -1) auditFile.seek(currentPosition); } catch (IOException e) {} } return retVal; } @Inject  FileAuditor(@AuditFile File auditFile); @Override void writeEvent(UUID eventId, Calendar eventTimeStamp, String principal, AuditEvent event, Collection<? extends AuditContext> contexts); @Override synchronized Integer getEventCount(); @Override synchronized CompositeData[] getEvents(Integer eventCount); @Override synchronized CompositeData getLastEvent(); @Override synchronized void clear(); }
FileAuditor extends AbstractAuditor implements AuditorMBean { @Override public synchronized CompositeData getLastEvent() { if (eventType == null) return null; CompositeData retVal = null; long currentPosition = -1; try { currentPosition = auditFile.getFilePointer(); retVal = getEvent(currentPosition); } catch (IOException e) { } finally { try { if (currentPosition > -1) auditFile.seek(currentPosition); } catch (IOException e) {} } return retVal; } @Inject  FileAuditor(@AuditFile File auditFile); @Override void writeEvent(UUID eventId, Calendar eventTimeStamp, String principal, AuditEvent event, Collection<? extends AuditContext> contexts); @Override synchronized Integer getEventCount(); @Override synchronized CompositeData[] getEvents(Integer eventCount); @Override synchronized CompositeData getLastEvent(); @Override synchronized void clear();  }