You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by "Ross Laidlaw (JIRA)" <ji...@apache.org> on 2014/08/04 07:21:11 UTC

[jira] [Created] (OODT-729) Fix File Manager Unit Tests - 'util' Package

Ross Laidlaw created OODT-729:
---------------------------------

             Summary: Fix File Manager Unit Tests - 'util' Package
                 Key: OODT-729
                 URL: https://issues.apache.org/jira/browse/OODT-729
             Project: OODT
          Issue Type: Sub-task
          Components: file manager
    Affects Versions: 0.7
            Reporter: Ross Laidlaw
            Assignee: Ross Laidlaw
             Fix For: 0.7


This step fixes unit tests for the file manager's 'util' package.  The package has three test classes: TestGenericFileManagerObjectStructFactory, TestXmlRpcStructFactory and TestXmlStructFactory.  The TestXmlStructFactory class is not affected by this issue as it doesn't have any hard-coded paths to test resources, nor does it have any calls to System.setProperty().

For the other two classes, In a similar way to OODT-722 and OODT-723, the patch for this issue will replace hard-coded paths to test resources with paths from URLs via the 'getResource()' method, e.g.:

Before
{noformat}
  System.setProperty("java.util.logging.config.file", new File(
    "./src/main/resources/logging.properties").getAbsolutePath());
{noformat}

After
{noformat}
import java.net.URL;
...
  URL loggingPropertiesUrl = this.getClass().getResource(
    "/test.logging.properties");
  properties.setProperty("java.util.logging.config.file",
    new File(loggingPropertiesUrl.getFile()).getAbsolutePath());
{noformat}

It also modifies the setUp and tearDown methods to prevent System properties for the tests (set by calls to System.setProperty()) persisting between tests.  A java.util.Properties object is used to store the System properties settings before each test begins and then restore to those settings afterwards:

{noformat}
import java.util.Properties;
...
public class TestGenericFileManagerObjectStructFactory extends TestCase {
  ...
  private Properties initialProperties = new Properties(
    System.getProperties());

  protected void setUp() throws Exception {
    Properties properties = new Properties(System.getProperties());
    URL loggingPropertiesUrl = this.getClass().getResource(
      "/test.logging.properties");
    properties.setProperty("java.util.logging.config.file", new File(
      loggingPropertiesUrl.getFile()).getAbsolutePath());
      System.setProperties(properties);
  }

  protected void tearDown() throws Exception {
    System.setProperties(initialProperties);
  }

{noformat}




--
This message was sent by Atlassian JIRA
(v6.2#6252)