Search in sources :

Example 31 with EventQueryDefinition

use of org.ff4j.audit.EventQueryDefinition in project ff4j by ff4j.

the class AbstractEventRepositoryTest method testPurgeEvents.

/**
 * TDD.
 */
@Test
public void testPurgeEvents() throws InterruptedException {
    // Given, 2 events in the repo
    long topStart = System.currentTimeMillis();
    Event evtAudit = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE);
    evtAudit.setUuid("1234-5678-9012-3456");
    Event evtFeatureUsage = new Event(SOURCE_JAVA, TARGET_FEATURE, "f2", ACTION_CHECK_OK);
    evtFeatureUsage.setUuid("1234-5678-9012-3457");
    repo.saveEvent(evtAudit);
    repo.saveEvent(evtFeatureUsage);
    Thread.sleep(100);
    Assert.assertNotNull(repo.getEventByUUID(evtAudit.getUuid(), System.currentTimeMillis()));
    Assert.assertNotNull(repo.getEventByUUID(evtFeatureUsage.getUuid(), System.currentTimeMillis()));
    // When
    EventQueryDefinition testQuery = new EventQueryDefinition(topStart - 100, System.currentTimeMillis());
    repo.purgeFeatureUsage(testQuery);
    Assert.assertNull(repo.getEventByUUID(evtFeatureUsage.getUuid(), System.currentTimeMillis()));
    Assert.assertTrue(repo.searchFeatureUsageEvents(testQuery).isEmpty());
    // Then
    EventQueryDefinition testQuery2 = new EventQueryDefinition(topStart - 100, System.currentTimeMillis());
    repo.purgeAuditTrail(testQuery2);
    Assert.assertNull(repo.getEventByUUID(evtAudit.getUuid(), System.currentTimeMillis()));
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Aggregations

EventQueryDefinition (org.ff4j.audit.EventQueryDefinition)31 Test (org.junit.Test)25 Event (org.ff4j.audit.Event)22 MutableHitCount (org.ff4j.audit.MutableHitCount)8 BarChart (org.ff4j.audit.chart.BarChart)3 TimeSeriesChart (org.ff4j.audit.chart.TimeSeriesChart)3 Date (java.util.Date)2 EventSeries (org.ff4j.audit.EventSeries)2 ParseException (java.text.ParseException)1 PieChart (org.ff4j.audit.chart.PieChart)1 EventRepository (org.ff4j.audit.repository.EventRepository)1 JdbcQueryBuilder (org.ff4j.store.JdbcQueryBuilder)1