use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AuditManagerTest method testGetMostRecentEvents.
@Test
public void testGetMostRecentEvents() throws Exception {
int numEvents = 11;
List<AuditEvent> expectedEvents = new ArrayList<>(numEvents);
for (int i = 0; i < numEvents; i++) {
AuditEvent event = createEvent(AUDIT_EVENT_BASE + MILLIS_FORMAT.format(i));
expectedEvents.add(event);
}
EasyMock.expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(getEventNames(expectedEvents));
for (AuditEvent event : expectedEvents.subList(1, expectedEvents.size())) {
EasyMock.expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, AuditEvent.FACET_ID, event.getName())).andReturn(event);
}
metadataRepositoryControl.replay();
List<AuditEvent> events = auditManager.getMostRecentAuditEvents(metadataRepository, Collections.singletonList(TEST_REPO_ID));
assertNotNull(events);
assertEquals(numEvents - 1, events.size());
int expectedTimestampCounter = numEvents - 1;
for (AuditEvent event : events) {
String num = MILLIS_FORMAT.format(expectedTimestampCounter);
assertTestEvent(event, AUDIT_EVENT_BASE + num, getDefaultTestResourceName(num));
expectedTimestampCounter--;
}
metadataRepositoryControl.verify();
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AuditManagerTest method testGetEventsWithNonExistantResource.
@Test
public void testGetEventsWithNonExistantResource() throws Exception {
Date current = new Date();
AuditEvent expectedEvent1 = createEvent(new Date(current.getTime() - 12345));
Date expectedTimestamp = new Date(current.getTime() - 3000);
AuditEvent expectedEvent2 = createEvent(expectedTimestamp);
expectedEvent2.setResource("different-resource");
AuditEvent expectedEvent3 = createEvent(new Date(current.getTime() - 1000));
EasyMock.expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(Arrays.asList(expectedEvent1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
EasyMock.expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent1.getName())).andReturn(expectedEvent1);
EasyMock.expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent2.getName())).andReturn(expectedEvent2);
EasyMock.expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent3.getName())).andReturn(expectedEvent3);
metadataRepositoryControl.replay();
List<AuditEvent> events = auditManager.getAuditEventsInRange(metadataRepository, Collections.singletonList(TEST_REPO_ID), "foo", new Date(current.getTime() - 20000), current);
assertEquals(0, events.size());
metadataRepositoryControl.verify();
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AuditManagerTest method testGetEventsRangeNotInside.
@Test
public void testGetEventsRangeNotInside() throws Exception {
Date current = new Date();
String name1 = createEvent(new Date(current.getTime() - 12345)).getName();
Date expectedTimestamp = new Date(current.getTime() - 3000);
String name2 = createEvent(expectedTimestamp).getName();
String name3 = createEvent(new Date(current.getTime() - 1000)).getName();
EasyMock.expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(Arrays.asList(name1, name2, name3));
metadataRepositoryControl.replay();
List<AuditEvent> events = auditManager.getAuditEventsInRange(metadataRepository, Collections.singletonList(TEST_REPO_ID), new Date(current.getTime() - 20000), new Date(current.getTime() - 16000));
assertEquals(0, events.size());
metadataRepositoryControl.verify();
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AbstractRepositoryAdmin method triggerAuditEvent.
protected void triggerAuditEvent(String repositoryId, String resource, String action, AuditInformation auditInformation) {
User user = auditInformation == null ? null : auditInformation.getUser();
AuditEvent event = new AuditEvent(repositoryId, user == null ? "null" : user.getUsername(), resource, action);
event.setRemoteIP(auditInformation == null ? "null" : auditInformation.getRemoteAddr());
for (AuditListener listener : getAuditListeners()) {
listener.auditEvent(event);
}
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class ArchivaDavResource method triggerAuditEvent.
private void triggerAuditEvent(String remoteIP, String repositoryId, String resource, String action) {
AuditEvent event = new AuditEvent(repositoryId, principal, resource, action);
event.setRemoteIP(remoteIP);
for (AuditListener listener : auditListeners) {
listener.auditEvent(event);
}
}
Aggregations