Search in sources :

Example 1 with TableElement

use of org.activityinfo.legacy.shared.reports.model.TableElement in project activityinfo by bedatadriven.

the class TableGeneratorTest method simpleTable.

@Test
public void simpleTable() {
    TableElement table = new TableElement();
    TableColumn column = new TableColumn("Location", "location.name");
    table.addColumn(column);
    TableGenerator gtor = new TableGenerator(createDispatcher(), null);
    gtor.generate(user, table, null, null);
    Assert.assertNotNull("content is set", table.getContent());
    TableData data = table.getContent().getData();
    List<SiteDTO> rows = data.getRows();
    Assert.assertEquals("row count", 1, rows.size());
    SiteDTO row = rows.get(0);
    assertThat((String) row.get(column.getSitePropertyName()), equalTo("tampa bay"));
}
Also used : SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) TableData(org.activityinfo.legacy.shared.reports.content.TableData) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) TableElement(org.activityinfo.legacy.shared.reports.model.TableElement) Test(org.junit.Test)

Example 2 with TableElement

use of org.activityinfo.legacy.shared.reports.model.TableElement in project activityinfo by bedatadriven.

the class TableGeneratorTest method testMap.

// 
// @Test
// public void tableWithMap() {
// 
// MapReportElement map = new MapReportElement();
// map.setBaseMapId(GoogleBaseMap.ROADMAP.getId());
// 
// BubbleMapLayer layer = new BubbleMapLayer();
// layer.addIndicator(INDICATOR_ID);
// map.addLayer(layer);
// 
// TableElement table = new TableElement();
// table.setMap(map);
// 
// TableColumn column = new TableColumn("Location", "location.name");
// table.addColumn(column);
// 
// TableColumn mapColumn = new TableColumn("Map", "map");
// table.addColumn(mapColumn);
// 
// DispatcherSync dispatcher = createDispatcher();
// TableGenerator gtor = new TableGenerator(dispatcher, new
// MapGenerator(dispatcher, null, null));
// gtor.generate(user, table, null, null);
// 
// Assert.assertNotNull("content is set", table.getContent());
// 
// TableData data = table.getContent().getData();
// List<SiteDTO> rows = data.getRows();
// Assert.assertEquals("row count", 1, rows.size());
// 
// SiteDTO row = rows.get(0);
// assertThat((String)row.get(column.getSitePropertyName()),
// equalTo("tampa bay"));
// assertThat((String)row.get("map"), equalTo("1"));
// }
@Test
public void testMap() {
    TableElement table = new TableElement();
    table.addColumn(new TableColumn("Index", "map"));
    table.addColumn(new TableColumn("Site", "location.name"));
    MapReportElement map = new MapReportElement();
    map.setBaseMapId("map1");
    CircledMapLayer layer = new BubbleMapLayer();
    layer.setLabelSequence(new ArabicNumberSequence());
    map.addLayer(layer);
    table.setMap(map);
    DispatcherSync dispatcher = createMock(DispatcherSync.class);
    expect(dispatcher.execute(isA(GetSites.class))).andReturn(new SiteResult(dummySite())).anyTimes();
    TileBaseMap baseMap1 = new TileBaseMap();
    baseMap1.setId("map1");
    baseMap1.setMinZoom(0);
    baseMap1.setMaxZoom(12);
    baseMap1.setCopyright("(C)");
    baseMap1.setName("Grand Canyon");
    baseMap1.setTileUrlPattern("http://s/test.png");
    expect(dispatcher.execute(isA(GetBaseMaps.class))).andReturn(new BaseMapResult(Collections.singletonList(baseMap1)));
    replay(dispatcher);
    TableGenerator gtor = new TableGenerator(dispatcher, new MapGenerator(dispatcher, new MockIndicatorDAO()));
    gtor.generate(user, table, null, null);
    MapContent mapContent = map.getContent();
    Assert.assertNotNull("map content", mapContent);
    Assert.assertEquals("marker count", 1, mapContent.getMarkers().size());
    Assert.assertEquals("label on marker", "1", ((BubbleMapMarker) mapContent.getMarkers().get(0)).getLabel());
    Map<Integer, String> siteLabels = mapContent.siteLabelMap();
    Assert.assertEquals("site id in map", "1", siteLabels.get(1));
    SiteDTO row = table.getContent().getData().getRows().get(0);
    Assert.assertEquals("label on row", "1", row.get("map"));
}
Also used : ArabicNumberSequence(org.activityinfo.legacy.shared.reports.model.labeling.ArabicNumberSequence) MapContent(org.activityinfo.legacy.shared.reports.content.MapContent) BaseMapResult(org.activityinfo.legacy.shared.command.result.BaseMapResult) BubbleMapLayer(org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer) TableColumn(org.activityinfo.legacy.shared.reports.model.TableColumn) TableElement(org.activityinfo.legacy.shared.reports.model.TableElement) MapReportElement(org.activityinfo.legacy.shared.reports.model.MapReportElement) SiteResult(org.activityinfo.legacy.shared.command.result.SiteResult) TileBaseMap(org.activityinfo.legacy.shared.model.TileBaseMap) CircledMapLayer(org.activityinfo.legacy.shared.reports.model.layers.CircledMapLayer) GetBaseMaps(org.activityinfo.legacy.shared.command.GetBaseMaps) SiteDTO(org.activityinfo.legacy.shared.model.SiteDTO) DispatcherSync(org.activityinfo.server.command.DispatcherSync) Test(org.junit.Test)

Aggregations

SiteDTO (org.activityinfo.legacy.shared.model.SiteDTO)2 TableColumn (org.activityinfo.legacy.shared.reports.model.TableColumn)2 TableElement (org.activityinfo.legacy.shared.reports.model.TableElement)2 Test (org.junit.Test)2 GetBaseMaps (org.activityinfo.legacy.shared.command.GetBaseMaps)1 BaseMapResult (org.activityinfo.legacy.shared.command.result.BaseMapResult)1 SiteResult (org.activityinfo.legacy.shared.command.result.SiteResult)1 TileBaseMap (org.activityinfo.legacy.shared.model.TileBaseMap)1 MapContent (org.activityinfo.legacy.shared.reports.content.MapContent)1 TableData (org.activityinfo.legacy.shared.reports.content.TableData)1 MapReportElement (org.activityinfo.legacy.shared.reports.model.MapReportElement)1 ArabicNumberSequence (org.activityinfo.legacy.shared.reports.model.labeling.ArabicNumberSequence)1 BubbleMapLayer (org.activityinfo.legacy.shared.reports.model.layers.BubbleMapLayer)1 CircledMapLayer (org.activityinfo.legacy.shared.reports.model.layers.CircledMapLayer)1 DispatcherSync (org.activityinfo.server.command.DispatcherSync)1