Skip to content
Permalink
Browse files

o JENKINS-10994: more fixes for environment var support. not yet test…

…ed extensively

git-svn-id: https://svn.jenkins-ci.org/trunk/hudson/plugins/thinBackup@39912 71c3de6d-444a-0410-be80-ed276b4c234a
  • Loading branch information...
msteinkogler committed Sep 16, 2011
1 parent 0101c4f commit b23366e2fe48894d72635d600a51fafcdc9e500c
@@ -26,4 +26,7 @@
<p>
Specify the backup directory. The hudson process needs write access to this directory.
</p>
<p>
<b>NOTE:</b><br/>The backup path can contain environment variables. The format is ${ENV_VAR}.
</p>
</div>
@@ -42,7 +42,7 @@ private ThinBackupPluginImpl createMockPlugin() {
when(mockPlugin.getHudsonHome()).thenReturn(root);
when(mockPlugin.getFullBackupSchedule()).thenReturn("");
when(mockPlugin.getDiffBackupSchedule()).thenReturn("");
when(mockPlugin.getBackupPath()).thenReturn(backupDir.getAbsolutePath());
when(mockPlugin.getExpandedBackupPath()).thenReturn(backupDir.getAbsolutePath());
when(mockPlugin.getNrMaxStoredFull()).thenReturn(-1);
when(mockPlugin.isCleanupDiff()).thenReturn(false);
when(mockPlugin.isMoveOldBackupsToZipFile()).thenReturn(false);
@@ -127,7 +127,7 @@ public void testGetReferencingDiffBackups() {

@Test
public void testGetBackups() {
final List<String> backups = Utils.getBackupsAsDates(backupDir);
final List<String> backups = Utils.getBackupsAsDates(backupDir.getAbsoluteFile());
Assert.assertEquals(9, backups.size());
}

@@ -139,37 +139,24 @@ public void testGetValidBackupSets() {

@Test
public void testExpandEnvironmentVariables() {
final Map<String, String> unixMap = new HashMap<String, String>();
unixMap.put("os.name", "linux");
unixMap.put("TEST_VAR", "REPLACEMENT");
String unixPath = "${TEST_VAR}";
Assert.assertEquals("REPLACEMENT", Utils.internalExpandEnvironmentVariables(unixPath, unixMap));
unixPath = "1${TEST_VAR}2";
Assert.assertEquals("1REPLACEMENT2", Utils.internalExpandEnvironmentVariables(unixPath, unixMap));
unixPath = "1${TEST_VAR2";
Assert.assertEquals("1${TEST_VAR2", Utils.internalExpandEnvironmentVariables(unixPath, unixMap));
unixPath = "1${TEST_VAR}2${3";
Assert.assertEquals("1REPLACEMENT2${3", Utils.internalExpandEnvironmentVariables(unixPath, unixMap));
unixPath = "1${TEST_VAR}2${TEST_VAR}3";
Assert.assertEquals("1REPLACEMENT2REPLACEMENT3", Utils.internalExpandEnvironmentVariables(unixPath, unixMap));
unixPath = "1${NO_VALUE}";
Assert.assertEquals("1", Utils.internalExpandEnvironmentVariables(unixPath, unixMap));

final Map<String, String> windowsMap = new HashMap<String, String>();
windowsMap.put("os.name", "windows");
windowsMap.put("TEST_VAR", "REPLACEMENT");
String windowsPath = "%TEST_VAR%";
Assert.assertEquals("REPLACEMENT", Utils.internalExpandEnvironmentVariables(windowsPath, windowsMap));
windowsPath = "1%TEST_VAR%2";
Assert.assertEquals("1REPLACEMENT2", Utils.internalExpandEnvironmentVariables(windowsPath, windowsMap));
windowsPath = "1%TEST_VAR2";
Assert.assertEquals("1%TEST_VAR2", Utils.internalExpandEnvironmentVariables(windowsPath, windowsMap));
windowsPath = "1%TEST_VAR%2%3";
Assert.assertEquals("1REPLACEMENT2%3", Utils.internalExpandEnvironmentVariables(windowsPath, windowsMap));
windowsPath = "1%TEST_VAR%2%TEST_VAR%3";
Assert.assertEquals("1REPLACEMENT2REPLACEMENT3", Utils.internalExpandEnvironmentVariables(windowsPath, windowsMap));
windowsPath = "1%NO_VALUE%";
Assert.assertEquals("1", Utils.internalExpandEnvironmentVariables(windowsPath, windowsMap));
final Map<String, String> map = new HashMap<String, String>();
map.put("TEST_VAR", "REPLACEMENT");
String path = "${TEST_VAR}";
Assert.assertEquals("REPLACEMENT", Utils.internalExpandEnvironmentVariables(path, map));
path = "1${TEST_VAR}2";
Assert.assertEquals("1REPLACEMENT2", Utils.internalExpandEnvironmentVariables(path, map));
path = "1${TEST_VAR2";
Assert.assertEquals("1${TEST_VAR2", Utils.internalExpandEnvironmentVariables(path, map));
path = "1${TEST_VAR}2${3";
Assert.assertEquals("1REPLACEMENT2${3", Utils.internalExpandEnvironmentVariables(path, map));
path = "1${TEST_VAR}2${TEST_VAR}3";
Assert.assertEquals("1REPLACEMENT2REPLACEMENT3", Utils.internalExpandEnvironmentVariables(path, map));
path = "1${NO_VALUE_DEFINED}";
try {
Utils.internalExpandEnvironmentVariables(path, map);
Assert.assertFalse("Expected an exception.", true);
} catch (final EnvironmentVariableNotDefinedException evnde) {
// if an exception is caught, everything is AOK.
}
}

}

0 comments on commit b23366e

Please sign in to comment.
You can’t perform that action at this time.