dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #16937
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6583: Data value set import unit test
------------------------------------------------------------
revno: 6583
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-04-15 16:52:54 +0200
message:
Data value set import unit test
added:
dhis-2/dhis-dxf2/src/test/resources/datavalueset/
dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetB.csv
dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetB.xml
renamed:
dhis-2/dhis-dxf2/src/test/resources/dataValueSetA.xml => dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetA.xml
modified:
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingCsvDataValue.java
dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingCsvDataValueSet.java
dhis-2/dhis-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java
dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetA.xml
--
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-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingCsvDataValue.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingCsvDataValue.java 2012-04-14 18:32:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingCsvDataValue.java 2012-04-15 14:52:54 +0000
@@ -176,4 +176,14 @@
writer.writeNext( values.toArray( row ) );
}
+
+ public static String[] getHeaders()
+ {
+ String[] headers = {
+ "dataelelement", "period", "orgunit",
+ "categoryoptioncombo", "value", "storedby",
+ "timestamp", "comment", "followup" };
+
+ return headers;
+ }
}
=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingCsvDataValueSet.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingCsvDataValueSet.java 2012-04-14 18:32:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingCsvDataValueSet.java 2012-04-15 14:52:54 +0000
@@ -46,12 +46,22 @@
public StreamingCsvDataValueSet( CSVWriter writer )
{
- this.writer = writer;
+ this.writer = writer;
+ this.writer.writeNext( StreamingCsvDataValue.getHeaders() ); // Write headers
}
public StreamingCsvDataValueSet( CSVReader reader )
{
this.reader = reader;
+
+ try
+ {
+ this.reader.readNext(); // Skip first row / headers
+ }
+ catch ( IOException ex )
+ {
+ throw new RuntimeException( ex );
+ }
}
@Override
=== modified file 'dhis-2/dhis-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java'
--- dhis-2/dhis-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java 2012-04-11 20:16:18 +0000
+++ dhis-2/dhis-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java 2012-04-15 14:52:54 +0000
@@ -86,10 +86,18 @@
private DataElement deC;
private DataSet dsA;
private OrganisationUnit ouA;
+ private OrganisationUnit ouB;
private Period peA;
+ private Period peB;
private DataElementCategoryOptionCombo optionComboA;
@Override
+ public boolean emptyDatabaseAfterTest()
+ {
+ return true;
+ }
+
+ @Override
public void setUpTest()
{
deA = createDataElement( 'A' );
@@ -97,7 +105,9 @@
deC = createDataElement( 'C' );
dsA = createDataSet( 'A', new MonthlyPeriodType() );
ouA = createOrganisationUnit( 'A' );
+ ouB = createOrganisationUnit( 'B' );
peA = createPeriod( getDate( 2012, 1, 1 ), getDate( 2012, 1, 31 ) );
+ peB = createPeriod( getDate( 2012, 2, 1 ), getDate( 2012, 2, 29 ) );
optionComboA = categoryService.getDefaultDataElementCategoryOptionCombo();
deA.setUid( "f7n9E0hX8qk" );
@@ -105,20 +115,23 @@
deC.setUid( "eY5ehpbEsB7" );
dsA.setUid( "pBOMPrpg1QX" );
ouA.setUid( "DiszpKrYNg8" );
+ ouB.setUid( "BdfsJfj87js" );
dataElementService.addDataElement( deA );
dataElementService.addDataElement( deB );
dataElementService.addDataElement( deC );
dataSetService.addDataSet( dsA );
organisationUnitService.addOrganisationUnit( ouA );
+ organisationUnitService.addOrganisationUnit( ouB );
periodService.addPeriod( peA );
+ periodService.addPeriod( peB );
}
@Test
- public void testImport()
+ public void testImportDataValueSetXml()
throws Exception
{
- ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "dataValueSetA.xml" ).getInputStream() );
+ ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetA.xml" ).getInputStream() );
assertNotNull( summary );
assertNotNull( summary.getDataValueCount() );
@@ -137,6 +150,38 @@
assertEquals( dsA, registration.getDataSet() );
assertEquals( peA, registration.getPeriod() );
assertEquals( ouA, registration.getSource() );
- assertEquals( getDate( 2012, 1, 2 ), registration.getDate() );
+ assertEquals( getDate( 2012, 1, 9 ), registration.getDate() );
+ }
+
+ @Test
+ public void testImportDataValuesXml()
+ throws Exception
+ {
+ ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream() );
+
+ assertImportDataValues( summary );
+ }
+
+ private void assertImportDataValues( ImportSummary summary )
+ {
+ assertNotNull( summary );
+ assertNotNull( summary.getDataValueCount() );
+
+ Collection<DataValue> dataValues = dataValueService.getAllDataValues();
+
+ assertNotNull( dataValues );
+ assertEquals( 12, dataValues.size() );
+ assertTrue( dataValues.contains( new DataValue( deA, peA, ouA, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deA, peA, ouB, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deA, peB, ouA, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deA, peB, ouB, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deB, peA, ouA, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deB, peA, ouB, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deB, peB, ouA, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deB, peB, ouB, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deC, peA, ouA, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deC, peA, ouB, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deC, peB, ouA, optionComboA ) ) );
+ assertTrue( dataValues.contains( new DataValue( deC, peB, ouB, optionComboA ) ) );
}
}
=== added directory 'dhis-2/dhis-dxf2/src/test/resources/datavalueset'
=== renamed file 'dhis-2/dhis-dxf2/src/test/resources/dataValueSetA.xml' => 'dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetA.xml'
--- dhis-2/dhis-dxf2/src/test/resources/dataValueSetA.xml 2012-04-11 11:33:43 +0000
+++ dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetA.xml 2012-04-15 14:52:54 +0000
@@ -1,5 +1,5 @@
-<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="pBOMPrpg1QX" completeDate="2012-01-02" period="201201" orgUnit="DiszpKrYNg8">
- <dataValue dataElement="f7n9E0hX8qk" value="10001" storedBy="john" comment="comment" followup="false"/>
- <dataValue dataElement="Ix2HsbDMLea" value="10002" storedBy="john" comment="comment" followup="false"/>
- <dataValue dataElement="eY5ehpbEsB7" value="10003" storedBy="john" comment="comment" followup="false"/>
+<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0" dataSet="pBOMPrpg1QX" completeDate="2012-01-09" period="201201" orgUnit="DiszpKrYNg8">
+ <dataValue dataElement="f7n9E0hX8qk" value="10001" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="Ix2HsbDMLea" value="10002" storedBy="john" timestamp="2012-01-02" comment="comment" followup="false"/>
+ <dataValue dataElement="eY5ehpbEsB7" value="10003" storedBy="john" timestamp="2012-01-03" comment="comment" followup="false"/>
</dataValueSet>
\ No newline at end of file
=== added file 'dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetB.csv'
--- dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetB.csv 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetB.csv 2012-04-15 14:52:54 +0000
@@ -0,0 +1,13 @@
+"dataelelement","period","orgunit","categoryoptioncombo","value","storedby","timestamp","comment","followup"
+"f7n9E0hX8qk","201201","DiszpKrYNg8","","10001","john","2012-01-01","comment","false"
+"f7n9E0hX8qk","201201","BdfsJfj87js","","10002","john","2012-01-01","comment","false"
+"f7n9E0hX8qk","201202","DiszpKrYNg8","","10003","john","2012-01-01","comment","false"
+"f7n9E0hX8qk","201202","BdfsJfj87js","","10004","john","2012-01-01","comment","false"
+"Ix2HsbDMLea","201201","DiszpKrYNg8","","10005","john","2012-01-01","comment","false"
+"Ix2HsbDMLea","201201","BdfsJfj87js","","10006","john","2012-01-01","comment","false"
+"Ix2HsbDMLea","201202","DiszpKrYNg8","","10007","john","2012-01-01","comment","false"
+"Ix2HsbDMLea","201202","BdfsJfj87js","","10008","john","2012-01-01","comment","false"
+"eY5ehpbEsB7","201201","DiszpKrYNg8","","10009","john","2012-01-01","comment","false"
+"eY5ehpbEsB7","201201","BdfsJfj87js","","10010","john","2012-01-01","comment","false"
+"eY5ehpbEsB7","201202","DiszpKrYNg8","","10011","john","2012-01-01","comment","false"
+"eY5ehpbEsB7","201202","BdfsJfj87js","","10012","john","2012-01-01","comment","false"
\ No newline at end of file
=== added file 'dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetB.xml'
--- dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetB.xml 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/test/resources/datavalueset/dataValueSetB.xml 2012-04-15 14:52:54 +0000
@@ -0,0 +1,14 @@
+<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0">
+ <dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="DiszpKrYNg8" value="10001" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="f7n9E0hX8qk" period="201201" orgUnit="BdfsJfj87js" value="10002" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="f7n9E0hX8qk" period="201202" orgUnit="DiszpKrYNg8" value="10003" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="f7n9E0hX8qk" period="201202" orgUnit="BdfsJfj87js" value="10004" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="Ix2HsbDMLea" period="201201" orgUnit="DiszpKrYNg8" value="10005" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="Ix2HsbDMLea" period="201201" orgUnit="BdfsJfj87js" value="10006" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="Ix2HsbDMLea" period="201202" orgUnit="DiszpKrYNg8" value="10007" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="Ix2HsbDMLea" period="201202" orgUnit="BdfsJfj87js" value="10008" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="eY5ehpbEsB7" period="201201" orgUnit="DiszpKrYNg8" value="10009" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="eY5ehpbEsB7" period="201201" orgUnit="BdfsJfj87js" value="10010" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="eY5ehpbEsB7" period="201202" orgUnit="DiszpKrYNg8" value="10011" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+ <dataValue dataElement="eY5ehpbEsB7" period="201202" orgUnit="BdfsJfj87js" value="10012" storedBy="john" timestamp="2012-01-01" comment="comment" followup="false"/>
+</dataValueSet>