← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 478: Injecting path to temp external directory during test phase.

 

------------------------------------------------------------
revno: 478
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Tue 2009-08-18 15:55:55 +0200
message:
  Injecting path to temp external directory during test phase.
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dhis14/IbatisConfigurationManagerTest.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/ixf/IXFConfigurationManagerTest.java
  dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.java
  dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/report/ReportManagerTest.java
  dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java
  dhis-2/dhis-support/dhis-support-external/src/test/java/org/hisp/dhis/external/location/LocationManagerTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.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-importexport/src/test/java/org/hisp/dhis/importexport/dhis14/IbatisConfigurationManagerTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dhis14/IbatisConfigurationManagerTest.java	2009-06-14 19:43:19 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dhis14/IbatisConfigurationManagerTest.java	2009-08-18 13:55:55 +0000
@@ -32,6 +32,7 @@
 import java.util.Properties;
 
 import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.importexport.IbatisConfiguration;
 import org.hisp.dhis.importexport.IbatisConfigurationManager;
 import org.junit.Test;
@@ -57,6 +58,8 @@
     @Override
     public void setUpTest()
     {
+        setExternalTestDir( (LocationManager) getBean( LocationManager.ID ) );
+        
         configurationManager = (IbatisConfigurationManager) getBean( IbatisConfigurationManager.ID );
         
         setDependency( configurationManager, "configDir", "test", String.class );

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/ixf/IXFConfigurationManagerTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/ixf/IXFConfigurationManagerTest.java	2009-06-14 19:43:19 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/ixf/IXFConfigurationManagerTest.java	2009-08-18 13:55:55 +0000
@@ -34,6 +34,7 @@
 import java.util.List;
 
 import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.importexport.ixf.config.IXFConfiguration;
 import org.hisp.dhis.importexport.ixf.config.IXFConfigurationManager;
 import org.hisp.dhis.importexport.ixf.config.IXFCountry;
@@ -56,6 +57,8 @@
     public void setUpTest()
         throws Exception
     {
+        setExternalTestDir( (LocationManager) getBean( LocationManager.ID ) );
+        
         configurationManager = (IXFConfigurationManager) getBean( IXFConfigurationManager.ID );
         
         setDependency( configurationManager, "configDir", "test", String.class );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.java	2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/completeness/DataSetCompletenessServiceTest.java	2009-08-18 13:55:55 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.external.configuration.NoConfigurationFoundException;
+import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
@@ -97,6 +98,8 @@
     @Override
     public void setUpTest()
     {
+        setExternalTestDir( (LocationManager) getBean( LocationManager.ID ) );
+        
         periodService = (PeriodService) getBean( PeriodService.ID );
         
         organisationUnitService = (OrganisationUnitService) getBean( OrganisationUnitService.ID );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/report/ReportManagerTest.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/report/ReportManagerTest.java	2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/test/java/org/hisp/dhis/report/ReportManagerTest.java	2009-08-18 13:55:55 +0000
@@ -32,6 +32,7 @@
 
 import org.hisp.dhis.DhisSpringTest;
 import org.hisp.dhis.external.configuration.NoConfigurationFoundException;
+import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.report.manager.ReportConfiguration;
 import org.junit.Test;
 
@@ -65,6 +66,8 @@
     public void testConfiguration()
         throws NoConfigurationFoundException
     {
+        setExternalTestDir( (LocationManager) getBean( LocationManager.ID ) );
+        
         ReportConfiguration config = new ReportConfiguration( "home", "directory" );
         
         reportManager.setConfiguration( config );

=== modified file 'dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java'
--- dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java	2009-04-02 14:23:50 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/main/java/org/hisp/dhis/external/location/DefaultLocationManager.java	2009-08-18 13:55:55 +0000
@@ -52,6 +52,11 @@
 
     private String externalDir = null;
 
+    public void setExternalDir( String externalDir )
+    {
+        this.externalDir = externalDir;
+    }
+
     private String environmentVariable;
 
     public void setEnvironmentVariable( String environmentVariable )

=== modified file 'dhis-2/dhis-support/dhis-support-external/src/test/java/org/hisp/dhis/external/location/LocationManagerTest.java'
--- dhis-2/dhis-support/dhis-support-external/src/test/java/org/hisp/dhis/external/location/LocationManagerTest.java	2009-06-10 22:25:07 +0000
+++ dhis-2/dhis-support/dhis-support-external/src/test/java/org/hisp/dhis/external/location/LocationManagerTest.java	2009-08-18 13:55:55 +0000
@@ -46,9 +46,7 @@
  */
 public class LocationManagerTest
     extends DhisSpringTest
-{
-    private LocationManager locationManager;
-    
+{    
     private InputStream in;
     
     private OutputStream out;
@@ -62,7 +60,7 @@
     @Override
     public void setUpTest()
     {
-        locationManager = (LocationManager) getBean( LocationManager.ID );
+        setExternalTestDir( (LocationManager) getBean( LocationManager.ID ) );
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2009-08-18 13:55:55 +0000
@@ -35,6 +35,8 @@
 import java.util.List;
 import java.util.Set;
 
+import java.io.File;
+
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.datadictionary.DataDictionary;
 import org.hisp.dhis.datadictionary.DataDictionaryService;
@@ -60,6 +62,7 @@
 import org.hisp.dhis.dbms.DbmsManager;
 import org.hisp.dhis.expression.Expression;
 import org.hisp.dhis.expression.ExpressionService;
+import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.importexport.ImportDataValue;
 import org.hisp.dhis.importexport.ImportObjectStatus;
 import org.hisp.dhis.indicator.Indicator;
@@ -96,6 +99,8 @@
 {
     private static final String BASE_UUID = "C3C2E28D-9686-4634-93FD-BE3133935EC";
 
+    private static final String EXT_TEST_DIR = System.getProperty( "user.home" ) + File.separator + "dhis2_test_dir";
+
     private static Date date;
     
     // -------------------------------------------------------------------------
@@ -144,6 +149,8 @@
     
     protected DbmsManager dbmsManager;
     
+    protected LocationManager locationManager;
+    
     static
     {
         Calendar calendar = Calendar.getInstance();
@@ -840,4 +847,46 @@
         
         return extended;
     }
+
+    /**
+     * Injects the externalDir property of LocationManager to user.home/dhis2_test_dir.
+     * LocationManager dependency must be retrieved from the context up front.
+     * 
+     * @param locationManager The LocationManager to be injected with the external directory.
+     */
+    public void setExternalTestDir( LocationManager locationManager )
+    {
+        this.locationManager = locationManager;
+        
+        setDependency( locationManager, "externalDir", EXT_TEST_DIR, String.class );
+    }
+    
+
+    /**
+     * Attempts to remove the external test directory.
+     */
+    public void removeExternalTestDir()
+    {
+        deleteDir( new File( EXT_TEST_DIR ) );
+    }
+    
+    private boolean deleteDir( File dir ) 
+    {
+        if ( dir.isDirectory() )
+        {
+            String[] children = dir.list();
+            
+            for ( int i = 0; i < children.length; i++ )
+            {
+                boolean success = deleteDir( new File( dir, children[ i ] ) );
+                
+                if ( !success ) 
+                {
+                    return false;
+                }
+            }
+        }
+        
+        return dir.delete();
+    }    
 }