← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17073: DXF 2 service, closing input stream in tests

 

------------------------------------------------------------
revno: 17073
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2014-10-13 14:28:52 +0200
message:
  DXF 2 service, closing input stream in tests
modified:
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/TrackedEntityInstanceServiceTest.java
  dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/gml/GmlImportServiceTest.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-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2014-10-06 22:28:17 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2014-10-13 12:28:52 +0000
@@ -36,8 +36,10 @@
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
+import java.io.InputStream;
 import java.util.Collection;
 
+import org.apache.commons.io.IOUtils;
 import org.hisp.dhis.DhisTest;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategory;
@@ -112,6 +114,8 @@
     private Period peA;
     private Period peB;
     
+    private InputStream in;
+    
     @Override
     public boolean emptyDatabaseAfterTest()
     {
@@ -176,11 +180,23 @@
         periodService.addPeriod( peB );        
     }
 
+    @Override
+    public void tearDownTest()
+    {
+        IOUtils.closeQuietly( in );
+    }
+
+    // -------------------------------------------------------------------------
+    // Tests
+    // -------------------------------------------------------------------------
+
     @Test
     public void testImportDataValueSetXml()
         throws Exception
     {
-        ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetA.xml" ).getInputStream() );
+        in = new ClassPathResource( "datavalueset/dataValueSetA.xml" ).getInputStream();
+        
+        ImportSummary summary = dataValueSetService.saveDataValueSet( in );
         
         assertNotNull( summary );
         assertNotNull( summary.getDataValueCount() );
@@ -206,7 +222,9 @@
     public void testImportDataValuesXmlWithCodeA()
         throws Exception
     {
-        ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetACode.xml" ).getInputStream() );
+        in = new ClassPathResource( "datavalueset/dataValueSetACode.xml" ).getInputStream();
+            
+        ImportSummary summary = dataValueSetService.saveDataValueSet( in );
         
         assertNotNull( summary );
         assertNotNull( summary.getDataValueCount() );
@@ -232,7 +250,9 @@
     public void testImportDataValuesXml()
         throws Exception
     {
-        ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream() );
+        in = new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream();
+        
+        ImportSummary summary = dataValueSetService.saveDataValueSet( in );
         
         assertImportDataValues( summary );
     }
@@ -241,8 +261,10 @@
     public void testImportDataValuesXmlWithCodeB()
         throws Exception
     {
+        in = new ClassPathResource( "datavalueset/dataValueSetBcode.xml" ).getInputStream();
+        
         ImportOptions options = new ImportOptions( CODE, CODE, false, true, NEW_AND_UPDATES, false );
-        ImportSummary summary = dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetBcode.xml" ).getInputStream(), options );
+        ImportSummary summary = dataValueSetService.saveDataValueSet( in, options );
         
         assertImportDataValues( summary );
     }
@@ -251,12 +273,78 @@
     public void testImportDataValuesCsv()
         throws Exception
     {
-        ImportSummary summary = dataValueSetService.saveDataValueSetCsv( 
-            new ClassPathResource( "datavalueset/dataValueSetB.csv" ).getInputStream(), null, null );
+        in = new ClassPathResource( "datavalueset/dataValueSetB.csv" ).getInputStream();
+        
+        ImportSummary summary = dataValueSetService.saveDataValueSetCsv( in, null, null );
         
         assertImportDataValues( summary );
     }
     
+    @Test
+    public void testImportDataValuesXmlDryRun()
+        throws Exception
+    {
+        in = new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream();
+        
+        ImportOptions options = new ImportOptions( UID, UID, true, true, NEW_AND_UPDATES, false );
+        
+        dataValueSetService.saveDataValueSet( in, options );
+        
+        Collection<DataValue> dataValues = dataValueService.getAllDataValues();
+        
+        assertNotNull( dataValues );
+        assertEquals( 0, dataValues.size() );
+    }
+    
+    @Test
+    public void testImportDataValuesXmlUpdatesOnly()
+        throws Exception
+    {
+        in = new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream();
+        
+        ImportOptions options = new ImportOptions( UID, UID, false, true, UPDATES, false );
+        
+        dataValueSetService.saveDataValueSet( in, options );
+        
+        Collection<DataValue> dataValues = dataValueService.getAllDataValues();
+        
+        assertNotNull( dataValues );
+        assertEquals( 0, dataValues.size() );
+    }
+
+    @Test
+    public void testImportDataValuesWithNewPeriod()
+        throws Exception
+    {
+        dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetC.xml" ).getInputStream() );
+        
+        Collection<DataValue> dataValues = dataValueService.getAllDataValues();
+        
+        assertNotNull( dataValues );
+        assertEquals( 3, dataValues.size() );
+    }
+    
+    @Test
+    public void testImportDataValuesWithAttributeOptionCombo()
+        throws Exception
+    {
+        in = new ClassPathResource( "datavalueset/dataValueSetD.xml" ).getInputStream();
+        
+        dataValueSetService.saveDataValueSet( in );
+        
+        Collection<DataValue> dataValues = dataValueService.getAllDataValues();
+        
+        assertNotNull( dataValues );
+        assertEquals( 3, dataValues.size() );
+        assertTrue( dataValues.contains( new DataValue( deA, peA, ouA, ocDef, ocA ) ) );
+        assertTrue( dataValues.contains( new DataValue( deB, peA, ouA, ocDef, ocA ) ) );
+        assertTrue( dataValues.contains( new DataValue( deC, peA, ouA, ocDef, ocA ) ) );        
+    }
+
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
     private void assertImportDataValues( ImportSummary summary )
     {
         assertNotNull( summary );
@@ -280,58 +368,4 @@
         assertTrue( dataValues.contains( new DataValue( deC, peB, ouB, ocDef, ocDef ) ) );        
     }
     
-    @Test
-    public void testImportDataValuesXmlDryRun()
-        throws Exception
-    {
-        ImportOptions options = new ImportOptions( UID, UID, true, true, NEW_AND_UPDATES, false );
-        
-        dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream(), options );
-        
-        Collection<DataValue> dataValues = dataValueService.getAllDataValues();
-        
-        assertNotNull( dataValues );
-        assertEquals( 0, dataValues.size() );
-    }
-    
-    @Test
-    public void testImportDataValuesXmlUpdatesOnly()
-        throws Exception
-    {
-        ImportOptions options = new ImportOptions( UID, UID, false, true, UPDATES, false );
-        
-        dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetB.xml" ).getInputStream(), options );
-        
-        Collection<DataValue> dataValues = dataValueService.getAllDataValues();
-        
-        assertNotNull( dataValues );
-        assertEquals( 0, dataValues.size() );
-    }
-
-    @Test
-    public void testImportDataValuesWithNewPeriod()
-        throws Exception
-    {
-        dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetC.xml" ).getInputStream() );
-        
-        Collection<DataValue> dataValues = dataValueService.getAllDataValues();
-        
-        assertNotNull( dataValues );
-        assertEquals( 3, dataValues.size() );
-    }
-    
-    @Test
-    public void testImportDataValuesWithAttributeOptionCombo()
-        throws Exception
-    {
-        dataValueSetService.saveDataValueSet( new ClassPathResource( "datavalueset/dataValueSetD.xml" ).getInputStream() );
-        
-        Collection<DataValue> dataValues = dataValueService.getAllDataValues();
-        
-        assertNotNull( dataValues );
-        assertEquals( 3, dataValues.size() );
-        assertTrue( dataValues.contains( new DataValue( deA, peA, ouA, ocDef, ocA ) ) );
-        assertTrue( dataValues.contains( new DataValue( deB, peA, ouA, ocDef, ocA ) ) );
-        assertTrue( dataValues.contains( new DataValue( deC, peA, ouA, ocDef, ocA ) ) );        
-    }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/EnrollmentServiceTest.java	2014-10-13 12:28:52 +0000
@@ -90,7 +90,8 @@
     private ProgramStage programStage;
 
     @Override
-    protected void setUpTest() throws Exception
+    protected void setUpTest() 
+        throws Exception
     {
         organisationUnitA = createOrganisationUnit( 'A' );
         organisationUnitB = createOrganisationUnit( 'B' );
@@ -347,7 +348,6 @@
         assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
 
         TrackedEntityInstance trackedEntityInstance = trackedEntityInstanceService.getTrackedEntityInstance( maleA );
-        // person.setName( "Changed Name" );
         trackedEntityInstanceService.updateTrackedEntityInstance( trackedEntityInstance );
 
         List<Enrollment> enrollments = enrollmentService.getEnrollments( trackedEntityInstance ).getEnrollments();

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java	2014-10-08 12:58:59 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java	2014-10-13 12:28:52 +0000
@@ -84,7 +84,8 @@
     private ProgramStage programStageA;
 
     @Override
-    protected void setUpTest() throws Exception
+    protected void setUpTest() 
+        throws Exception
     {
         identifiableObjectManager = _identifiableObjectManager;
         userService = _userService;

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.java	2014-10-07 13:46:29 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationMultiEventsServiceTest.java	2014-10-13 12:28:52 +0000
@@ -191,12 +191,6 @@
         createUserAndInjectSecurityContext( true );
     }
 
-    // @Override
-    public boolean emptyDatabaseAfterTest()
-    {
-        return true;
-    }
-
     @Test
     public void testSaveWithoutProgramStageShouldFail()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java	2014-10-07 13:46:29 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/RegistrationSingleEventServiceTest.java	2014-10-13 12:28:52 +0000
@@ -156,12 +156,6 @@
         createUserAndInjectSecurityContext( true );
     }
 
-    // @Override
-    public boolean emptyDatabaseAfterTest()
-    {
-        return true;
-    }
-
     @Test
     public void testSaveWithoutEnrollmentShouldFail()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/TrackedEntityInstanceServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/TrackedEntityInstanceServiceTest.java	2014-10-06 10:11:29 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/TrackedEntityInstanceServiceTest.java	2014-10-13 12:28:52 +0000
@@ -113,12 +113,6 @@
         programInstanceService.enrollTrackedEntityInstance( femaleA, programA, null, null, organisationUnitA );
     }
 
-    // @Override
-    public boolean emptyDatabaseAfterTest()
-    {
-        return true;
-    }
-
     @Test
     public void getPersonByUid()
     {

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/gml/GmlImportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/gml/GmlImportServiceTest.java	2014-10-11 10:37:39 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/gml/GmlImportServiceTest.java	2014-10-13 12:28:52 +0000
@@ -36,9 +36,11 @@
 import java.util.Collection;
 import java.util.HashMap;
 
+import org.apache.commons.io.IOUtils;
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.junit.After;
 import org.junit.Test;
 import org.springframework.core.io.ClassPathResource;
 
@@ -60,6 +62,16 @@
 
         inputStream = new ClassPathResource( "gmlOrgUnits.gml" ).getInputStream();        
     }
+    
+    @After
+    public void after()
+    {
+        IOUtils.closeQuietly( inputStream );
+    }
+
+    // -------------------------------------------------------------------------
+    // Tests
+    // -------------------------------------------------------------------------
 
     @Test
     public void fromGmlTest()