Details
-
Sub-task
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
0.7
-
Don't Know (Unsure) - The default level
Description
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
System.setProperty("java.util.logging.config.file", new File( "./src/main/resources/logging.properties").getAbsolutePath());
After
import java.net.URL; ... URL loggingPropertiesUrl = this.getClass().getResource( "/test.logging.properties"); properties.setProperty("java.util.logging.config.file", new File(loggingPropertiesUrl.getFile()).getAbsolutePath());
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:
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); }