dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #10062
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2746: Added a new test method for DataSetServiceTest.
------------------------------------------------------------
revno: 2746
committer: Hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-01-25 23:52:21 +0700
message:
Added a new test method for DataSetServiceTest.
modified:
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.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-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java 2010-08-30 13:04:39 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataset/DataSetServiceTest.java 2011-01-25 16:52:21 +0000
@@ -32,10 +32,13 @@
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.PeriodType;
@@ -59,8 +62,10 @@
{
dataSetService = (DataSetService) getBean( DataSetService.ID );
+ dataElementService = (DataElementService) getBean( DataElementService.ID );
+
organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );
-
+
periodType = PeriodType.getAvailablePeriodTypes().iterator().next();
}
@@ -74,7 +79,7 @@
assertEquals( "ShortName" + uniqueCharacter, dataSet.getShortName() );
assertEquals( periodType, dataSet.getPeriodType() );
}
-
+
// -------------------------------------------------------------------------
// DataSet
// -------------------------------------------------------------------------
@@ -84,16 +89,16 @@
{
DataSet dataSetA = createDataSet( 'A', periodType );
DataSet dataSetB = createDataSet( 'B', periodType );
-
+
int idA = dataSetService.addDataSet( dataSetA );
- int idB = dataSetService.addDataSet( dataSetB );
-
+ int idB = dataSetService.addDataSet( dataSetB );
+
dataSetA = dataSetService.getDataSet( idA );
dataSetB = dataSetService.getDataSet( idB );
-
+
assertEquals( idA, dataSetA.getId() );
assertEq( 'A', dataSetA );
-
+
assertEquals( idB, dataSetB.getId() );
assertEq( 'B', dataSetB );
}
@@ -102,19 +107,19 @@
public void testUpdateDataSet()
{
DataSet dataSet = createDataSet( 'A', periodType );
-
+
int id = dataSetService.addDataSet( dataSet );
-
+
dataSet = dataSetService.getDataSet( id );
-
+
assertEq( 'A', dataSet );
-
+
dataSet.setName( "DataSetB" );
-
+
dataSetService.updateDataSet( dataSet );
-
+
dataSet = dataSetService.getDataSet( id );
-
+
assertEquals( dataSet.getName(), "DataSetB" );
}
@@ -123,22 +128,22 @@
{
DataSet dataSetA = createDataSet( 'A', periodType );
DataSet dataSetB = createDataSet( 'B', periodType );
-
+
int idA = dataSetService.addDataSet( dataSetA );
int idB = dataSetService.addDataSet( dataSetB );
-
+
assertNotNull( dataSetService.getDataSet( idA ) );
assertNotNull( dataSetService.getDataSet( idB ) );
-
+
dataSetService.deleteDataSet( dataSetService.getDataSet( idA ) );
-
+
assertNull( dataSetService.getDataSet( idA ) );
assertNotNull( dataSetService.getDataSet( idB ) );
dataSetService.deleteDataSet( dataSetService.getDataSet( idB ) );
-
+
assertNull( dataSetService.getDataSet( idA ) );
- assertNull( dataSetService.getDataSet( idB ) );
+ assertNull( dataSetService.getDataSet( idB ) );
}
@Test
@@ -147,10 +152,10 @@
{
DataSet dataSetA = createDataSet( 'A', periodType );
DataSet dataSetB = createDataSet( 'B', periodType );
-
+
int idA = dataSetService.addDataSet( dataSetA );
int idB = dataSetService.addDataSet( dataSetB );
-
+
assertEquals( dataSetService.getDataSetByName( "DataSetA" ).getId(), idA );
assertEquals( dataSetService.getDataSetByName( "DataSetB" ).getId(), idB );
assertNull( dataSetService.getDataSetByName( "DataSetC" ) );
@@ -176,15 +181,15 @@
{
DataSet dataSetA = createDataSet( 'A', periodType );
DataSet dataSetB = createDataSet( 'B', periodType );
-
+
dataSetService.addDataSet( dataSetA );
dataSetService.addDataSet( dataSetB );
-
+
Collection<DataSet> dataSets = dataSetService.getAllDataSets();
-
+
assertEquals( dataSets.size(), 2 );
assertTrue( dataSets.contains( dataSetA ) );
- assertTrue( dataSets.contains( dataSetB ) );
+ assertTrue( dataSets.contains( dataSetB ) );
}
@Test
@@ -193,53 +198,53 @@
OrganisationUnit sourceA = createOrganisationUnit( 'A' );
OrganisationUnit sourceB = createOrganisationUnit( 'B' );
OrganisationUnit sourceC = createOrganisationUnit( 'C' );
-
+
organisationUnitService.addOrganisationUnit( sourceA );
organisationUnitService.addOrganisationUnit( sourceB );
organisationUnitService.addOrganisationUnit( sourceC );
-
+
DataSet dataSetA = createDataSet( 'A', periodType );
DataSet dataSetB = createDataSet( 'B', periodType );
DataSet dataSetC = createDataSet( 'C', periodType );
-
+
dataSetA.getSources().add( sourceA );
dataSetA.getSources().add( sourceB );
-
+
dataSetB.getSources().add( sourceB );
- dataSetB.getSources().add( sourceC );
+ dataSetB.getSources().add( sourceC );
dataSetC.getSources().add( sourceA );
dataSetC.getSources().add( sourceC );
-
+
dataSetService.addDataSet( dataSetA );
dataSetService.addDataSet( dataSetB );
dataSetService.addDataSet( dataSetC );
-
+
Collection<DataSet> dataSets = dataSetService.getDataSetsBySource( sourceA );
-
+
assertEquals( 2, dataSets.size() );
assertTrue( dataSets.contains( dataSetA ) );
assertTrue( dataSets.contains( dataSetC ) );
-
- dataSets = dataSetService.getDataSetsBySource( sourceB );
+
+ dataSets = dataSetService.getDataSetsBySource( sourceB );
assertEquals( 2, dataSets.size() );
assertTrue( dataSets.contains( dataSetA ) );
assertTrue( dataSets.contains( dataSetB ) );
dataSets = dataSetService.getDataSetsBySource( sourceC );
-
+
assertEquals( 2, dataSets.size() );
assertTrue( dataSets.contains( dataSetB ) );
- assertTrue( dataSets.contains( dataSetC ) );
+ assertTrue( dataSets.contains( dataSetC ) );
}
@Test
public void testGetDataSetsBySources()
{
OrganisationUnit unitA = createOrganisationUnit( 'A' );
- OrganisationUnit unitB = createOrganisationUnit( 'B' );
- OrganisationUnit unitC = createOrganisationUnit( 'C' );
+ OrganisationUnit unitB = createOrganisationUnit( 'B' );
+ OrganisationUnit unitC = createOrganisationUnit( 'C' );
organisationUnitService.addOrganisationUnit( unitA );
organisationUnitService.addOrganisationUnit( unitB );
organisationUnitService.addOrganisationUnit( unitC );
@@ -252,16 +257,16 @@
dataSetA.getSources().add( unitB );
dataSetB.getSources().add( unitA );
dataSetC.getSources().add( unitB );
-
+
dataSetService.addDataSet( dataSetA );
dataSetService.addDataSet( dataSetB );
dataSetService.addDataSet( dataSetC );
dataSetService.addDataSet( dataSetD );
-
+
Collection<Source> sources = new HashSet<Source>();
sources.add( unitA );
sources.add( unitB );
-
+
Collection<DataSet> dataSets = dataSetService.getDataSetsBySources( sources );
assertEquals( 3, dataSets.size() );
@@ -271,14 +276,14 @@
sources = new HashSet<Source>();
sources.add( unitA );
-
+
dataSets = dataSetService.getDataSetsBySources( sources );
-
+
assertEquals( 2, dataSets.size() );
assertTrue( dataSets.contains( dataSetA ) );
assertTrue( dataSets.contains( dataSetB ) );
}
-
+
@Test
public void testGetSourcesAssociatedWithDataSet()
{
@@ -288,36 +293,68 @@
OrganisationUnit sourceD = createOrganisationUnit( 'D' );
OrganisationUnit sourceE = createOrganisationUnit( 'E' );
OrganisationUnit sourceF = createOrganisationUnit( 'F' );
-
+
organisationUnitService.addOrganisationUnit( sourceA );
organisationUnitService.addOrganisationUnit( sourceB );
organisationUnitService.addOrganisationUnit( sourceC );
organisationUnitService.addOrganisationUnit( sourceD );
organisationUnitService.addOrganisationUnit( sourceE );
organisationUnitService.addOrganisationUnit( sourceF );
-
+
DataSet dataSetA = createDataSet( 'A', periodType );
DataSet dataSetB = createDataSet( 'B', periodType );
-
+
dataSetA.getSources().add( sourceA );
dataSetA.getSources().add( sourceB );
dataSetA.getSources().add( sourceC );
dataSetB.getSources().add( sourceC );
dataSetB.getSources().add( sourceD );
- dataSetB.getSources().add( sourceE );
-
+ dataSetB.getSources().add( sourceE );
+
dataSetService.addDataSet( dataSetA );
dataSetService.addDataSet( dataSetB );
Collection<Source> sources = new HashSet<Source>();
-
+
sources.add( sourceA );
sources.add( sourceB );
sources.add( sourceD );
sources.add( sourceE );
-
+
assertEquals( 2, dataSetService.getSourcesAssociatedWithDataSet( dataSetA, sources ) );
assertEquals( 2, dataSetService.getSourcesAssociatedWithDataSet( dataSetB, sources ) );
}
+
+ @Test
+ public void testDataSetHasMembers()
+ {
+ DataElement elementA = createDataElement( 'A' );
+ DataElement elementB = createDataElement( 'B' );
+ DataElement elementC = createDataElement( 'C' );
+
+ dataElementService.addDataElement( elementA );
+ dataElementService.addDataElement( elementB );
+ dataElementService.addDataElement( elementC );
+
+ Collection<DataElement> dataElements = new ArrayList<DataElement>();
+
+ dataElements.add( elementA );
+ dataElements.add( elementB );
+ dataElements.add( elementC );
+
+ DataSet dataSetA = createDataSet( 'A', periodType );
+
+ dataSetA.getDataElements().add( elementA );
+ dataSetA.getDataElements().add( elementB );
+ dataSetA.getDataElements().add( elementC );
+
+ int idA = dataSetService.addDataSet( dataSetA );
+
+ assertTrue( dataSetService.dataSetHasMembers( periodType ) );
+
+ dataSetService.getDataSet( idA ).getDataElements().removeAll( dataElements );
+
+ assertTrue( !dataSetService.dataSetHasMembers( periodType ) );
+ }
}