← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1705: Changed the association from MapView to MapLegendSet from primitive identifier to object.

 

------------------------------------------------------------
revno: 1705
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-03-26 12:21:37 +0100
message:
  Changed the association from MapView to MapLegendSet from primitive identifier to object.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
  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/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml
  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/MappingStoreTest.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-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java	2010-03-25 18:55:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapLegendSet.java	2010-03-26 11:21:37 +0000
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.HashSet;
 import java.util.Set;
 
 import org.hisp.dhis.indicator.Indicator;
@@ -55,9 +56,9 @@
 
     private String colorHigh;
 
-    private Set<MapLegend> mapLegends;
+    private Set<MapLegend> mapLegends = new HashSet<MapLegend>();
 
-    private Set<Indicator> indicators;
+    private Set<Indicator> indicators = new HashSet<Indicator>();
 
     public MapLegendSet()
     {

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2010-03-25 18:55:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java	2010-03-26 11:21:37 +0000
@@ -70,7 +70,7 @@
 
     private String colorHigh;
 
-    private int mapLegendSetId;
+    private MapLegendSet mapLegendSet;     
 
     private String longitude;
 
@@ -84,7 +84,7 @@
 
     public MapView( String name, IndicatorGroup indicatorGroup, Indicator indicator, PeriodType periodType,
         Period period, String mapSourceType, String mapSource, String mapLegendType, int method, int classes,
-        String colorLow, String colorHigh, int mapLegendSetId, String longitude, String latitude, int zoom )
+        String colorLow, String colorHigh, MapLegendSet mapLegendSet, String longitude, String latitude, int zoom )
     {
         this.name = name;
         this.indicatorGroup = indicatorGroup;
@@ -98,7 +98,7 @@
         this.classes = classes;
         this.colorLow = colorLow;
         this.colorHigh = colorHigh;
-        this.mapLegendSetId = mapLegendSetId;
+        this.mapLegendSet = mapLegendSet;
         this.longitude = longitude;
         this.latitude = latitude;
         this.zoom = zoom;
@@ -272,14 +272,14 @@
         this.colorHigh = colorHigh;
     }
 
-    public int getMapLegendSetId()
+    public MapLegendSet getMapLegendSet()
     {
-        return mapLegendSetId;
+        return mapLegendSet;
     }
 
-    public void setMapLegendSetId( int mapLegendSetId )
+    public void setMapLegendSet( MapLegendSet mapLegendSet )
     {
-        this.mapLegendSetId = mapLegendSetId;
+        this.mapLegendSet = mapLegendSet;
     }
 
     public String getLongitude()

=== 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-03-25 18:55:29 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/java/org/hisp/dhis/mapping/DefaultMappingService.java	2010-03-26 11:21:37 +0000
@@ -663,6 +663,8 @@
 
         Period period = periodService.getPeriod( periodId );
 
+        MapLegendSet mapLegendSet = getMapLegendSet( mapLegendSetId );
+        
         mapView.setName( name );
         mapView.setIndicatorGroup( indicatorGroup );
         mapView.setIndicator( indicator );
@@ -675,7 +677,7 @@
         mapView.setClasses( classes );
         mapView.setColorLow( colorLow );
         mapView.setColorHigh( colorHigh );
-        mapView.setMapLegendSetId( mapLegendSetId );
+        mapView.setMapLegendSet( mapLegendSet );
         mapView.setLongitude( longitude );
         mapView.setLatitude( latitude );
         mapView.setZoom( zoom );
@@ -701,6 +703,8 @@
 
         Period period = periodService.getPeriod( periodId );
 
+        MapLegendSet mapLegendSet = getMapLegendSet( mapLegendSetId );
+        
         String mapSourceType = (String) userSettingService
             .getUserSetting( KEY_MAP_SOURCE_TYPE, MAP_SOURCE_TYPE_GEOJSON );
 
@@ -720,7 +724,7 @@
             mapView.setClasses( classes );
             mapView.setColorLow( colorLow );
             mapView.setColorHigh( colorHigh );
-            mapView.setMapLegendSetId( mapLegendSetId );
+            mapView.setMapLegendSet( mapLegendSet );
             mapView.setLongitude( longitude );
             mapView.setLatitude( latitude );
             mapView.setZoom( zoom );
@@ -730,7 +734,7 @@
         else
         {
             mapView = new MapView( name, indicatorGroup, indicator, periodType, period, mapSourceType, mapSource,
-                mapLegendType, method, classes, colorLow, colorHigh, mapLegendSetId, longitude, latitude, zoom );
+                mapLegendType, method, classes, colorLow, colorHigh, mapLegendSet, longitude, latitude, zoom );
 
             addMapView( mapView );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml'
--- dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml	2010-03-25 18:55:29 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/main/resources/org/hisp/dhis/mapping/hibernate/MapView.hbm.xml	2010-03-26 11:21:37 +0000
@@ -39,7 +39,8 @@
 			
 		<property name="colorHigh"/>
 		
-		<property name="mapLegendSetId"/>
+		<many-to-one name="mapLegendSet" class="org.hisp.dhis.mapping.MapLegendSet"
+			column="maplegendsetid" foreign-key="fk_mapview_maplegendsetid"/>
 		
 		<property name="longitude"/>
         

=== 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-03-25 18:55:29 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingServiceTest.java	2010-03-26 11:21:37 +0000
@@ -49,171 +49,175 @@
  * @author Lars Helge Overland
  * @version $Id$
  */
-public class MappingServiceTest extends DhisSpringTest {
-	private MappingService mappingService;
-
-	private OrganisationUnit organisationUnit;
-
-	private OrganisationUnitLevel organisationUnitLevel;
-
-	private IndicatorGroup indicatorGroup;
-	private IndicatorType indicatorType;
-	private Indicator indicator;
-
-	private PeriodType periodType;
-	private Period period;
-
-	private Map mapA;
-	private Map mapB;
-
-	private MapOrganisationUnitRelation mapOrganisationUnitRelationA;
-	private MapOrganisationUnitRelation mapOrganisationUnitRelationB;
-
-	// -------------------------------------------------------------------------
-	// Fixture
-	// -------------------------------------------------------------------------
-
-	@Override
-	public void setUpTest() {
-		mappingService = (MappingService) getBean(MappingService.ID);
-
-		organisationUnitService = (OrganisationUnitService) getBean(OrganisationUnitService.ID);
-
-		indicatorService = (IndicatorService) getBean(IndicatorService.ID);
-
-		periodService = (PeriodService) getBean(PeriodService.ID);
-
-		organisationUnit = createOrganisationUnit('A');
-		organisationUnitLevel = new OrganisationUnitLevel(1, "Level");
-
-		organisationUnitService.addOrganisationUnit(organisationUnit);
-		organisationUnitService.addOrganisationUnitLevel(organisationUnitLevel);
-
-		mapA = createMap('A', organisationUnit, organisationUnitLevel);
-		mapB = createMap('B', organisationUnit, organisationUnitLevel);
-
-		mapOrganisationUnitRelationA = new MapOrganisationUnitRelation(mapA,
-				organisationUnit, "Feature");
-		mapOrganisationUnitRelationB = new MapOrganisationUnitRelation(mapB,
-				organisationUnit, "Feature");
-
-		indicatorGroup = createIndicatorGroup('A');
-		indicatorService.addIndicatorGroup(indicatorGroup);
-
-		indicatorType = createIndicatorType('A');
-		indicatorService.addIndicatorType(indicatorType);
-
-		indicator = createIndicator('A', indicatorType);
-		indicatorService.addIndicator(indicator);
-
-		periodType = periodService.getPeriodTypeByName(MonthlyPeriodType.NAME);
-		period = createPeriod(periodType, getDate(2000, 1, 1), getDate(2000, 2,
-				1));
-		periodService.addPeriod(period);
-	}
-
-	// -------------------------------------------------------------------------
-	// Map tests
-	// -------------------------------------------------------------------------
-
-	@Test
-	public void testAddGetMap() {
-		int idA = mappingService.addMap(mapA);
-		int idB = mappingService.addMap(mapB);
-
-		assertEquals(mapA, mappingService.getMap(idA));
-		assertEquals(mapB, mappingService.getMap(idB));
-	}
-
-	@Test
-	public void testDeleteMap() {
-		int idA = mappingService.addMap(mapA);
-		int idB = mappingService.addMap(mapB);
-
-		mappingService
-				.addMapOrganisationUnitRelation(mapOrganisationUnitRelationA);
-		mappingService
-				.addMapOrganisationUnitRelation(mapOrganisationUnitRelationB);
-
-		assertNotNull(mappingService.getMap(idA));
-		assertNotNull(mappingService.getMap(idB));
-
-		mappingService.deleteMap(mapA);
-
-		assertNull(mappingService.getMap(idA));
-		assertNotNull(mappingService.getMap(idB));
-
-		mappingService.deleteMap(mapB);
-
-		assertNull(mappingService.getMap(idA));
-		assertNull(mappingService.getMap(idB));
-	}
-
-	// -------------------------------------------------------------------------
-	// MapOrganisationUnitRelation tests
-	// -------------------------------------------------------------------------
-
-	@Test
-	public void addGetMapOrganisationUnitRelation() {
-		mappingService.addMap(mapA);
-		mappingService.addMap(mapB);
-
-		int idA = mappingService
-				.addMapOrganisationUnitRelation(mapOrganisationUnitRelationA);
-		int idB = mappingService
-				.addMapOrganisationUnitRelation(mapOrganisationUnitRelationB);
-
-		assertEquals(mappingService.getMapOrganisationUnitRelation(idA),
-				mapOrganisationUnitRelationA);
-		assertEquals(mappingService.getMapOrganisationUnitRelation(idB),
-				mapOrganisationUnitRelationB);
-	}
-
-	@Test
-	public void deleteMapOrganisationUnitRelation() {
-		mappingService.addMap(mapA);
-		mappingService.addMap(mapB);
-
-		int idA = mappingService
-				.addMapOrganisationUnitRelation(mapOrganisationUnitRelationA);
-		int idB = mappingService
-				.addMapOrganisationUnitRelation(mapOrganisationUnitRelationB);
-
-		assertNotNull(mappingService.getMapOrganisationUnitRelation(idA));
-		assertNotNull(mappingService.getMapOrganisationUnitRelation(idB));
-
-		mappingService
-				.deleteMapOrganisationUnitRelation(mapOrganisationUnitRelationA);
-
-		assertNull(mappingService.getMapOrganisationUnitRelation(idA));
-		assertNotNull(mappingService.getMapOrganisationUnitRelation(idB));
-
-		mappingService
-				.deleteMapOrganisationUnitRelation(mapOrganisationUnitRelationB);
-
-		assertNull(mappingService.getMapOrganisationUnitRelation(idA));
-		assertNull(mappingService.getMapOrganisationUnitRelation(idB));
-	}
-
-	// -------------------------------------------------------------------------
-	// MapView tests
-	// -------------------------------------------------------------------------
-
-	@Test
-	public void testAddGetMapView() {
-		mappingService.addMap(mapA);
-
-		MapView mapView = new MapView("MapViewA", indicatorGroup, indicator,
-				periodType, period, MapView.MAP_SOURCE_TYPE_SHAPEFILE,
-				"sl_districts", MapLegendSet.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "A", "B", 1, "1", "1", 1);
-
-		int idA = mappingService.addMapView(mapView);
-
-		assertEquals(mapView, mappingService.getMapView(idA));
-		assertEquals(indicatorGroup, mappingService.getMapView(idA)
-				.getIndicatorGroup());
-		assertEquals(indicator, mappingService.getMapView(idA).getIndicator());
-		assertEquals(periodType, mappingService.getMapView(idA).getPeriodType());
-		assertEquals(period, mappingService.getMapView(idA).getPeriod());
-	}
+public class MappingServiceTest
+    extends DhisSpringTest
+{
+    private MappingService mappingService;
+
+    private OrganisationUnit organisationUnit;
+
+    private OrganisationUnitLevel organisationUnitLevel;
+
+    private IndicatorGroup indicatorGroup;
+
+    private IndicatorType indicatorType;
+
+    private Indicator indicator;
+
+    private PeriodType periodType;
+
+    private Period period;
+    
+    private MapLegendSet mapLegendSet;
+    
+    private Map mapA;
+
+    private Map mapB;
+
+    private MapOrganisationUnitRelation mapOrganisationUnitRelationA;
+
+    private MapOrganisationUnitRelation mapOrganisationUnitRelationB;
+
+    // -------------------------------------------------------------------------
+    // Fixture
+    // -------------------------------------------------------------------------
+
+    @Override
+    public void setUpTest()
+    {
+        mappingService = (MappingService) getBean( MappingService.ID );
+
+        organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
+
+        indicatorService = (IndicatorService) getBean( IndicatorService.ID );
+
+        periodService = (PeriodService) getBean( PeriodService.ID );
+
+        organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitLevel = new OrganisationUnitLevel( 1, "Level" );
+
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+        organisationUnitService.addOrganisationUnitLevel( organisationUnitLevel );
+
+        mapA = createMap( 'A', organisationUnit, organisationUnitLevel );
+        mapB = createMap( 'B', organisationUnit, organisationUnitLevel );
+
+        mapOrganisationUnitRelationA = new MapOrganisationUnitRelation( mapA, organisationUnit, "Feature" );
+        mapOrganisationUnitRelationB = new MapOrganisationUnitRelation( mapB, organisationUnit, "Feature" );
+
+        indicatorGroup = createIndicatorGroup( 'A' );
+        indicatorService.addIndicatorGroup( indicatorGroup );
+
+        indicatorType = createIndicatorType( 'A' );
+        indicatorService.addIndicatorType( indicatorType );
+
+        indicator = createIndicator( 'A', indicatorType );
+        indicatorService.addIndicator( indicator );
+
+        periodType = periodService.getPeriodTypeByName( MonthlyPeriodType.NAME );
+        period = createPeriod( periodType, getDate( 2000, 1, 1 ), getDate( 2000, 2, 1 ) );
+        periodService.addPeriod( period );        
+
+        mapLegendSet = createMapLegendSet( 'A', indicator );        
+        mappingService.addMapLegendSet( mapLegendSet );
+    }
+
+    // -------------------------------------------------------------------------
+    // Map tests
+    // -------------------------------------------------------------------------
+
+    @Test
+    public void testAddGetMap()
+    {
+        int idA = mappingService.addMap( mapA );
+        int idB = mappingService.addMap( mapB );
+
+        assertEquals( mapA, mappingService.getMap( idA ) );
+        assertEquals( mapB, mappingService.getMap( idB ) );
+    }
+
+    @Test
+    public void testDeleteMap()
+    {
+        int idA = mappingService.addMap( mapA );
+        int idB = mappingService.addMap( mapB );
+
+        mappingService.addMapOrganisationUnitRelation( mapOrganisationUnitRelationA );
+        mappingService.addMapOrganisationUnitRelation( mapOrganisationUnitRelationB );
+
+        assertNotNull( mappingService.getMap( idA ) );
+        assertNotNull( mappingService.getMap( idB ) );
+
+        mappingService.deleteMap( mapA );
+
+        assertNull( mappingService.getMap( idA ) );
+        assertNotNull( mappingService.getMap( idB ) );
+
+        mappingService.deleteMap( mapB );
+
+        assertNull( mappingService.getMap( idA ) );
+        assertNull( mappingService.getMap( idB ) );
+    }
+
+    // -------------------------------------------------------------------------
+    // MapOrganisationUnitRelation tests
+    // -------------------------------------------------------------------------
+
+    @Test
+    public void addGetMapOrganisationUnitRelation()
+    {
+        mappingService.addMap( mapA );
+        mappingService.addMap( mapB );
+
+        int idA = mappingService.addMapOrganisationUnitRelation( mapOrganisationUnitRelationA );
+        int idB = mappingService.addMapOrganisationUnitRelation( mapOrganisationUnitRelationB );
+
+        assertEquals( mappingService.getMapOrganisationUnitRelation( idA ), mapOrganisationUnitRelationA );
+        assertEquals( mappingService.getMapOrganisationUnitRelation( idB ), mapOrganisationUnitRelationB );
+    }
+
+    @Test
+    public void deleteMapOrganisationUnitRelation()
+    {
+        mappingService.addMap( mapA );
+        mappingService.addMap( mapB );
+
+        int idA = mappingService.addMapOrganisationUnitRelation( mapOrganisationUnitRelationA );
+        int idB = mappingService.addMapOrganisationUnitRelation( mapOrganisationUnitRelationB );
+
+        assertNotNull( mappingService.getMapOrganisationUnitRelation( idA ) );
+        assertNotNull( mappingService.getMapOrganisationUnitRelation( idB ) );
+
+        mappingService.deleteMapOrganisationUnitRelation( mapOrganisationUnitRelationA );
+
+        assertNull( mappingService.getMapOrganisationUnitRelation( idA ) );
+        assertNotNull( mappingService.getMapOrganisationUnitRelation( idB ) );
+
+        mappingService.deleteMapOrganisationUnitRelation( mapOrganisationUnitRelationB );
+
+        assertNull( mappingService.getMapOrganisationUnitRelation( idA ) );
+        assertNull( mappingService.getMapOrganisationUnitRelation( idB ) );
+    }
+
+    // -------------------------------------------------------------------------
+    // MapView tests
+    // -------------------------------------------------------------------------
+
+    @Test
+    public void testAddGetMapView()
+    {
+        mappingService.addMap( mapA );
+
+        MapView mapView = new MapView( "MapViewA", indicatorGroup, indicator, periodType, period,
+            MapView.MAP_SOURCE_TYPE_SHAPEFILE, "sl_districts", MapLegendSet.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "A",
+            "B", mapLegendSet, "1", "1", 1 );
+
+        int idA = mappingService.addMapView( mapView );
+
+        assertEquals( mapView, mappingService.getMapView( idA ) );
+        assertEquals( indicatorGroup, mappingService.getMapView( idA ).getIndicatorGroup() );
+        assertEquals( indicator, mappingService.getMapView( idA ).getIndicator() );
+        assertEquals( periodType, mappingService.getMapView( idA ).getPeriodType() );
+        assertEquals( period, mappingService.getMapView( idA ).getPeriod() );
+    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingStoreTest.java'
--- dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingStoreTest.java	2010-03-25 18:55:29 +0000
+++ dhis-2/dhis-services/dhis-service-mapping/src/test/java/org/hisp/dhis/mapping/MappingStoreTest.java	2010-03-26 11:21:37 +0000
@@ -49,112 +49,125 @@
  * @author Lars Helge Overland
  * @version $Id$
  */
-public class MappingStoreTest extends DhisSpringTest {
-	private MappingStore mappingStore;
-
-	private OrganisationUnit organisationUnit;
-
-	private OrganisationUnitLevel organisationUnitLevel;
-
-	private IndicatorGroup indicatorGroup;
-	private IndicatorType indicatorType;
-	private Indicator indicator;
-
-	private PeriodType periodType;
-	private Period period;
-
-	private Map mapA;
-	private Map mapB;
-
-	// -------------------------------------------------------------------------
-	// Fixture
-	// -------------------------------------------------------------------------
-
-	@Override
-	public void setUpTest() {
-		mappingStore = (MappingStore) getBean(MappingStore.ID);
-
-		organisationUnitService = (OrganisationUnitService) getBean(OrganisationUnitService.ID);
-
-		indicatorService = (IndicatorService) getBean(IndicatorService.ID);
-
-		periodService = (PeriodService) getBean(PeriodService.ID);
-
-		organisationUnit = createOrganisationUnit('A');
-		organisationUnitLevel = new OrganisationUnitLevel(1, "Level");
-
-		organisationUnitService.addOrganisationUnit(organisationUnit);
-		organisationUnitService.addOrganisationUnitLevel(organisationUnitLevel);
-
-		mapA = createMap('A', organisationUnit, organisationUnitLevel);
-		mapB = createMap('B', organisationUnit, organisationUnitLevel);
-
-		indicatorGroup = createIndicatorGroup('A');
-		indicatorService.addIndicatorGroup(indicatorGroup);
-
-		indicatorType = createIndicatorType('A');
-		indicatorService.addIndicatorType(indicatorType);
-
-		indicator = createIndicator('A', indicatorType);
-		indicatorService.addIndicator(indicator);
-
-		periodType = periodService.getPeriodTypeByName(MonthlyPeriodType.NAME);
-		period = createPeriod(periodType, getDate(2000, 1, 1), getDate(2000, 2,
-				1));
-		periodService.addPeriod(period);
-	}
-
-	// -------------------------------------------------------------------------
-	// Map tests
-	// -------------------------------------------------------------------------
-
-	@Test
-	public void testAddGetMap() {
-		int idA = mappingStore.addMap(mapA);
-		int idB = mappingStore.addMap(mapB);
-
-		assertEquals(mapA, mappingStore.getMap(idA));
-		assertEquals(mapB, mappingStore.getMap(idB));
-	}
-
-	@Test
-	public void testDeleteMap() {
-		int idA = mappingStore.addMap(mapA);
-		int idB = mappingStore.addMap(mapB);
-
-		assertNotNull(mappingStore.getMap(idA));
-		assertNotNull(mappingStore.getMap(idB));
-
-		mappingStore.deleteMap(mapA);
-
-		assertNull(mappingStore.getMap(idA));
-		assertNotNull(mappingStore.getMap(idB));
-
-		mappingStore.deleteMap(mapB);
-
-		assertNull(mappingStore.getMap(idA));
-		assertNull(mappingStore.getMap(idB));
-	}
-
-	// -------------------------------------------------------------------------
-	// MapView tests
-	// -------------------------------------------------------------------------
-
-	@Test
-	public void testAddGetMapView() {
-		mappingStore.addMap(mapA);
-
-		MapView mapView = new MapView("MapViewA", indicatorGroup, indicator,
-				periodType, period, MapView.MAP_SOURCE_TYPE_SHAPEFILE,
-				"sl_districts", MapLegendSet.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "A", "B", 1, "1", "1", 1);
-
-		int idA = mappingStore.addMapView(mapView);
-
-		assertEquals(mapView, mappingStore.getMapView(idA));
-		assertEquals(indicatorGroup, mappingStore.getMapView(idA)
-				.getIndicatorGroup());
-		assertEquals(indicator, mappingStore.getMapView(idA).getIndicator());
-		assertEquals(periodType, mappingStore.getMapView(idA).getPeriodType());
-		assertEquals(period, mappingStore.getMapView(idA).getPeriod());
-	}
+public class MappingStoreTest
+    extends DhisSpringTest
+{
+    private MappingStore mappingStore;
+
+    private OrganisationUnit organisationUnit;
+
+    private OrganisationUnitLevel organisationUnitLevel;
+
+    private IndicatorGroup indicatorGroup;
+
+    private IndicatorType indicatorType;
+
+    private Indicator indicator;
+
+    private PeriodType periodType;
+
+    private Period period;
+
+    private MapLegendSet mapLegendSet;
+    
+    private Map mapA;
+
+    private Map mapB;
+
+    // -------------------------------------------------------------------------
+    // Fixture
+    // -------------------------------------------------------------------------
+
+    @Override
+    public void setUpTest()
+    {
+        mappingStore = (MappingStore) getBean( MappingStore.ID );
+
+        organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
+
+        indicatorService = (IndicatorService) getBean( IndicatorService.ID );
+
+        periodService = (PeriodService) getBean( PeriodService.ID );
+
+        organisationUnit = createOrganisationUnit( 'A' );
+        organisationUnitLevel = new OrganisationUnitLevel( 1, "Level" );
+
+        organisationUnitService.addOrganisationUnit( organisationUnit );
+        organisationUnitService.addOrganisationUnitLevel( organisationUnitLevel );
+
+        mapA = createMap( 'A', organisationUnit, organisationUnitLevel );
+        mapB = createMap( 'B', organisationUnit, organisationUnitLevel );
+
+        indicatorGroup = createIndicatorGroup( 'A' );
+        indicatorService.addIndicatorGroup( indicatorGroup );
+
+        indicatorType = createIndicatorType( 'A' );
+        indicatorService.addIndicatorType( indicatorType );
+
+        indicator = createIndicator( 'A', indicatorType );
+        indicatorService.addIndicator( indicator );
+
+        periodType = periodService.getPeriodTypeByName( MonthlyPeriodType.NAME );
+        period = createPeriod( periodType, getDate( 2000, 1, 1 ), getDate( 2000, 2, 1 ) );
+        periodService.addPeriod( period );
+        
+        mapLegendSet = createMapLegendSet( 'A', indicator );        
+        mappingStore.addMapLegendSet( mapLegendSet );
+    }
+
+    // -------------------------------------------------------------------------
+    // Map tests
+    // -------------------------------------------------------------------------
+
+    @Test
+    public void testAddGetMap()
+    {
+        int idA = mappingStore.addMap( mapA );
+        int idB = mappingStore.addMap( mapB );
+
+        assertEquals( mapA, mappingStore.getMap( idA ) );
+        assertEquals( mapB, mappingStore.getMap( idB ) );
+    }
+
+    @Test
+    public void testDeleteMap()
+    {
+        int idA = mappingStore.addMap( mapA );
+        int idB = mappingStore.addMap( mapB );
+
+        assertNotNull( mappingStore.getMap( idA ) );
+        assertNotNull( mappingStore.getMap( idB ) );
+
+        mappingStore.deleteMap( mapA );
+
+        assertNull( mappingStore.getMap( idA ) );
+        assertNotNull( mappingStore.getMap( idB ) );
+
+        mappingStore.deleteMap( mapB );
+
+        assertNull( mappingStore.getMap( idA ) );
+        assertNull( mappingStore.getMap( idB ) );
+    }
+
+    // -------------------------------------------------------------------------
+    // MapView tests
+    // -------------------------------------------------------------------------
+
+    @Test
+    public void testAddGetMapView()
+    {
+        mappingStore.addMap( mapA );
+
+        MapView mapView = new MapView( "MapViewA", indicatorGroup, indicator, periodType, period,
+            MapView.MAP_SOURCE_TYPE_SHAPEFILE, "sl_districts", MapLegendSet.MAPLEGENDSET_TYPE_AUTOMATIC, 1, 1, "A",
+            "B", mapLegendSet, "1", "1", 1 );
+
+        int idA = mappingStore.addMapView( mapView );
+
+        assertEquals( mapView, mappingStore.getMapView( idA ) );
+        assertEquals( indicatorGroup, mappingStore.getMapView( idA ).getIndicatorGroup() );
+        assertEquals( indicator, mappingStore.getMapView( idA ).getIndicator() );
+        assertEquals( periodType, mappingStore.getMapView( idA ).getPeriodType() );
+        assertEquals( period, mappingStore.getMapView( idA ).getPeriod() );
+    }
 }
\ No newline at end of file