Search in sources :

Example 26 with EventQueryDefinition

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

the class AbstractEventRepositoryTest method testSaveCheckOff.

/**
 * TDD.
 */
@Test
public void testSaveCheckOff() throws InterruptedException {
    long start = System.currentTimeMillis();
    // Given
    Event evt1 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OFF);
    // When
    Assert.assertTrue(repo.saveEvent(evt1));
    Thread.sleep(100);
    // Then
    Assert.assertEquals(0, repo.getFeatureUsageTotalHitCount(new EventQueryDefinition(start, System.currentTimeMillis())));
    Assert.assertEquals(0, repo.getAuditTrail(new EventQueryDefinition(start, System.currentTimeMillis())).size());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 27 with EventQueryDefinition

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

the class AbstractEventRepositoryTest method testPieChart.

@Test
public void testPieChart() 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);
    EventQueryDefinition eqd = new EventQueryDefinition(start - 10, System.currentTimeMillis());
    Assert.assertNotNull(repo.getFeatureUsagePieChart(eqd));
    Assert.assertNotNull(repo.getHostPieChart(eqd));
    Assert.assertNotNull(repo.getSourcePieChart(eqd));
    Assert.assertNotNull(repo.getUserPieChart(eqd));
    Assert.assertNotNull(repo.getHostBarChart(eqd));
    Assert.assertNotNull(repo.getSourceBarChart(eqd));
    Assert.assertNotNull(repo.getUserBarChart(eqd));
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) Test(org.junit.Test)

Example 28 with EventQueryDefinition

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

the class AbstractEventRepositoryTest method testSourceHitCount.

/**
 * TDD.
 */
@Test
public void testSourceHitCount() 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));
        repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", ACTION_CHECK_OK));
    }
    Thread.sleep(200);
    repo.saveEvent(new Event(SOURCE_WEBAPI, TARGET_FEATURE, "f1", ACTION_CHECK_OK));
    Thread.sleep(200);
    // Then
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
    Map<String, MutableHitCount> mapOfHit = repo.getSourceHitCount(testQuery);
    Assert.assertEquals(3, mapOfHit.size());
    Assert.assertTrue(mapOfHit.containsKey(SOURCE_JAVA));
    Assert.assertTrue(mapOfHit.containsKey(SOURCE_WEB));
    Assert.assertEquals(1, mapOfHit.get(SOURCE_WEBAPI).get());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 29 with EventQueryDefinition

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

the class AbstractEventRepositoryTest method testUserHitCount.

/**
 * TDD.
 */
@Test
public void testUserHitCount() throws InterruptedException {
    long start = System.currentTimeMillis();
    // When
    for (int i = 0; i < 8; i++) {
        Event e1 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK);
        e1.setUser("JOHN");
        repo.saveEvent(e1);
        Thread.sleep(100);
        Event e2 = new Event(SOURCE_JAVA, TARGET_FEATURE, "f1", ACTION_CHECK_OK);
        e2.setUser("BOB");
        repo.saveEvent(e2);
        Thread.sleep(100);
    }
    Thread.sleep(200);
    // Then
    EventQueryDefinition testQuery = new EventQueryDefinition(start - 20, System.currentTimeMillis());
    Map<String, MutableHitCount> mapOfHit = repo.getUserHitCount(testQuery);
    Assert.assertEquals(2, mapOfHit.size());
    Assert.assertTrue(mapOfHit.containsKey("JOHN"));
    Assert.assertTrue(mapOfHit.containsKey("BOB"));
    Assert.assertEquals(8, mapOfHit.get("BOB").get());
}
Also used : EventQueryDefinition(org.ff4j.audit.EventQueryDefinition) Event(org.ff4j.audit.Event) MutableHitCount(org.ff4j.audit.MutableHitCount) Test(org.junit.Test)

Example 30 with EventQueryDefinition

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

the class AbstractEventRepositoryTest method testFeatureUsageHitCount.

@Test
public void testFeatureUsageHitCount() 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", EventConstants.ACTION_CHECK_OK));
        repo.saveEvent(new Event(SOURCE_WEB, TARGET_FEATURE, "f2", EventConstants.ACTION_CHECK_OK));
    }
    Thread.sleep(100);
    // Assert bar chart (2 bars with 8 and 8)
    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)

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