You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by rl...@apache.org on 2014/08/06 01:50:47 UTC

svn commit: r1616051 - in /oodt/trunk: CHANGES.txt filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestExpImpCatalog.java filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestMetadataBasedProductMover.java

Author: rlaidlaw
Date: Tue Aug  5 23:50:46 2014
New Revision: 1616051

URL: http://svn.apache.org/r1616051
Log:
OODT-735: fixed test classes in file manager tools package to find test resources and reset system properties

Modified:
    oodt/trunk/CHANGES.txt
    oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestExpImpCatalog.java
    oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestMetadataBasedProductMover.java

Modified: oodt/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1616051&r1=1616050&r2=1616051&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Tue Aug  5 23:50:46 2014
@@ -4,6 +4,9 @@ Apache OODT Change Log
 Release 0.7 - Current Development
 -------------------------------------------- 
 
+* OODT-735 Fix File Manager unit tests (step 9) - fix test classes in 'tools'
+  package (rlaidlaw)
+
 * OODT-734 Fix File Manager unit tests (step 8) - fix test classes in 'system'
   package (rlaidlaw)
 

Modified: oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestExpImpCatalog.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestExpImpCatalog.java?rev=1616051&r1=1616050&r2=1616051&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestExpImpCatalog.java (original)
+++ oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestExpImpCatalog.java Tue Aug  5 23:50:46 2014
@@ -33,7 +33,7 @@ import java.io.FileInputStream;
 import java.net.URL;
 import java.util.Iterator;
 import java.util.List;
-
+import java.util.Properties;
 //Junit imports
 import junit.framework.TestCase;
 
@@ -58,6 +58,9 @@ public class TestExpImpCatalog extends T
     private static final String transferServiceFacClass = "org.apache.oodt.cas."
             + "filemgr.datatransfer.LocalDataTransferFactory";
 
+    private Properties initialProperties = new Properties(
+        System.getProperties());
+
     public TestExpImpCatalog() {
     }
     
@@ -181,10 +184,11 @@ public class TestExpImpCatalog extends T
      */
     protected void setUp() throws Exception {
         System.out.println("Test set up");
-        fm = startXmlRpcFileManager(FM_PORT, new File(
-                "./src/testdata/ingest/cat").getCanonicalPath());
-        fm2 = startXmlRpcFileManager(FM_PORT + 1, new File(
-                "./src/testdata/ingest/cat2").getCanonicalPath());
+        URL ingestUrl = this.getClass().getResource("/ingest");
+        String cat1 = new File(ingestUrl.getFile()).getCanonicalPath() + "cat";
+        String cat2 = new File(ingestUrl.getFile()).getCanonicalPath() + "cat2";
+        fm = startXmlRpcFileManager(FM_PORT, cat1);
+        fm2 = startXmlRpcFileManager(FM_PORT + 1, cat2);
         ingestTestFiles();
         try {
             expImp = new ExpImpCatalog(new URL("http://localhost:" + FM_PORT),
@@ -207,12 +211,17 @@ public class TestExpImpCatalog extends T
         fm2 = null;
 
         // blow away lucene cat
-        deleteAllFiles(new File("./src/testdata/ingest/cat").getCanonicalPath());
-        deleteAllFiles(new File("./src/testdata/ingest/cat2")
-                .getCanonicalPath());
+        URL ingestUrl = this.getClass().getResource("/ingest");
+        String cat1 = new File(ingestUrl.getFile()).getCanonicalPath() + "cat";
+        String cat2 = new File(ingestUrl.getFile()).getCanonicalPath() + "cat2";
+        deleteAllFiles(cat1);
+        deleteAllFiles(cat2);
 
         // blow away test file
         deleteAllFiles("/tmp/test.txt");
+
+        // Reset the System properties to initial values.
+        System.setProperties(initialProperties);
     }
 
     private void ingestTestFiles() {
@@ -220,19 +229,23 @@ public class TestExpImpCatalog extends T
         StdIngester ingester = new StdIngester(transferServiceFacClass);
 
         try {
+            URL ingestUrl = this.getClass().getResource("/ingest");
+            URL refUrl = this.getClass().getResource("/ingest/test.txt");
+            URL metUrl = this.getClass().getResource("/ingest/test.txt.met");
+
             prodMet = new SerializableMetadata(new FileInputStream(
-                    "./src/testdata/ingest/test.txt.met"));
+                new File(metUrl.getFile())));
 
             // now add the right file location
             prodMet.addMetadata(CoreMetKeys.FILE_LOCATION, new File(
-                    "./src/testdata/ingest").getCanonicalPath());
+                ingestUrl.getFile()).getCanonicalPath());
             ingester.ingest(new URL("http://localhost:" + FM_PORT), new File(
-                    "./src/testdata/ingest/test.txt"), prodMet);
+                refUrl.getFile()), prodMet);
             
             prodMet.replaceMetadata(CoreMetKeys.PRODUCT_NAME, "TestTypeFile");
             prodMet.replaceMetadata(CoreMetKeys.PRODUCT_TYPE, "TestType");
             ingester.ingest(new URL("http://localhost:" + FM_PORT), new File(
-                "./src/testdata/ingest/test.txt"), prodMet);
+                refUrl.getFile()), prodMet);
         } catch (Exception e) {
             fail(e.getMessage());
         }
@@ -253,52 +266,59 @@ public class TestExpImpCatalog extends T
     }
 
     private XmlRpcFileManager startXmlRpcFileManager(int port, String catPath) {
+
+        Properties properties = new Properties(System.getProperties());
+
         XmlRpcFileManager fileMgr = null;
         
         // first make sure to load properties for the file manager
         // and make sure to load logging properties as well
 
         // set the log levels
-        System.setProperty("java.util.logging.config.file", new File(
-                "./src/main/resources/logging.properties").getAbsolutePath());
+        URL loggingPropertiesUrl = this.getClass().getResource(
+            "/test.logging.properties");
+        properties.setProperty("java.util.logging.config.file", new File(
+            loggingPropertiesUrl.getFile()).getAbsolutePath());
         
         
         // first load the example configuration
         try {
-            System.getProperties().load(
-                    new FileInputStream("./src/main/resources/filemgr.properties"));
+            URL filemgrPropertiesUrl = this.getClass().getResource(
+                "/filemgr.properties");
+            properties.load(
+                new FileInputStream(new File(filemgrPropertiesUrl.getFile())));
         } catch (Exception e) {
             fail(e.getMessage());
         }
 
         // override the catalog to use: we'll use lucene
-        System.setProperty("filemgr.catalog.factory",
+        properties.setProperty("filemgr.catalog.factory",
                 "org.apache.oodt.cas.filemgr.catalog.LuceneCatalogFactory");
-        System.setProperty(
+        properties.setProperty(
                 "org.apache.oodt.cas.filemgr.catalog.lucene.idxPath",
                 catPath);
 
         // now override the repo mgr policy
+        URL fmpolicyUrl = this.getClass().getResource("/ingest/fmpolicy");
         try {
-            System.setProperty(
-                    "org.apache.oodt.cas.filemgr.repositorymgr.dirs",
-                    "file://"
-                            + new File("./src/testdata/ingest/fmpolicy")
-                                    .getCanonicalPath());
+          properties.setProperty(
+              "org.apache.oodt.cas.filemgr.repositorymgr.dirs",
+              "file://" + new File(fmpolicyUrl.getFile()).getCanonicalPath());
         } catch (Exception e) {
             fail(e.getMessage());
         }
 
         // now override the val layer ones
-        System.setProperty("org.apache.oodt.cas.filemgr.validation.dirs",
-                "file://"
-                        + new File("./src/testdata/ingest/fmpolicy")
-                                .getAbsolutePath());
+        properties.setProperty("org.apache.oodt.cas.filemgr.validation.dirs",
+            "file://" + new File(fmpolicyUrl.getFile()).getAbsolutePath());
 
         // set up mime repo path
-        System.setProperty(
-                "org.apache.oodt.cas.filemgr.mime.type.repository", new File(
-                        "./src/main/resources/mime-types.xml").getAbsolutePath());
+        URL mimeTypesUrl = this.getClass().getResource("/mime-types.xml");
+        properties.setProperty(
+            "org.apache.oodt.cas.filemgr.mime.type.repository",
+            new File(mimeTypesUrl.getFile()).getAbsolutePath());
+
+        System.setProperties(properties);
 
         try {
             fileMgr = new XmlRpcFileManager(port);

Modified: oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestMetadataBasedProductMover.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestMetadataBasedProductMover.java?rev=1616051&r1=1616050&r2=1616051&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestMetadataBasedProductMover.java (original)
+++ oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/tools/TestMetadataBasedProductMover.java Tue Aug  5 23:50:46 2014
@@ -29,7 +29,7 @@ import org.apache.oodt.cas.metadata.Seri
 import java.io.File;
 import java.io.FileInputStream;
 import java.net.URL;
-
+import java.util.Properties;
 //Junit imports
 import junit.framework.TestCase;
 
@@ -58,6 +58,9 @@ public class TestMetadataBasedProductMov
 
     private MetadataBasedProductMover mover;
 
+    private Properties initialProperties = new Properties(
+        System.getProperties());
+
     public TestMetadataBasedProductMover() {
     }
 
@@ -78,14 +81,18 @@ public class TestMetadataBasedProductMov
         StdIngester ingester = new StdIngester(transferServiceFacClass);
 
         try {
+            URL ingestUrl = this.getClass().getResource("/ingest");
+            URL refUrl = this.getClass().getResource("/ingest/test.txt");
+            URL metUrl = this.getClass().getResource("/ingest/test.txt.met");
+
             prodMet = new SerializableMetadata(new FileInputStream(
-                    "./src/testdata/ingest/test.txt.met"));
+                new File(metUrl.getFile())));
 
             // now add the right file location
             prodMet.addMetadata(CoreMetKeys.FILE_LOCATION, new File(
-                    "./src/testdata/ingest").getCanonicalPath());
+                ingestUrl.getFile()).getCanonicalPath());
             ingester.ingest(new URL("http://localhost:" + FM_PORT), new File(
-                    "./src/testdata/ingest/test.txt"), prodMet);
+                refUrl.getFile()), prodMet);
         } catch (Exception e) {
             fail(e.getMessage());
         }
@@ -124,6 +131,9 @@ public class TestMetadataBasedProductMov
 
         // blow away test file
         deleteAllFilesRecursive("/tmp/text");
+
+        // Reset the System properties to initial values.
+        System.setProperties(initialProperties);
     }
 
     private void deleteAllFilesRecursive(String startDirPath) {
@@ -162,56 +172,65 @@ public class TestMetadataBasedProductMov
     }
 
     private void startXmlRpcFileManager() {
+
+        Properties properties = new Properties(System.getProperties());
+
         // first make sure to load properties for the file manager
         // and make sure to load logging properties as well
 
         // set the log levels
-        System.setProperty("java.util.logging.config.file", new File(
-                "./src/main/resources/logging.properties").getAbsolutePath());
+        URL loggingPropertiesUrl = this.getClass().getResource(
+            "/test.logging.properties");
+        properties.setProperty("java.util.logging.config.file", new File(
+            loggingPropertiesUrl.getFile()).getAbsolutePath());
 
         // first load the example configuration
         try {
-            System.getProperties().load(
-                    new FileInputStream("./src/main/resources/filemgr.properties"));
+            URL filemgrPropertiesUrl = this.getClass().getResource(
+                "/filemgr.properties");
+            properties.load(
+              new FileInputStream(new File(filemgrPropertiesUrl.getFile())));
         } catch (Exception e) {
             fail(e.getMessage());
         }
 
         // override the catalog to use: we'll use lucene
         try {
-            luceneCatLoc = new File("./src/testdata/ingest/cat")
-                    .getCanonicalPath();
+            URL ingestUrl = this.getClass().getResource("/ingest");
+            luceneCatLoc = new File(ingestUrl.getFile()).getCanonicalPath()
+                + "/cat";
         } catch (Exception e) {
             fail(e.getMessage());
         }
 
-        System.setProperty("filemgr.catalog.factory",
+        properties.setProperty("filemgr.catalog.factory",
                 "org.apache.oodt.cas.filemgr.catalog.LuceneCatalogFactory");
-        System.setProperty(
+        properties.setProperty(
                 "org.apache.oodt.cas.filemgr.catalog.lucene.idxPath",
                 luceneCatLoc);
 
         // now override the repo mgr policy
         try {
-            System.setProperty(
-                    "org.apache.oodt.cas.filemgr.repositorymgr.dirs",
-                    "file://"
-                            + new File("./src/testdata/ingest/fmpolicy")
-                                    .getCanonicalPath());
+          URL fmpolicyUrl = this.getClass().getResource("/ingest/fmpolicy");
+          properties.setProperty(
+              "org.apache.oodt.cas.filemgr.repositorymgr.dirs",
+              "file://" + new File(fmpolicyUrl.getFile()).getCanonicalPath());
         } catch (Exception e) {
             fail(e.getMessage());
         }
 
         // now override the val layer ones
-        System.setProperty("org.apache.oodt.cas.filemgr.validation.dirs",
-                "file://"
-                        + new File("./src/main/resources/examples/core")
-                                .getAbsolutePath());
+        URL examplesCoreUrl = this.getClass().getResource("/examples/core");
+        properties.setProperty("org.apache.oodt.cas.filemgr.validation.dirs",
+            "file://" + new File(examplesCoreUrl.getFile()).getAbsolutePath());
 
         // set up mime repo path
-        System.setProperty(
-                "org.apache.oodt.cas.filemgr.mime.type.repository", new File(
-                        "./src/main/resources/mime-types.xml").getAbsolutePath());
+        URL mimeTypesUrl = this.getClass().getResource("/mime-types.xml");
+        properties.setProperty(
+            "org.apache.oodt.cas.filemgr.mime.type.repository",
+            new File(mimeTypesUrl.getFile()).getAbsolutePath());
+
+        System.setProperties(properties);
 
         try {
             fm = new XmlRpcFileManager(FM_PORT);