Search in sources :

Example 6 with AuditEvent

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();
}
Also used : ArrayList(java.util.ArrayList) AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) Test(org.junit.Test)

Example 7 with AuditEvent

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();
}
Also used : AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) Date(java.util.Date) Test(org.junit.Test)

Example 8 with AuditEvent

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();
}
Also used : AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) Date(java.util.Date) Test(org.junit.Test)

Example 9 with AuditEvent

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);
    }
}
Also used : User(org.apache.archiva.redback.users.User) AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) AuditListener(org.apache.archiva.repository.events.AuditListener)

Example 10 with AuditEvent

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);
    }
}
Also used : AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) AuditListener(org.apache.archiva.repository.events.AuditListener)

Aggregations

AuditEvent (org.apache.archiva.metadata.model.facets.AuditEvent)21 Test (org.junit.Test)13 Date (java.util.Date)11 ArrayList (java.util.ArrayList)5 AuditListener (org.apache.archiva.repository.events.AuditListener)5 ParseException (java.text.ParseException)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 AuditInformation (org.apache.archiva.admin.model.AuditInformation)1 User (org.apache.archiva.redback.users.User)1