Search in sources :

Example 21 with AuditEvent

use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.

the class AuditManagerTest method testGetMostRecentEventsInterleavedRepositories.

@Test
public void testGetMostRecentEventsInterleavedRepositories() throws Exception {
    int numEvents = 11;
    Map<String, List<String>> eventNames = new LinkedHashMap<String, List<String>>();
    List<AuditEvent> events = new ArrayList<>();
    eventNames.put(TEST_REPO_ID, new ArrayList<String>());
    eventNames.put(TEST_REPO_ID_2, new ArrayList<String>());
    for (int i = 0; i < numEvents; i++) {
        String repositoryId = i % 2 == 0 ? TEST_REPO_ID : TEST_REPO_ID_2;
        String num = MILLIS_FORMAT.format(i);
        AuditEvent event = createEvent(repositoryId, AUDIT_EVENT_BASE + num, getDefaultTestResourceName(num));
        events.add(event);
        eventNames.get(repositoryId).add(event.getName());
    }
    EasyMock.expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(eventNames.get(TEST_REPO_ID));
    EasyMock.expect(metadataRepository.getMetadataFacets(TEST_REPO_ID_2, AuditEvent.FACET_ID)).andReturn(eventNames.get(TEST_REPO_ID_2));
    for (AuditEvent event : events.subList(1, events.size())) {
        EasyMock.expect(metadataRepository.getMetadataFacet(event.getRepositoryId(), AuditEvent.FACET_ID, event.getName())).andReturn(event);
    }
    metadataRepositoryControl.replay();
    events = auditManager.getMostRecentAuditEvents(metadataRepository, Arrays.asList(TEST_REPO_ID, TEST_REPO_ID_2));
    assertNotNull(events);
    assertEquals(numEvents - 1, events.size());
    int expectedTimestampCounter = numEvents - 1;
    for (AuditEvent event : events) {
        String num = MILLIS_FORMAT.format(expectedTimestampCounter);
        String expectedRepoId = expectedTimestampCounter % 2 == 0 ? TEST_REPO_ID : TEST_REPO_ID_2;
        assertTestEvent(event, expectedRepoId, AUDIT_EVENT_BASE + num, getDefaultTestResourceName(num));
        expectedTimestampCounter--;
    }
    metadataRepositoryControl.verify();
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

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