Search in sources :

Example 6 with EventQueryDefinition

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

the class AbstractEventRepositoryTest method testFeatureUsageBarCharts.

@Test
public void testFeatureUsageBarCharts() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Create Event
    repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", EventConstants.ACTION_CREATE));
    for (int i = 0; i < 8; i++) {
        Thread.sleep(100);
        repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
        repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
    }
    // Assert bar chart (2 bars with 8 and 8)
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 10, System.currentTimeMillis() + 10);
    BarChart bChart = repo.getFeatureUsageBarChart(testQuery);
    Assert.assertEquals(2, bChart.getChartBars().size());
    Assert.assertEquals(new Integer(8), bChart.getChartBars().get(0).getValue());
    Assert.assertEquals(new Integer(8), bChart.getChartBars().get(1).getValue());
    Assert.assertNotNull(bChart.getChartBars().get(0).getColor());
    Assert.assertNotNull(bChart.getChartBars().get(1).getColor());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) BarChart(org.ff4j.audit.chart.BarChart) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 7 with EventQueryDefinition

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

the class AbstractEventRepositoryTest method testSaveAuditTrail.

@Test
public void testSaveAuditTrail() throws InterruptedException {
    long start = System.currentTimeMillis();
    Event evt1 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", EventConstants.ACTION_CREATE);
    Assert.assertTrue(repo.saveEvent(evt1));
    Thread.sleep(200);
    Assert.assertEquals(1, repo.getAuditTrail(new EventQueryDefinition(start - 10, System.currentTimeMillis())).size());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 8 with EventQueryDefinition

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

the class AbstractEventRepositoryTest method testGetFeatureUsageHistory.

@Test
public void testGetFeatureUsageHistory() throws InterruptedException {
    long start = System.currentTimeMillis();
    repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CREATE));
    for (int i = 0; i < 8; i++) {
        Thread.sleep(100);
        repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
        repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
    }
    Thread.sleep(100);
    // Then
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
    TimeSeriesChart tsc = repo.getFeatureUsageHistory(testQuery, TimeUnit.HOURS);
    Assert.assertEquals(1, tsc.getTimeSlots().size());
}
Also used : TimeSeriesChart(org.ff4j.audit.chart.TimeSeriesChart) EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 9 with EventQueryDefinition

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

the class AbstractEventRepositoryTest method testHostHitCount.

/**
 * TDD.
 */
@Test
public void testHostHitCount() throws InterruptedException {
    long start = System.currentTimeMillis();
    // When
    for (int i = 0; i < 8; i++) {
        Thread.sleep(100);
        repo.saveEvent(new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
    }
    Thread.sleep(200);
    // Then
    EventQueryDefinition testQuery = new EventQueryDefinition(start, System.currentTimeMillis());
    Map<String, MutableHitCount> mapOfHit = repo.getHostHitCount(testQuery);
    Assert.assertEquals(1, mapOfHit.size());
    Assert.assertEquals(1, mapOfHit.values().size());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 10 with EventQueryDefinition

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

the class AuditBeanTest method testEventQueryDefinition.

@Test
public void testEventQueryDefinition() {
    EventQueryDefinition eqd = new EventQueryDefinition();
    eqd.setFrom(System.currentTimeMillis() - 100);
    eqd.setTo(System.currentTimeMillis() + 100);
    eqd.setHostFilters(Util.set("localhost"));
    eqd.setSourceFilters(Util.set("JAVA_API"));
    eqd.setActionFilters(Util.set(EventConstants.ACTION_CHECK_OK));
    eqd.setNamesFilter(Util.set("F1"));
    eqd.setFrom(new Long(eqd.getFrom()));
    eqd.setTo(new Long(eqd.getTo()));
    eqd.addFilterAction(EventConstants.ACTION_CLEAR);
    eqd.addFilterHost("MC");
    eqd.addFilterSource("WEB_CONSOLE");
    eqd.addFilterName("f2");
    Assert.assertTrue(eqd.getActionFilters().contains(EventConstants.ACTION_CHECK_OK));
    Assert.assertFalse(eqd.matchAction(null));
    Assert.assertTrue(eqd.matchAction(EventConstants.ACTION_CHECK_OK));
    Assert.assertFalse(eqd.matchAction(EventConstants.ACTION_CHECK_OFF));
    Assert.assertFalse(eqd.matchSource(null));
    Assert.assertTrue(eqd.matchSource("JAVA_API"));
    Assert.assertFalse(eqd.matchSource(EventConstants.ACTION_CHECK_OFF));
    Assert.assertFalse(eqd.matchHost(null));
    Assert.assertTrue(eqd.matchHost("localhost"));
    Assert.assertFalse(eqd.matchHost(EventConstants.ACTION_CHECK_OFF));
    Assert.assertFalse(eqd.matchName(null));
    Assert.assertTrue(eqd.matchName("f2"));
    Assert.assertFalse(eqd.matchName(EventConstants.ACTION_CHECK_OFF));
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) 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