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();
}
Aggregations