use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AuditManagerTest method testAddAuditEventNoRepositoryId.
@Test
public void testAddAuditEventNoRepositoryId() throws Exception {
AuditEvent event = createEvent(new Date());
event.setRepositoryId(null);
// should just be ignored
metadataRepositoryControl.replay();
auditManager.addAuditEvent(metadataRepository, event);
metadataRepositoryControl.verify();
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AuditManagerTest method testAddAuditEvent.
@Test
public void testAddAuditEvent() throws Exception {
AuditEvent event = createEvent(new Date());
metadataRepository.addMetadataFacet(TEST_REPO_ID, event);
metadataRepositoryControl.replay();
auditManager.addAuditEvent(metadataRepository, event);
metadataRepositoryControl.verify();
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AuditManagerTest method testGetEventsRangeUpperOutside.
@Test
public void testGetEventsRangeUpperOutside() throws Exception {
Date current = new Date();
AuditEvent event1 = createEvent(new Date(current.getTime() - 12345));
Date expectedTimestamp = new Date(current.getTime() - 3000);
AuditEvent expectedEvent2 = createEvent(expectedTimestamp);
Date ts3 = new Date(current.getTime() - 1000);
AuditEvent expectedEvent3 = createEvent(ts3);
EasyMock.expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(Arrays.asList(event1.getName(), expectedEvent2.getName(), expectedEvent3.getName()));
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), new Date(current.getTime() - 4000), current);
assertEquals(2, events.size());
assertTestEvent(events.get(0), TIMESTAMP_FORMAT.format(ts3), expectedEvent3.getResource());
assertTestEvent(events.get(1), TIMESTAMP_FORMAT.format(expectedTimestamp), expectedEvent2.getResource());
metadataRepositoryControl.verify();
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AuditManagerTest method testGetEventsRangeLowerAndUpperOutside.
@Test
public void testGetEventsRangeLowerAndUpperOutside() throws Exception {
Date current = new Date();
Date ts1 = new Date(current.getTime() - 12345);
AuditEvent expectedEvent1 = createEvent(ts1);
Date expectedTimestamp = new Date(current.getTime() - 3000);
AuditEvent expectedEvent2 = createEvent(expectedTimestamp);
Date ts3 = new Date(current.getTime() - 1000);
AuditEvent expectedEvent3 = createEvent(ts3);
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), new Date(current.getTime() - 20000), current);
assertEquals(3, events.size());
assertTestEvent(events.get(0), TIMESTAMP_FORMAT.format(ts3), expectedEvent3.getResource());
assertTestEvent(events.get(1), TIMESTAMP_FORMAT.format(expectedTimestamp), expectedEvent2.getResource());
assertTestEvent(events.get(2), TIMESTAMP_FORMAT.format(ts1), expectedEvent1.getResource());
metadataRepositoryControl.verify();
}
use of org.apache.archiva.metadata.model.facets.AuditEvent in project archiva by apache.
the class AuditManagerTest method testGetEventsRangeInside.
@Test
public void testGetEventsRangeInside() throws Exception {
Date current = new Date();
AuditEvent event1 = createEvent(new Date(current.getTime() - 12345));
Date expectedTimestamp = new Date(current.getTime() - 3000);
AuditEvent expectedEvent = createEvent(expectedTimestamp);
AuditEvent event3 = createEvent(new Date(current.getTime() - 1000));
EasyMock.expect(metadataRepository.getMetadataFacets(TEST_REPO_ID, AuditEvent.FACET_ID)).andReturn(Arrays.asList(event1.getName(), expectedEvent.getName(), event3.getName()));
// only match the middle one
EasyMock.expect(metadataRepository.getMetadataFacet(TEST_REPO_ID, AuditEvent.FACET_ID, expectedEvent.getName())).andReturn(expectedEvent);
metadataRepositoryControl.replay();
List<AuditEvent> events = auditManager.getAuditEventsInRange(metadataRepository, Collections.singletonList(TEST_REPO_ID), new Date(current.getTime() - 4000), new Date(current.getTime() - 2000));
assertEquals(1, events.size());
assertTestEvent(events.get(0), TIMESTAMP_FORMAT.format(expectedTimestamp), expectedEvent.getResource());
metadataRepositoryControl.verify();
}
Aggregations