@Test public void testGetLastEvent_AssertRecordContentAndContext() { FileAuditor auditor = new FileAuditor(auditFile); AuditEvent event1 = new AuditEvent("Category" + UUID.randomUUID(), "type"); AuditEvent event2 = new AuditEvent("Category" + UUID.randomUUID(), "type"); DefaultAuditContext context1 = new DefaultAuditContext("name1", "value1"); DefaultAuditContext context2 = new DefaultAuditContext("name2", "value2"); auditor.audit(PRINCIPAL, event1); auditor.audit(PRINCIPAL, event2, Arrays.asList(context1, context2)); 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")); String[] contexts = (String[])lastMessage.get("Contexts"); assertEquals(2, contexts.length); assertEquals("name1:value1", contexts[0]); assertEquals("name2:value2", contexts[1]); }
@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();  }