Search in sources :

Example 16 with EventQueryDefinition

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

the class FeatureUsageController method get.

/**
 * {@inheritDoc}
 */
public void get(HttpServletRequest req, HttpServletResponse res, WebContext ctx) throws Exception {
    createPage(ctx, new EventQueryDefinition());
    LOGGER.info("Display feature usage");
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition)

Example 17 with EventQueryDefinition

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

the class EventRepositoryTestSupport method testFeatureUsageHitCount.

/**
 * TDD.
 */
@Test
public void testFeatureUsageHitCount() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Given empty event repository
    // When
    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, System.currentTimeMillis());
    // Assert Pie Chart (2 sectors with 8 and 8)
    Map<String, MutableHitCount> mapOfHit = repo.getFeatureUsageHitCount(testQuery);
    Assert.assertEquals(2, mapOfHit.size());
    Assert.assertTrue(mapOfHit.containsKey("f1"));
    Assert.assertTrue(mapOfHit.containsKey("f2"));
    Assert.assertEquals(8, mapOfHit.get("f1").get());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 18 with EventQueryDefinition

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

the class EventRepositoryTestSupport method testSaveAuditTrail.

/**
 * TDD.
 */
@Test
public void testSaveAuditTrail() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Given
    Event evt1 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", EventConstants.ACTION_CREATE);
    // When
    repo.saveEvent(evt1);
    // Wait for the event to be effectively store
    Thread.sleep(200);
    EventQueryDefinition eqd2 = new EventQueryDefinition(start - 200, System.currentTimeMillis());
    Assert.assertEquals(1, repo.getAuditTrail(eqd2).size());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 19 with EventQueryDefinition

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

the class EventRepositoryTestSupport 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 20 with EventQueryDefinition

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

the class EventRepositoryTestSupport method testFeatureUsageBarCharts.

/**
 * TDD.
 */
@Test
public void testFeatureUsageBarCharts() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Given empty event repository
    // When
    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));
    }
    // Then : 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)

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