use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.
the class ProjectTest method deleteProject.
@Test
public void deleteProject() {
setUser(1);
long originalDatabaseVersion = lookupDbVersion(1);
int projectId = 2;
execute(RequestChange.delete("Project", projectId));
SchemaDTO schema = execute(new GetSchema());
assertThat(schema.getProjectById(projectId), nullValue());
// make sure it's gone from sites
Filter filter = new Filter();
filter.addRestriction(DimensionType.Site, 3);
SiteResult sites = execute(new GetSites(filter));
assertThat(sites.getData().get(0).getProject(), is(nullValue()));
// and doesn't show up in pivoting...
PivotSites pivot = new PivotSites();
Dimension projectDimension = new Dimension(DimensionType.Project);
pivot.setDimensions(projectDimension);
pivot.setFilter(filter);
PivotResult buckets = execute(pivot);
assertThat(buckets.getBuckets().size(), equalTo(1));
assertThat(buckets.getBuckets().get(0).getCategory(projectDimension), is(nullValue()));
// make sure the version number of the database is updated
assertThat(lookupDbVersion(1), not(equalTo(originalDatabaseVersion)));
}
use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.
the class EmptyChartsTest method generate.
@Test
public void generate() {
PivotChartReportElement element = new PivotChartReportElement(Type.StackedBar);
element.setIndicator(1);
element.addCategoryDimension(new Dimension(DimensionType.Partner));
element.addSeriesDimension(new Dimension(DimensionType.Database));
DispatcherSync dispatcher = createMock(DispatcherSync.class);
expect(dispatcher.execute(isA(PivotSites.class))).andReturn(new PivotSites.PivotResult(Collections.EMPTY_LIST));
expect(dispatcher.execute(isA(GetDimensionLabels.class))).andReturn(new GetDimensionLabels.DimensionLabels(Collections.EMPTY_MAP));
replay(dispatcher);
IndicatorDAO indicatorDAO = createMock(IndicatorDAO.class);
expect(indicatorDAO.findById(eq(1))).andReturn(new Indicator());
replay(indicatorDAO);
PivotChartGenerator generator = new PivotChartGenerator(dispatcher, indicatorDAO);
generator.generate(new User(), element, new Filter(), new DateRange());
}
use of org.activityinfo.shared.report.model.Dimension 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());
}
use of org.activityinfo.shared.report.model.Dimension in project activityinfo by bedatadriven.
the class PieMapMarkerTest method testPies.
@Test
public void testPies() {
Dimension dimension = new Dimension(DimensionType.Indicator);
dimension.setCategoryColor(101, 255);
dimension.setCategoryColor(102, 0x00FF00);
dimension.setCategoryColor(103, 0x0000FF);
SiteDTO site1 = new SiteDTO();
site1.setId(1);
site1.setX(0d);
site1.setY(0d);
site1.setIndicatorValue(101, 50d);
site1.setIndicatorValue(102, 40d);
site1.setIndicatorValue(103, 10d);
List<SiteDTO> sites = new ArrayList<SiteDTO>();
sites.add(site1);
PiechartMapLayer layer = new PiechartMapLayer();
layer.addIndicatorId(101);
layer.addIndicatorId(102);
layer.addIndicatorId(103);
// layer.getColorDimensions().add(dimension);
MapReportElement mapElement = new MapReportElement();
mapElement.addLayer(layer);
MapContent content = new MapContent();
TiledMap map = new TiledMap(640, 480, new AiLatLng(0, 0), 6);
Map<Integer, Indicator> indicators = Maps.newHashMap();
indicators.put(101, new Indicator());
indicators.put(102, new Indicator());
indicators.put(103, new Indicator());
PiechartLayerGenerator generator = new PiechartLayerGenerator(layer, indicators);
generator.setSites(sites);
generator.generate(map, content);
Assert.assertEquals(1, content.getMarkers().size());
PieMapMarker marker = (PieMapMarker) content.getMarkers().get(0);
Assert.assertEquals(3, marker.getSlices().size());
}
use of org.activityinfo.shared.report.model.Dimension 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());
}
Aggregations