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 06:27:29 UTC

svn commit: r1616090 - in /oodt/trunk: ./ filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/ filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/

Author: rlaidlaw
Date: Wed Aug  6 04:27:28 2014
New Revision: 1616090

URL: http://svn.apache.org/r1616090
Log:
OODT-736: fixed tests in file manager structs 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/structs/TestProduct.java
    oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/TestReference.java
    oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/TestTypeHandler.java

Modified: oodt/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/oodt/trunk/CHANGES.txt?rev=1616090&r1=1616089&r2=1616090&view=diff
==============================================================================
--- oodt/trunk/CHANGES.txt (original)
+++ oodt/trunk/CHANGES.txt Wed Aug  6 04:27:28 2014
@@ -4,7 +4,10 @@ Apache OODT Change Log
 Release 0.7 - Current Development
 -------------------------------------------- 
 
-* OODT-737 Fix File Manager unit tests (step 10) - fix test classes in 'cli'
+* OODT-737 Fix File Manager unit tests (step 11) - fix test classes in 'cli'
+  package (rlaidlaw)
+
+* OODT-736 Fix File Manager unit tests (step 10) - fix test classes in 'structs'
   package (rlaidlaw)
 
 * OODT-735 Fix File Manager unit tests (step 9) - fix test classes in 'tools'

Modified: oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/TestProduct.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/TestProduct.java?rev=1616090&r1=1616089&r2=1616090&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/TestProduct.java (original)
+++ oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/TestProduct.java Wed Aug  6 04:27:28 2014
@@ -25,8 +25,9 @@ import org.apache.oodt.commons.xml.XMLUt
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.net.URL;
 import java.util.Collections;
-
+import java.util.Properties;
 //Junit imports
 import junit.framework.TestCase;
 
@@ -41,11 +42,22 @@ import junit.framework.TestCase;
  */
 public class TestProduct extends TestCase {
 
-  public TestProduct() {
-    System.setProperty("org.apache.oodt.cas.filemgr.mime.type.repository",
-        new File("./src/main/resources/mime-types.xml").getAbsolutePath());
+  private Properties initialProperties = new Properties(System.getProperties());
+
+  public void setUp() throws Exception {
+    Properties properties = new Properties(System.getProperties());
+
+    URL url = this.getClass().getResource("/mime-types.xml");
+    properties.setProperty("org.apache.oodt.cas.filemgr.mime.type.repository",
+        new File(url.getFile()).getAbsolutePath());
+
+    System.setProperties(properties);
   }
-  
+
+  public void tearDown() throws Exception {
+    System.setProperties(initialProperties);
+  }
+
   /**
    * @since OODT-41
    */

Modified: oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/TestReference.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/TestReference.java?rev=1616090&r1=1616089&r2=1616090&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/TestReference.java (original)
+++ oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/TestReference.java Wed Aug  6 04:27:28 2014
@@ -19,7 +19,8 @@ package org.apache.oodt.cas.filemgr.stru
 
 //JDK imports
 import java.io.File;
-
+import java.net.URL;
+import java.util.Properties;
 //Junit imports
 import junit.framework.TestCase;
 
@@ -33,9 +34,20 @@ import junit.framework.TestCase;
  */
 public class TestReference extends TestCase {
 
-  public TestReference() {
-    System.setProperty("org.apache.oodt.cas.filemgr.mime.type.repository",
-        new File("./src/main/resources/mime-types.xml").getAbsolutePath());
+  private Properties initialProperties = new Properties(System.getProperties());
+
+  public void setUp() throws Exception {
+    Properties properties = new Properties(System.getProperties());
+
+    URL url = this.getClass().getResource("/mime-types.xml");
+    properties.setProperty("org.apache.oodt.cas.filemgr.mime.type.repository",
+        new File(url.getFile()).getAbsolutePath());
+
+    System.setProperties(properties);
+  }
+
+  public void tearDown() throws Exception {
+    System.setProperties(initialProperties);
   }
 
   /**

Modified: oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/TestTypeHandler.java
URL: http://svn.apache.org/viewvc/oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/TestTypeHandler.java?rev=1616090&r1=1616089&r2=1616090&view=diff
==============================================================================
--- oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/TestTypeHandler.java (original)
+++ oodt/trunk/filemgr/src/test/java/org/apache/oodt/cas/filemgr/structs/type/TestTypeHandler.java Wed Aug  6 04:27:28 2014
@@ -38,7 +38,6 @@ import org.apache.oodt.cas.filemgr.syste
 import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
 import org.apache.oodt.cas.filemgr.validation.ValidationLayer;
 import org.apache.oodt.cas.metadata.Metadata;
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -51,14 +50,12 @@ import java.sql.Statement;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Properties;
 import java.util.Vector;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-
 import javax.sql.DataSource;
-
 import org.apache.xmlrpc.XmlRpcException;
-
 import junit.framework.TestCase;
 
 public class TestTypeHandler extends TestCase {
@@ -70,16 +67,26 @@ public class TestTypeHandler extends Tes
     XmlRpcFileManager fmServer;
     
     int FILEMGR_PORT = 9999;
-    
-    public TestTypeHandler() {
+
+    private Properties initialProperties = new Properties(
+        System.getProperties());
+
+    public void setUpProperties() {
+
+        Properties properties = new Properties(System.getProperties());
+
         // 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(
+                filemgrPropertiesUrl.getFile()));
         } catch (Exception e) {
             fail(e.getMessage());
         }
@@ -104,36 +111,35 @@ public class TestTypeHandler extends Tes
         tmpDirPath += "testCat";
 
         // now override the catalog ones
-        System.setProperty(
+        properties.setProperty(
                 "org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.url",
                 "jdbc:hsqldb:file:" + tmpDirPath + "/testCat;shutdown=true");
 
-        System.setProperty(
+        properties.setProperty(
                 "org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.user",
                 "sa");
-        System.setProperty(
+        properties.setProperty(
                 "org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.pass",
                 "");
-        System.setProperty(
+        properties.setProperty(
                 "org.apache.oodt.cas.filemgr.catalog.datasource.jdbc.driver",
                 "org.hsqldb.jdbcDriver");
 
         // now override the val layer ones
-        System.setProperty("org.apache.oodt.cas.filemgr.validation.dirs",
-                "file://"
-                        + new File("./src/testdata/xmlrpc-struct-factory")
-                                .getAbsolutePath());
+        URL structFactoryUrl = this.getClass().getResource(
+            "/xmlrpc-struct-factory");
+        properties.setProperty("org.apache.oodt.cas.filemgr.validation.dirs",
+            "file://" + new File(structFactoryUrl.getFile()).getAbsolutePath());
         
-        System.setProperty("org.apache.oodt.cas.filemgr.repositorymgr.dirs",
-                "file://"
-                        + new File("./src/testdata/xmlrpc-struct-factory")
-                                .getAbsolutePath());
+        properties.setProperty("org.apache.oodt.cas.filemgr.repositorymgr.dirs",
+            "file://" + new File(structFactoryUrl.getFile()).getAbsolutePath());
 
         // override quote fields
-        System.setProperty(
+        properties.setProperty(
                 "org.apache.oodt.cas.filemgr.catalog.datasource.quoteFields",
                 "true");
 
+        System.setProperties(properties);
     }
    
     public void testAddAndGetMetadata() throws SQLException, MalformedURLException, ConnectionException {
@@ -213,12 +219,13 @@ public class TestTypeHandler extends Tes
         assertEquals("04.00", ((TermQueryCriteria) query.getCriteria().get(0)).getValue());
     }
     
-    private static Product getTestProduct() throws MalformedURLException {
+    private Product getTestProduct() throws MalformedURLException {
         Product testProduct = Product.getDefaultFlatProduct("test",
                 "urn:oodt:GenericFile");
         List<Reference> refs = new LinkedList<Reference>();
+        URL refUrl = this.getClass().getResource("/ingest/test.txt");
         Reference ref = new Reference();
-        ref.setOrigReference(new File("./src/testdata/ingest/test.txt").toURL().toExternalForm());
+        ref.setOrigReference(new File(refUrl.getFile()).toURL().toExternalForm());
         ref.setFileSize(123);
         refs.add(ref);
         testProduct.setProductReferences(refs);
@@ -231,6 +238,7 @@ public class TestTypeHandler extends Tes
      * @see junit.framework.TestCase#setUp()
      */
     protected void setUp() throws Exception {
+        setUpProperties();
         createSchema();
         startXmlRpcFileManager();
     }
@@ -256,6 +264,8 @@ public class TestTypeHandler extends Tes
             }
 
         }
+
+        System.setProperties(initialProperties);
     }
     
     private void createSchema() {
@@ -271,8 +281,9 @@ public class TestTypeHandler extends Tes
         publicDataSource = DatabaseConnectionBuilder.buildDataSource(user, pass,
                 driver, url);
         try {
+            URL scriptUrl = this.getClass().getResource("/testcat.sql");
             SqlScript coreSchemaScript = new SqlScript(new File(
-                    "./src/testdata/testcat.sql").getAbsolutePath(), publicDataSource);
+                scriptUrl.getFile()).getAbsolutePath(), publicDataSource);
             coreSchemaScript.loadScript();
             coreSchemaScript.execute();
         } catch (Exception e) {