1 package com.atlassian.config;
2
3 import junit.framework.TestCase;
4
5 public class TestDefaultHomeLocator extends TestCase
6 {
7 private String oldHomeProperty;
8 protected DefaultHomeLocator homeLocator;
9 protected static final String INIT_PROPERTY = "test.home";
10
11 public void setUp() throws Exception
12 {
13 super.setUp();
14 oldHomeProperty = System.getProperty(INIT_PROPERTY);
15 if (oldHomeProperty != null)
16 fail("Hey! The home property wasn't null! Is this leaking from somewhere? " + oldHomeProperty);
17
18 System.getProperties().remove(INIT_PROPERTY);
19 homeLocator = new DefaultHomeLocator();
20 homeLocator.setInitPropertyName(INIT_PROPERTY);
21 }
22
23 public void tearDown() throws Exception
24 {
25 if (oldHomeProperty == null)
26 System.getProperties().remove(INIT_PROPERTY);
27 else
28 System.setProperty(INIT_PROPERTY, oldHomeProperty);
29
30 super.tearDown();
31 }
32
33 public void testGetHomePathFromConfigFile()
34 {
35 homeLocator.setPropertiesFile("test-homelocator-init.properties");
36 assertEquals("c:/temp/conftest", homeLocator.getHomePath());
37 }
38
39 public void testSystemPropertyOverridesConfigFile()
40 {
41 homeLocator.setPropertiesFile("test-homelocator-init.properties");
42 System.setProperty(INIT_PROPERTY, "/tmp/fish");
43 assertEquals("/tmp/fish", homeLocator.getHomePath());
44 }
45
46 public void testNonExistentConfigFile()
47 {
48 homeLocator.setPropertiesFile("my-cats-breath-smells-like-cat-food.properties");
49 assertNull(homeLocator.getHomePath());
50 }
51 }