Search in sources :

Example 16 with AuditEvent

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

Example 17 with AuditEvent

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

Example 18 with AuditEvent

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

Example 19 with AuditEvent

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

Example 20 with AuditEvent

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