dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09353
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2460: Mapping - Fixed bug NullPointerException. Unit test for MappingServiceTest - working in process...
------------------------------------------------------------
revno: 2460
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-01-04 16:54:15 +0700
message:
Mapping - Fixed bug NullPointerException. Unit test for MappingServiceTest - working in process...
modified:
dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java
dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2010-12-31 05:07:49 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java 2011-01-04 09:54:15 +0000
@@ -627,8 +627,11 @@
{
MapView mapView = mappingStore.getMapView( id );
- mapView.getParentOrganisationUnit().setLevel(
- organisationUnitService.getLevelOfOrganisationUnit( mapView.getParentOrganisationUnit() ) );
+ if ( mapView != null )
+ {
+ mapView.getParentOrganisationUnit().setLevel(
+ organisationUnitService.getLevelOfOrganisationUnit( mapView.getParentOrganisationUnit() ) );
+ }
return mapView;
}
@@ -641,7 +644,7 @@
public Collection<MapView> getAllMapViews()
{
Collection<MapView> mapViews = mappingStore.getAllMapViews();
-
+
if ( mapViews.size() > 0 )
{
for ( MapView mapView : mapViews )
=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java 2010-11-30 13:04:58 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java 2011-01-04 09:54:15 +0000
@@ -28,6 +28,11 @@
*/
import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.dataelement.DataElement;
@@ -66,6 +71,8 @@
private Indicator indicator;
private DataElement dataElement;
+
+ private DataElementGroup dataElementGroup;
private PeriodType periodType;
@@ -107,6 +114,10 @@
dataElement = createDataElement( 'A' );
dataElementService.addDataElement( dataElement );
+
+ dataElementGroup = createDataElementGroup( 'A' );
+ dataElementGroup.getMembers().add( dataElement );
+ dataElementService.addDataElementGroup( dataElementGroup );
periodType = periodService.getPeriodTypeByName( MonthlyPeriodType.NAME );
period = createPeriod( periodType, getDate( 2000, 1, 1 ), getDate( 2000, 2, 1 ) );
@@ -124,8 +135,8 @@
public void testAddGetMapView()
{
MapView mapView = new MapView( "MapViewA", OrganisationUnit.FEATURETYPE_MULTIPOLYGON,
- MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, indicator, new DataElementGroup(),
- new DataElement(), MappingService.MAP_DATE_TYPE_FIXED, periodType, period, "", "", organisationUnit,
+ MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, indicator, dataElementGroup,
+ dataElement, MappingService.MAP_DATE_TYPE_FIXED, periodType, period, "", "", organisationUnit,
organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", mapLegendSet, 5, 20,
"1", "1", 1 );
@@ -138,6 +149,165 @@
assertEquals( period, mappingService.getMapView( idA ).getPeriod() );
}
+ @Test
+ public void testGetDeleteMapViewByName()
+ {
+ MapView mapView = new MapView( "MapViewA", OrganisationUnit.FEATURETYPE_MULTIPOLYGON,
+ MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, indicator, dataElementGroup,
+ dataElement, MappingService.MAP_DATE_TYPE_FIXED, periodType, period, "", "", organisationUnit,
+ organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", mapLegendSet, 5, 20,
+ "1", "1", 1 );
+
+ int id = mappingService.addMapView( mapView );
+
+ mapView = mappingService.getMapViewByName( "MapViewA" );
+
+ mappingService.deleteMapView( mapView );
+
+ assertNull( mappingService.getMapView( id ) );
+ }
+
+ @Test
+ public void testGetAllMapViews()
+ {
+ MapView mapView1 = new MapView( "MapViewA", OrganisationUnit.FEATURETYPE_MULTIPOLYGON,
+ MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, indicator, dataElementGroup,
+ dataElement, MappingService.MAP_DATE_TYPE_FIXED, periodType, period, "", "", organisationUnit,
+ organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", mapLegendSet, 5, 20,
+ "1", "1", 1 );
+
+ MapView mapView2 = new MapView( "MapViewB", OrganisationUnit.FEATURETYPE_POLYGON,
+ MappingService.MAP_VALUE_TYPE_DATAELEMENT, indicatorGroup, indicator, dataElementGroup,
+ dataElement, MappingService.MAP_DATE_TYPE_START_END, periodType, period, "", "", organisationUnit,
+ organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", mapLegendSet, 5, 20,
+ "2", "2", 1 );
+
+ mappingService.addMapView( mapView1 );
+ mappingService.addMapView( mapView2 );
+
+ assertEquals( 2, mappingService.getAllMapViews().size() );
+ }
+
+
+ @Test
+ public void testGetMapViewsByFeatureType()
+ {
+ MapView mapView1 = new MapView( "MapViewA", OrganisationUnit.FEATURETYPE_MULTIPOLYGON,
+ MappingService.MAP_VALUE_TYPE_INDICATOR, indicatorGroup, indicator, dataElementGroup,
+ dataElement, MappingService.MAP_DATE_TYPE_FIXED, periodType, period, "", "", organisationUnit,
+ organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", mapLegendSet, 5, 20,
+ "1", "1", 1 );
+
+ MapView mapView2 = new MapView( "MapViewB", OrganisationUnit.FEATURETYPE_POLYGON,
+ MappingService.MAP_VALUE_TYPE_DATAELEMENT, indicatorGroup, indicator, dataElementGroup,
+ dataElement, MappingService.MAP_DATE_TYPE_START_END, periodType, period, "", "", organisationUnit,
+ organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", mapLegendSet, 5, 20,
+ "2", "2", 1 );
+
+ MapView mapView3 = new MapView( "MapViewC", OrganisationUnit.FEATURETYPE_MULTIPOLYGON,
+ MappingService.MAP_VALUE_TYPE_DATAELEMENT, indicatorGroup, indicator, dataElementGroup,
+ dataElement, MappingService.MAP_DATE_TYPE_START_END, periodType, period, "", "", organisationUnit,
+ organisationUnitLevel, MappingService.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "", "A", "B", mapLegendSet, 5, 20,
+ "3", "3", 1 );
+
+ mappingService.addMapView( mapView1 );
+ mappingService.addMapView( mapView2 );
+ mappingService.addMapView( mapView3 );
+
+ assertEquals( 1, mappingService.getMapViewsByFeatureType( OrganisationUnit.FEATURETYPE_POLYGON ).size() );
+ assertEquals( 2, mappingService.getMapViewsByFeatureType( OrganisationUnit.FEATURETYPE_MULTIPOLYGON ).size() );
+ }
+
+ // -------------------------------------------------------------------------
+ // MapLayer
+ // -------------------------------------------------------------------------
+
+ @Test
+ public void testAddGetMapLayer()
+ {
+ MapLayer mapLayer = new MapLayer( "MapLayerA", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "A", 0.1, "B", 1);
+
+ int id = mappingService.addMapLayer( mapLayer );
+
+ assertEquals( "MapLayerA", mappingService.getMapLayer( id ).getName() );
+ assertEquals( MappingService.MAP_LAYER_TYPE_BASELAYER, mappingService.getMapLayer( id ).getType() );
+ assertEquals( "A", mappingService.getMapLayer( id ).getFillColor() );
+ assertEquals( "B", mappingService.getMapLayer( id ).getStrokeColor() );
+ assertEquals( 0.1, mappingService.getMapLayer( id ).getFillOpacity() );
+ assertEquals( 1, mappingService.getMapLayer( id ).getStrokeWidth() );
+ }
+
+ @Test
+ public void testGetUpdateDeleteMapLayerByName()
+ {
+ MapLayer mapLayer = new MapLayer( "MapLayerA", MappingService.MAP_LAYER_TYPE_BASELAYER, "", "", "A", 0.1, "B", 1);
+
+ int id = mappingService.addMapLayer( mapLayer );
+
+ mapLayer = mappingService.getMapLayer( id );
+
+ mapLayer.setName( "MapLayerB" );
+ mapLayer.setFillOpacity( 0.05 );
+ mapLayer.setStrokeWidth( 0 );
+
+ mappingService.updateMapLayer( mapLayer );
+
+ assertEquals( "MapLayerB", mappingService.getMapLayerByName( "MapLayerB" ).getName() );
+ assertEquals( 0.05, mappingService.getMapLayerByName( "MapLayerB" ).getFillOpacity() );
+ assertEquals( 0, mappingService.getMapLayerByName( "MapLayerB" ).getStrokeWidth() );
+ }
+
+ @Test
+ public void testGetAllMapLayers()
+ {
+ MapLayer mapLayer1 = new MapLayer( "MapLayerA", MappingService.MAP_LAYER_TYPE_BASELAYER, "mapSourceA", "layerA", "A", 0.1, "B", 1);
+ MapLayer mapLayer2 = new MapLayer( "MapLayerB", MappingService.MAP_LAYER_TYPE_OVERLAY, "", "", "A", 0.1, "B", 1);
+ MapLayer mapLayer3 = new MapLayer( "MapLayerC", MappingService.MAP_LAYER_TYPE_OVERLAY, "mapSourceC", "layerC", "C", 0.1, "D", 2);
+ MapLayer mapLayer4 = new MapLayer( "MapLayerD", MappingService.MAP_LAYER_TYPE_BASELAYER, "mapSourceD", "layerA", "C", 0.1, "D", 2);
+
+ int idA = mappingService.addMapLayer( mapLayer1 );
+ int idB = mappingService.addMapLayer( mapLayer2 );
+ int idC = mappingService.addMapLayer( mapLayer3 );
+
+ assertEquals( mapLayer1, mappingService.getMapLayer( idA ) );
+ assertEquals( mapLayer2, mappingService.getMapLayer( idB ) );
+ assertEquals( mapLayer3, mappingService.getMapLayer( idC ) );
+ assertTrue( !mappingService.getAllMapLayers().contains( mapLayer4 ) );
+
+ }
+
+ @Test
+ public void testGetMapLayersByTypeOrMapSource()
+ {
+ List<MapLayer> baseLayers = new ArrayList<MapLayer>();
+ List<MapLayer> overlayLayers = new ArrayList<MapLayer>();
+
+ MapLayer mapLayer1 = new MapLayer( "MapLayerA", MappingService.MAP_LAYER_TYPE_BASELAYER, "mapSourceA", "layerA", "A", 0.1, "B", 1);
+ MapLayer mapLayer2 = new MapLayer( "MapLayerB", MappingService.MAP_LAYER_TYPE_OVERLAY, "mapSourceB", "", "A", 0.1, "B", 1);
+ MapLayer mapLayer3 = new MapLayer( "MapLayerC", MappingService.MAP_LAYER_TYPE_OVERLAY, "mapSourceC", "layerC", "C", 0.1, "D", 2);
+ MapLayer mapLayer4 = new MapLayer( "MapLayerD", MappingService.MAP_LAYER_TYPE_BASELAYER, "mapSourceD", "layerA", "C", 0.1, "D", 2);
+
+ baseLayers.add( mapLayer1 );
+ baseLayers.add( mapLayer4 );
+
+ overlayLayers.add( mapLayer2 );
+ overlayLayers.add( mapLayer3 );
+
+ int idA = mappingService.addMapLayer( mapLayer1 );
+ int idB = mappingService.addMapLayer( mapLayer2 );
+ int idC = mappingService.addMapLayer( mapLayer3 );
+ int idD = mappingService.addMapLayer( mapLayer4 );
+
+ assertEquals( baseLayers, mappingService.getMapLayersByType( MappingService.MAP_LAYER_TYPE_BASELAYER ) );
+ assertEquals( overlayLayers, mappingService.getMapLayersByType( MappingService.MAP_LAYER_TYPE_OVERLAY ) );
+
+ assertEquals( mappingService.getMapLayer( idA ), mappingService.getMapLayerByMapSource( "mapSourceA" ) );
+ assertEquals( mappingService.getMapLayer( idB ), mappingService.getMapLayerByMapSource( "mapSourceB" ) );
+ assertEquals( mappingService.getMapLayer( idC ), mappingService.getMapLayerByMapSource( "mapSourceC" ) );
+ assertEquals( mappingService.getMapLayer( idD ), mappingService.getMapLayerByMapSource( "mapSourceD" ) );
+
+ }
+
// -------------------------------------------------------------------------
// Map value tests
// -------------------------------------------------------------------------