dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03114
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1035: Improved testing of DimensionService.
------------------------------------------------------------
revno: 1035
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Mon 2009-11-16 13:30:59 +0100
message:
Improved testing of DimensionService.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/BasicDimensionSet.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.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/dimension/BasicDimensionSet.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/BasicDimensionSet.java 2009-11-16 10:32:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dimension/BasicDimensionSet.java 2009-11-16 12:30:59 +0000
@@ -1,6 +1,8 @@
package org.hisp.dhis.dimension;
import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -22,6 +24,11 @@
this.dimensions = dimensions;
}
+ public BasicDimensionSet( Dimension... dimensions )
+ {
+ this.dimensions = Arrays.asList( dimensions );
+ }
+
// -------------------------------------------------------------------------
// DimensionSet implementation
// -------------------------------------------------------------------------
@@ -95,9 +102,50 @@
}
// -------------------------------------------------------------------------
- // toString
+ // equals, hashCode, toString
// -------------------------------------------------------------------------
-
+
+ @Override
+ public boolean equals( Object object )
+ {
+ if ( this == object )
+ {
+ return true;
+ }
+
+ if ( object == null )
+ {
+ return false;
+ }
+
+ if ( getClass() != object.getClass() )
+ {
+ return false;
+ }
+
+ BasicDimensionSet other = (BasicDimensionSet) object;
+
+ if ( dimensions == null )
+ {
+ if ( other.dimensions != null )
+ {
+ return false;
+ }
+ }
+ else if ( !( new HashSet<Dimension>( dimensions ).equals( new HashSet<Dimension>( other.dimensions ) ) ) )
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return dimensions == null ? 0 : dimensions.hashCode();
+ }
+
public String toString()
{
return "[" + getName() + "]";
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java 2009-11-10 14:02:08 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dimension/DimensionServiceTest.java 2009-11-16 12:30:59 +0000
@@ -27,6 +27,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.HashSet;
+
import org.hisp.dhis.DhisSpringTest;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementGroupSet;
@@ -44,9 +50,12 @@
private DataElementGroupSet dataElementGroupSetA;
private DataElementGroupSet dataElementGroupSetB;
+ private DataElementGroupSet dataElementGroupSetC;
- private DataElement dataElementA;
+ private DataElement dataElementA;
private DataElement dataElementB;
+ private DataElement dataElementC;
+ private DataElement dataElementD;
@Override
public void setUpTest()
@@ -57,23 +66,57 @@
dataElementGroupSetA = new DataElementGroupSet( "DataElementGroupSetA" );
dataElementGroupSetB = new DataElementGroupSet( "DataElementGroupSetB" );
+ dataElementGroupSetC = new DataElementGroupSet( "DataElementGroupSetC" );
dataElementService.addDataElementGroupSet( dataElementGroupSetA );
dataElementService.addDataElementGroupSet( dataElementGroupSetB );
+ dataElementService.addDataElementGroupSet( dataElementGroupSetC );
dataElementA = createDataElement( 'A' );
dataElementB = createDataElement( 'B' );
+ dataElementC = createDataElement( 'C' );
+ dataElementD = createDataElement( 'D' );
dataElementA.getGroupSets().add( dataElementGroupSetA );
- dataElementA.getGroupSets().add( dataElementGroupSetA );
+ dataElementA.getGroupSets().add( dataElementGroupSetB );
+
+ dataElementB.getGroupSets().add( dataElementGroupSetB );
+ dataElementB.getGroupSets().add( dataElementGroupSetC );
+
+ dataElementC.getGroupSets().add( dataElementGroupSetA );
+ dataElementC.getGroupSets().add( dataElementGroupSetB );
dataElementService.addDataElement( dataElementA );
dataElementService.addDataElement( dataElementB );
- }
-
- @Test
- public void getDimensions()
- {
-
+ dataElementService.addDataElement( dataElementC );
+ dataElementService.addDataElement( dataElementD );
+ }
+
+ @Test
+ public void getDataElementDimensionSets()
+ {
+ Collection<DimensionSet> dimensionSets = dimensionService.getDataElementDimensionSets();
+
+ assertEquals( 3, dimensionSets.size() ); // Including default category combo
+ assertTrue( dimensionSets.contains( new BasicDimensionSet( dataElementGroupSetA, dataElementGroupSetB ) ) );
+ assertTrue( dimensionSets.contains( new BasicDimensionSet( dataElementGroupSetB, dataElementGroupSetC ) ) );
+ }
+
+ @Test
+ public void getDataElements()
+ {
+ Collection<DataElement> dataElements = new HashSet<DataElement>();
+
+ Collection<DimensionSet> dimensionSets = dimensionService.getDataElementDimensionSets();
+
+ for ( DimensionSet dimensionSet : dimensionSets )
+ {
+ dataElements.addAll( dimensionService.getDataElements( dimensionSet ) );
+ }
+
+ assertEquals( 3, dataElements.size() );
+ assertTrue( dataElements.contains( dataElementA ) );
+ assertTrue( dataElements.contains( dataElementB ) );
+ assertTrue( dataElements.contains( dataElementC ) );
}
}