PageRenderTime 29ms CodeModel.GetById 19ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/server/report/generator/map/BubbleGeneratorTest.java

http://sigma-h.googlecode.com/
Java | 120 lines | 83 code | 30 blank | 7 comment | 0 complexity | 5a428cd0c509336c79cd7583afd77492 MD5 | raw file
  1/*
  2 * All Sigmah code is released under the GNU General Public License v3
  3 * See COPYRIGHT.txt and LICENSE.txt.
  4 */
  5
  6package org.sigmah.server.report.generator.map;
  7
  8import org.junit.Assert;
  9import org.junit.Test;
 10import org.sigmah.shared.dao.SiteTableColumn;
 11import org.sigmah.server.domain.SiteData;
 12import org.sigmah.shared.report.content.BubbleMapMarker;
 13import org.sigmah.shared.report.content.LatLng;
 14import org.sigmah.shared.report.content.MapContent;
 15import org.sigmah.shared.report.model.*;
 16
 17import java.util.ArrayList;
 18import java.util.List;
 19/*
 20 * @author Alex Bertram
 21 */
 22public class BubbleGeneratorTest {
 23
 24
 25    @Test
 26    public void testColorByIndicators() {
 27
 28        MapElement element = new MapElement();
 29
 30        BubbleMapLayer layer = new BubbleMapLayer();
 31        layer.setClustered(true);
 32        layer.addIndicator(101);
 33        layer.addIndicator(102);
 34
 35        Dimension dim = new Dimension(DimensionType.Indicator);
 36        dim.setProperties(101, CategoryProperties.Color(0, 0, 255));
 37        dim.setProperties(102, CategoryProperties.Color(0, 0, 0));
 38        layer.getColorDimensions().add(dim);
 39
 40        List<SiteData> sites = new ArrayList<SiteData>();
 41
 42        SiteData site1 = new SiteData();
 43        site1.setValue(SiteTableColumn.id, 1) ;
 44        site1.setValue(SiteTableColumn.x, 29.3 );
 45        site1.setValue(SiteTableColumn.y, -1.5);
 46        site1.indicatorValues.put(101, 35.0);
 47        site1.indicatorValues.put(102, 55.0);
 48        sites.add(site1);
 49
 50        element.addLayer(layer);
 51
 52        TiledMap map = new TiledMap(640, 480, new LatLng(-1.5, 29.3), 9);
 53
 54        MapContent content = new MapContent();
 55
 56        BubbleLayerGenerator gtor = new BubbleLayerGenerator(element, layer);
 57        gtor.generate(sites, map, content);
 58
 59        Assert.assertEquals("marker count", 2, content.getMarkers().size());
 60        Assert.assertEquals(255, ((BubbleMapMarker) content.getMarkers().get(0)).getColor());
 61        Assert.assertEquals(0, ((BubbleMapMarker) content.getMarkers().get(1)).getColor());
 62        Assert.assertTrue(((BubbleMapMarker) content.getMarkers().get(0)).getRadius() >= layer.getMinRadius());
 63    }
 64
 65    @Test
 66    public void testColorByPartner() {
 67
 68        MapElement element = new MapElement();
 69
 70        BubbleMapLayer layer = new BubbleMapLayer();
 71        layer.setClustered(true);
 72        layer.addIndicator(101);
 73
 74        Dimension dim = new Dimension(DimensionType.Partner);
 75        dim.setProperties(301, CategoryProperties.Color(0, 0, 255));
 76        dim.setProperties(302, CategoryProperties.Color(0, 0, 0));
 77        layer.getColorDimensions().add(dim);
 78
 79        List<SiteData> sites = new ArrayList<SiteData>();
 80
 81        SiteData site1 = new SiteData();
 82        site1.setValue(SiteTableColumn.id, 1) ;
 83        site1.setValue(SiteTableColumn.partner_id, 301);
 84        site1.setValue(SiteTableColumn.x, 29.3 );
 85        site1.setValue(SiteTableColumn.y, -1.5);
 86        site1.indicatorValues.put(101, 35.0);
 87        sites.add(site1);
 88
 89        SiteData site2 = new SiteData();
 90        site2.setValue(SiteTableColumn.id, 2) ;
 91        site2.setValue(SiteTableColumn.partner_id, 302);
 92        site2.setValue(SiteTableColumn.x, 29.3 );
 93        site2.setValue(SiteTableColumn.y, -1.5);
 94        site2.indicatorValues.put(101, 70.0);
 95        sites.add(site2);
 96
 97        SiteData site3 = new SiteData();
 98        site3.setValue(SiteTableColumn.id, 3) ;
 99        site3.setValue(SiteTableColumn.partner_id, 302);
100        site3.setValue(SiteTableColumn.x, 29.3 );
101        site3.setValue(SiteTableColumn.y, -1.5);
102        site3.indicatorValues.put(101, 100.0);
103        sites.add(site3);
104
105        element.addLayer(layer);
106
107        TiledMap map = new TiledMap(640, 480, new LatLng(-1.5, 29.3), 9);
108
109        MapContent content = new MapContent();
110
111        BubbleLayerGenerator gtor = new BubbleLayerGenerator(element, layer);
112        gtor.generate(sites, map, content);
113
114        Assert.assertEquals("marker count", 2, content.getMarkers().size());
115        Assert.assertEquals(255, ((BubbleMapMarker) content.getMarkers().get(0)).getColor());
116        Assert.assertEquals(0, ((BubbleMapMarker) content.getMarkers().get(1)).getColor());
117    }
118
119
120}