Search in sources :

Example 11 with Bucket

use of org.activityinfo.shared.command.result.Bucket in project activityinfo by bedatadriven.

the class PivotTableGeneratorTest method testIndicatorSortOrder.

@Test
public void testIndicatorSortOrder() {
    // test input data: user
    User user = new User();
    user.setLocale("fr");
    // test input data: PivotTableElement
    PivotTableReportElement element = new PivotTableReportElement();
    Dimension indicatorDim = new Dimension(DimensionType.Indicator);
    element.addRowDimension(indicatorDim);
    // test input data: aggregated results
    List<Bucket> buckets = new ArrayList<Bucket>();
    buckets.add(newBucket(300, category(indicatorDim, 1, "Nb. menages", 3)));
    buckets.add(newBucket(400, category(indicatorDim, 2, "Nb. personnes", 1)));
    buckets.add(newBucket(600, category(indicatorDim, 3, "Nb. deplaces", 2)));
    // collaborator : PivotDAO
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(PivotSites.class))).andReturn(new PivotSites.PivotResult(buckets));
    replay(dispatcher);
    // CLASS UNDER TEST!!
    PivotTableGenerator generator = new PivotTableGenerator(dispatcher);
    generator.generate(user, element, null, null);
    Assert.assertNotNull("element content", element.getContent());
    List<PivotTableData.Axis> rows = element.getContent().getData().getRootRow().getChildren();
    Assert.assertEquals(2, ((EntityCategory) rows.get(0).getCategory()).getId());
    Assert.assertEquals(3, ((EntityCategory) rows.get(1).getCategory()).getId());
    Assert.assertEquals(1, ((EntityCategory) rows.get(2).getCategory()).getId());
}
Also used : PivotSites(org.activityinfo.shared.command.PivotSites) User(org.activityinfo.server.database.hibernate.entity.User) Bucket(org.activityinfo.shared.command.result.Bucket) ArrayList(java.util.ArrayList) Dimension(org.activityinfo.shared.report.model.Dimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) PivotTableReportElement(org.activityinfo.shared.report.model.PivotTableReportElement) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Example 12 with Bucket

use of org.activityinfo.shared.command.result.Bucket in project activityinfo by bedatadriven.

the class PivotSitesHandlerTest method testLinkedAttributegroupFilterData.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void testLinkedAttributegroupFilterData() {
    withAttributeGroupDim();
    forFilterData();
    execute();
    assertThat().thereAre(2).buckets();
    Dimension dim = new Dimension(DimensionType.AttributeGroup);
    Bucket causeBucket = findBucketsByCategory(buckets, dim, new EntityCategory(1)).get(0);
    assertEquals("cause", causeBucket.getCategory(dim).getLabel());
    assertEquals(0, (int) causeBucket.doubleValue());
    Bucket contenuBucket = findBucketsByCategory(buckets, dim, new EntityCategory(2)).get(0);
    assertEquals("contenu du kit", contenuBucket.getCategory(dim).getLabel());
    assertEquals(0, (int) contenuBucket.doubleValue());
}
Also used : Bucket(org.activityinfo.shared.command.result.Bucket) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 13 with Bucket

use of org.activityinfo.shared.command.result.Bucket in project activityinfo by bedatadriven.

the class PivotSitesHandlerTest method testLinkedAttributegroupFilterDataForIndicator.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void testLinkedAttributegroupFilterDataForIndicator() {
    withAttributeGroupDim();
    forFilterData();
    Dimension dim = new Dimension(DimensionType.AttributeGroup);
    // empty
    filter.addRestriction(DimensionType.Indicator, 100);
    execute();
    assertThat().thereAre(0).buckets();
    // cause, contenu du kit
    filter = new Filter();
    filter.addRestriction(DimensionType.Indicator, 1);
    execute();
    assertThat().thereAre(2).buckets();
    Bucket bucket1 = findBucketsByCategory(buckets, dim, new EntityCategory(1)).get(0);
    assertEquals("cause", bucket1.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket1.doubleValue());
    Bucket bucket2 = findBucketsByCategory(buckets, dim, new EntityCategory(2)).get(0);
    assertEquals("contenu du kit", bucket2.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket2.doubleValue());
    // cause
    filter = new Filter();
    filter.addRestriction(DimensionType.Indicator, 2);
    execute();
    assertThat().thereAre(1).buckets();
    bucket1 = findBucketsByCategory(buckets, dim, new EntityCategory(1)).get(0);
    assertEquals("cause", bucket1.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket1.doubleValue());
    // cause, contenu du kit
    filter = new Filter();
    filter.addRestriction(DimensionType.Indicator, Arrays.asList(1, 2, 100));
    execute();
    assertThat().thereAre(2).buckets();
    bucket1 = findBucketsByCategory(buckets, dim, new EntityCategory(1)).get(0);
    assertEquals("cause", bucket1.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket1.doubleValue());
    bucket2 = findBucketsByCategory(buckets, dim, new EntityCategory(2)).get(0);
    assertEquals("contenu du kit", bucket2.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket2.doubleValue());
}
Also used : Bucket(org.activityinfo.shared.command.result.Bucket) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 14 with Bucket

use of org.activityinfo.shared.command.result.Bucket in project activityinfo by bedatadriven.

the class PivotSitesHandlerLocalTest method testLinkedAttributegroupFilterData.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void testLinkedAttributegroupFilterData() {
    withAttributeGroupDim();
    forFilterData();
    execute();
    assertThat().thereAre(2).buckets();
    Dimension dim = new Dimension(DimensionType.AttributeGroup);
    Bucket causeBucket = findBucketsByCategory(buckets, dim, new EntityCategory(1)).get(0);
    assertEquals("cause", causeBucket.getCategory(dim).getLabel());
    assertEquals(0, (int) causeBucket.doubleValue());
    Bucket contenuBucket = findBucketsByCategory(buckets, dim, new EntityCategory(2)).get(0);
    assertEquals("contenu du kit", contenuBucket.getCategory(dim).getLabel());
    assertEquals(0, (int) contenuBucket.doubleValue());
}
Also used : Bucket(org.activityinfo.shared.command.result.Bucket) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Example 15 with Bucket

use of org.activityinfo.shared.command.result.Bucket in project activityinfo by bedatadriven.

the class PivotSitesHandlerLocalTest method testLinkedAttributegroupFilterDataForIndicator.

@Test
@OnDataSet("/dbunit/sites-linked.db.xml")
public void testLinkedAttributegroupFilterDataForIndicator() {
    withAttributeGroupDim();
    forFilterData();
    Dimension dim = new Dimension(DimensionType.AttributeGroup);
    // empty
    filter.addRestriction(DimensionType.Indicator, 100);
    execute();
    assertThat().thereAre(0).buckets();
    // cause, contenu du kit
    filter = new Filter();
    filter.addRestriction(DimensionType.Indicator, 1);
    execute();
    assertThat().thereAre(2).buckets();
    Bucket bucket1 = findBucketsByCategory(buckets, dim, new EntityCategory(1)).get(0);
    assertEquals("cause", bucket1.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket1.doubleValue());
    Bucket bucket2 = findBucketsByCategory(buckets, dim, new EntityCategory(2)).get(0);
    assertEquals("contenu du kit", bucket2.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket2.doubleValue());
    // cause
    filter = new Filter();
    filter.addRestriction(DimensionType.Indicator, 2);
    execute();
    assertThat().thereAre(1).buckets();
    bucket1 = findBucketsByCategory(buckets, dim, new EntityCategory(1)).get(0);
    assertEquals("cause", bucket1.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket1.doubleValue());
    // cause, contenu du kit
    filter = new Filter();
    filter.addRestriction(DimensionType.Indicator, Arrays.asList(1, 2, 100));
    execute();
    assertThat().thereAre(2).buckets();
    bucket1 = findBucketsByCategory(buckets, dim, new EntityCategory(1)).get(0);
    assertEquals("cause", bucket1.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket1.doubleValue());
    bucket2 = findBucketsByCategory(buckets, dim, new EntityCategory(2)).get(0);
    assertEquals("contenu du kit", bucket2.getCategory(dim).getLabel());
    assertEquals(0, (int) bucket2.doubleValue());
}
Also used : Bucket(org.activityinfo.shared.command.result.Bucket) Dimension(org.activityinfo.shared.report.model.Dimension) AttributeGroupDimension(org.activityinfo.shared.report.model.AttributeGroupDimension) AdminDimension(org.activityinfo.shared.report.model.AdminDimension) DateDimension(org.activityinfo.shared.report.model.DateDimension) EntityCategory(org.activityinfo.shared.report.content.EntityCategory) OnDataSet(org.activityinfo.server.database.OnDataSet) Test(org.junit.Test)

Aggregations

Bucket (org.activityinfo.shared.command.result.Bucket)16 Dimension (org.activityinfo.shared.report.model.Dimension)11 EntityCategory (org.activityinfo.shared.report.content.EntityCategory)9 AdminDimension (org.activityinfo.shared.report.model.AdminDimension)9 Test (org.junit.Test)8 AttributeGroupDimension (org.activityinfo.shared.report.model.AttributeGroupDimension)6 DateDimension (org.activityinfo.shared.report.model.DateDimension)6 PivotSites (org.activityinfo.shared.command.PivotSites)5 ArrayList (java.util.ArrayList)4 OnDataSet (org.activityinfo.server.database.OnDataSet)4 Comparator (java.util.Comparator)3 List (java.util.List)2 DispatcherSync (org.activityinfo.server.command.DispatcherSync)2 User (org.activityinfo.server.database.hibernate.entity.User)2 CommandException (org.activityinfo.shared.exception.CommandException)2 PivotTableData (org.activityinfo.shared.report.content.PivotTableData)2 PivotTableReportElement (org.activityinfo.shared.report.model.PivotTableReportElement)2 SqlResultCallback (com.bedatadriven.rebar.sql.client.SqlResultCallback)1 SqlResultSet (com.bedatadriven.rebar.sql.client.SqlResultSet)1 SqlResultSetRow (com.bedatadriven.rebar.sql.client.SqlResultSetRow)1