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:19:55 UTC

svn commit: r1616044 - in /oodt/trunk: CHANGES.txt filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManager.java filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManagerClient.java

Author: rlaidlaw
Date: Tue Aug  5 23:19:54 2014
New Revision: 1616044

URL: http://svn.apache.org/r1616044
Log:
OODT-734: fixed test classes in file manager system 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/system/TestXmlRpcFileManager.java
    oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManagerClient.java

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

Modified: oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManager.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManager.java?rev=1616044&r1=1616043&r2=1616044&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManager.java (original)
+++ oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManager.java Tue Aug  5 23:19:54 2014
@@ -23,7 +23,7 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.URL;
 import java.util.Collections;
-
+import java.util.Properties;
 //OODT imports
 import org.apache.oodt.cas.filemgr.ingest.StdIngester;
 import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
@@ -54,6 +54,9 @@ public class TestXmlRpcFileManager exten
   private static final String transferServiceFacClass = "org.apache.oodt.cas."
       + "filemgr.datatransfer.LocalDataTransferFactory";
 
+  private Properties initialProperties = new Properties(
+      System.getProperties());
+
   /**
    * @since OODT-72
    */
@@ -97,9 +100,11 @@ public class TestXmlRpcFileManager exten
     assertEquals(1, met.getAllMetadata(ProductMetKeys.PRODUCT_MIME_TYPES)
         .size());
 
+    URL refUrl = this.getClass().getResource("/ingest/test.txt");
+
     String origPath = null;
     try {
-      origPath = new File("./src/testdata/ingest/test.txt").getCanonicalPath();
+      origPath = new File(refUrl.getFile()).getCanonicalPath();
     } catch (IOException e) {
       fail(e.getMessage());
     }
@@ -145,7 +150,7 @@ public class TestXmlRpcFileManager exten
 
     origPath = null;
     try {
-      origPath = new File("./src/testdata/ingest/test.txt").getCanonicalPath();
+      origPath = new File(refUrl.getFile()).getCanonicalPath();
     } catch (IOException e) {
       fail(e.getMessage());
     }
@@ -183,6 +188,9 @@ public class TestXmlRpcFileManager exten
 
     // blow away test file
     deleteAllFiles("/tmp/test.txt");
+
+    // Reset the System properties to initial values.
+    System.setProperties(initialProperties);
   }
 
   private void deleteAllFiles(String startDir) {
@@ -204,69 +212,84 @@ public class TestXmlRpcFileManager exten
     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());
       prodMet.addMetadata(CoreMetKeys.FILENAME, "test.txt");
       prodMet.addMetadata(CoreMetKeys.PRODUCT_TYPE, "GenericFile");
       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());
     }
   }
 
   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("org.apache.oodt.cas.filemgr.catalog.lucene.idxPath",
+    properties.setProperty("org.apache.oodt.cas.filemgr.catalog.lucene.idxPath",
         luceneCatLoc);
 
     // 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());
 
     // override expand product met
-    System.setProperty("org.apache.oodt.cas.filemgr.metadata.expandProduct",
-        "true");
+    properties.setProperty("org.apache.oodt.cas.filemgr.metadata.expandProduct",
+      "true");
+
+    System.setProperties(properties);
 
     try {
       fm = new XmlRpcFileManager(FM_PORT);

Modified: oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManagerClient.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManagerClient.java?rev=1616044&r1=1616043&r2=1616044&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManagerClient.java (original)
+++ oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/system/TestXmlRpcFileManagerClient.java Tue Aug  5 23:19:54 2014
@@ -36,6 +36,7 @@ import java.net.URL;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Properties;
 import java.util.Vector;
 
 //Junit imports
@@ -60,6 +61,9 @@ public class TestXmlRpcFileManagerClient
     private static final String transferServiceFacClass = "org.apache.oodt.cas."
             + "filemgr.datatransfer.LocalDataTransferFactory";
 
+    private Properties initialProperties = new Properties(
+      System.getProperties());
+
     public TestXmlRpcFileManagerClient() {
     }
 
@@ -116,17 +120,21 @@ public class TestXmlRpcFileManagerClient
 
     }
     
-    public void testIngest() throws Exception {            
+    public void testIngest() throws Exception {
+        URL ingestUrl = this.getClass().getResource("/ingest");
+        URL refUrl = this.getClass().getResource("/ingest/test.txt");
+
         Metadata prodMet = new Metadata();
         prodMet.addMetadata(CoreMetKeys.FILE_LOCATION, new File(
-                "./src/testdata/ingest").getCanonicalPath());
+          ingestUrl.getFile()).getCanonicalPath());
         prodMet.addMetadata(CoreMetKeys.FILENAME, "test.txt");
         prodMet.addMetadata(CoreMetKeys.PRODUCT_NAME, "TestFile");
         prodMet.addMetadata(CoreMetKeys.PRODUCT_TYPE, "GenericFile");
-        
+
         StdIngester ingester = new StdIngester(transferServiceFacClass);
-        String productId = ingester.ingest(new URL("http://localhost:" + FM_PORT), new File(
-            "./src/testdata/ingest/test.txt"), prodMet);     
+        String productId = ingester.ingest(
+          new URL("http://localhost:" + FM_PORT),
+          new File(refUrl.getFile()), prodMet);
         XmlRpcFileManagerClient fmc = new XmlRpcFileManagerClient(new URL(
                 "http://localhost:" + FM_PORT));
         Metadata m = fmc.getMetadata(fmc.getProductById(productId));
@@ -139,15 +147,20 @@ public class TestXmlRpcFileManagerClient
      *
      */
     public void testMetadataPersistence() throws Exception {
+        URL ingestUrl = this.getClass().getResource("/ingest");
+        URL refUrl = this.getClass().getResource("/ingest/test-file-3.txt");
+        URL metUrl = this.getClass().getResource("/ingest/test-file-3.txt.met");
+
         Metadata prodMet = null;
         StdIngester ingester = new StdIngester(transferServiceFacClass);
         prodMet = new SerializableMetadata(new FileInputStream(
-            "./src/testdata/ingest/test-file-3.txt.met"));
+            metUrl.getFile()));
         // now add the right file location
         prodMet.addMetadata(CoreMetKeys.FILE_LOCATION, new File(
-            "./src/testdata/ingest").getCanonicalPath());
-        String productId = ingester.ingest(new URL("http://localhost:" + FM_PORT), new File(
-            "./src/testdata/ingest/test-file-3.txt"), prodMet);
+            ingestUrl.getFile()).getCanonicalPath());
+        String productId = ingester.ingest(
+            new URL("http://localhost:" + FM_PORT),
+            new File(refUrl.getFile()), prodMet);
         XmlRpcFileManagerClient fmc = new XmlRpcFileManagerClient(new URL(
                 "http://localhost:" + FM_PORT));
              
@@ -158,23 +171,27 @@ public class TestXmlRpcFileManagerClient
 
     
     public void testComplexQuery() throws Exception {
+        URL ingestUrl = this.getClass().getResource("/ingest");
+        URL refUrl1 = this.getClass().getResource("/ingest/test-file-1.txt");
+        URL refUrl2 = this.getClass().getResource("/ingest/test-file-2.txt");
+
         StdIngester ingester = new StdIngester(transferServiceFacClass);
 
         //ingest first file
         Metadata prodMet = new Metadata();
         prodMet.addMetadata(CoreMetKeys.FILE_LOCATION, new File(
-                "./src/testdata/ingest").getCanonicalPath());
+            ingestUrl.getFile()).getCanonicalPath());
         prodMet.addMetadata(CoreMetKeys.FILENAME, "test-file-1.txt");
         prodMet.addMetadata(CoreMetKeys.PRODUCT_NAME, "TestFile1");
         prodMet.addMetadata(CoreMetKeys.PRODUCT_TYPE, "GenericFile");
         ingester.ingest(new URL("http://localhost:" + FM_PORT), new File(
-            "./src/testdata/ingest/test-file-1.txt"), prodMet);           
+            refUrl1.getFile()), prodMet);           
         
         //ingest second file
         prodMet.replaceMetadata(CoreMetKeys.FILENAME, "test-file-2.txt");
         prodMet.replaceMetadata(CoreMetKeys.PRODUCT_NAME, "TestFile2");
         ingester.ingest(new URL("http://localhost:" + FM_PORT), new File(
-            "./src/testdata/ingest/test-file-2.txt"), prodMet);   
+            refUrl2.getFile()), prodMet);   
         
         //perform complex query
         ComplexQuery complexQuery = new ComplexQuery();
@@ -217,6 +234,9 @@ public class TestXmlRpcFileManagerClient
 
         // blow away test file
         deleteAllFiles("/tmp/test.txt");
+
+        // Reset the System properties to initial values.
+        System.setProperties(initialProperties);
     }
 
     private void deleteAllFiles(String startDir) {
@@ -238,72 +258,84 @@ public class TestXmlRpcFileManagerClient
         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());
             prodMet.addMetadata(CoreMetKeys.FILENAME, "test.txt");
             prodMet.addMetadata(CoreMetKeys.PRODUCT_TYPE, "GenericFile");
             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());
         }
     }
 
     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
+        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 {
             fm = new XmlRpcFileManager(FM_PORT);