modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/AntLauncher.java
| 8
modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/BundleAntProject.java
| 16
modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/task/BundleTask.java
| 15
modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/InputPropertyType.java
| 78 ++-
modules/plugins/ant-bundle/src/test/java/org/rhq/plugins/ant/AntBundlePluginComponentTest.java
| 249 +++++-----
modules/plugins/ant-bundle/src/test/resources/test-bundle.xml
| 7
6 files changed, 219 insertions(+), 154 deletions(-)
New commits:
commit 66425322f17f7880fe9d265043918dd9ddf2c879
Merge: 4698a79... 1059818...
Author: hudson auto <wnstb(a)yahoo.com>
Date: Wed Jun 30 13:46:26 2010 -0400
Merge branch 'release-3.0.0-test-build' of
ssh://git.fedorahosted.org/git/rhq/rhq into release-3.0.0-test-build
commit 4698a79902c681798b33c18c991f6c5ef6674e25
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Wed Jun 30 11:02:47 2010 -0400
get rid of inputProperties field, which was no longer needed
diff --git
a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/task/BundleTask.java
b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/task/BundleTask.java
index c67cdc8..db684e8 100644
--- a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/task/BundleTask.java
+++ b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/task/BundleTask.java
@@ -28,11 +28,9 @@ import org.rhq.bundle.ant.type.InputPropertyType;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
-import java.util.Set;
/**
* The rhq:bundle task defines the metadata needed to deploy, redeploy, or undeploy an
RHQ bundle.
@@ -44,7 +42,6 @@ public class BundleTask extends AbstractBundleTask {
private String version;
private String description;
private Map<String, DeploymentUnitType> deploymentUnits = new
HashMap<String, DeploymentUnitType>();
- private Set<InputPropertyType> inputProperties = new
HashSet<InputPropertyType>();
@Override
public void maybeConfigure() throws BuildException {
@@ -190,7 +187,6 @@ public class BundleTask extends AbstractBundleTask {
}
public void addConfigured(InputPropertyType inputProperty) {
- this.inputProperties.add(inputProperty);
inputProperty.init();
}
@@ -225,7 +221,7 @@ public class BundleTask extends AbstractBundleTask {
}
/**
- * Ensure we have a legal set of types.
+ * Ensure we have a legal set of child types.
*
* @throws BuildException if an error occurs
*/
commit 85bdf62f88f1e99bcef1184d57b3121020cd0e18
Author: Ian Springer <ian.springer(a)redhat.com>
Date: Wed Jun 30 10:54:56 2010 -0400
make sure that the rhq:inputProperty element sets the default value on the
corresponding project property during the configuration, and not the execution, of the
rhq:bundle task; that way, the other child elements of the rhq:bundle task can reference
the input property via ${inputProp} and know that it will be initialized to its default
value, if it had one; add validation of input properties according to their specified
type
diff --git a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/AntLauncher.java
b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/AntLauncher.java
index 03b58df..bfc8d2e 100644
--- a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/AntLauncher.java
+++ b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/AntLauncher.java
@@ -88,7 +88,7 @@ public class AntLauncher {
// Parse and validate the build file before even attempting to execute it.
parseBundleDeployFile(buildFile);
- BundleAntProject project = createProject(buildFile);
+ BundleAntProject project = createProject(buildFile, false);
try {
if (buildProperties != null) {
@@ -127,7 +127,7 @@ public class AntLauncher {
}
public BundleAntProject parseBundleDeployFile(File buildFile) throws
InvalidBuildFileException {
- BundleAntProject project = createProject(buildFile);
+ BundleAntProject project = createProject(buildFile, true);
ProjectHelper2 projectHelper = new ProjectHelper2();
try {
@@ -153,10 +153,10 @@ public class AntLauncher {
return project;
}
- private BundleAntProject createProject(File buildFile) {
+ private BundleAntProject createProject(File buildFile, boolean parseOnly) {
ClassLoader classLoader = getClass().getClassLoader();
- BundleAntProject project = new BundleAntProject();
+ BundleAntProject project = new BundleAntProject(parseOnly);
project.setCoreLoader(classLoader);
project.init();
project.setBaseDir(buildFile.getParentFile());
diff --git
a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/BundleAntProject.java
b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/BundleAntProject.java
index 412b22c..a80e61e 100644
--- a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/BundleAntProject.java
+++ b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/BundleAntProject.java
@@ -48,12 +48,14 @@ import org.rhq.core.util.updater.DeployDifferences;
*/
public class BundleAntProject extends Project {
// Bundle-level attributes
+ private boolean parseOnly;
+
private String bundleName;
private String bundleVersion;
private String bundleDescription;
- private ConfigurationDefinition configDef;
// Deployment-level attributes
+ private ConfigurationDefinition configDef;
private Configuration config;
private File deployDir;
private final Set<String> bundleFileNames = new HashSet<String>();
@@ -62,6 +64,18 @@ public class BundleAntProject extends Project {
private DeployDifferences deployDiffs = new DeployDifferences();
private boolean dryRun;
+ public BundleAntProject() {
+ this(false);
+ }
+
+ public BundleAntProject(boolean parseOnly) {
+ this.parseOnly = parseOnly;
+ }
+
+ public boolean isParseOnly() {
+ return parseOnly;
+ }
+
public Set<String> getBundleFileNames() {
return bundleFileNames;
}
diff --git
a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/task/BundleTask.java
b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/task/BundleTask.java
index fe20433..c67cdc8 100644
--- a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/task/BundleTask.java
+++ b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/task/BundleTask.java
@@ -132,11 +132,6 @@ public class BundleTask extends AbstractBundleTask {
}
getProject().setDeploymentPhase(deploymentPhase);
- // Initialize the deployment configuration.
- for (InputPropertyType inputProperty : this.inputProperties) {
- inputProperty.execute();
- }
-
String dryRunString = (String)
projectProps.get(DeployPropertyNames.DEPLOY_DRY_RUN);
boolean dryRun = Boolean.valueOf(dryRunString);
getProject().setDryRun(dryRun);
@@ -196,10 +191,10 @@ public class BundleTask extends AbstractBundleTask {
public void addConfigured(InputPropertyType inputProperty) {
this.inputProperties.add(inputProperty);
- inputProperty.init();
+ inputProperty.init();
}
- public void addConfigured(DeploymentUnitType deployment) {
+ public void add(DeploymentUnitType deployment) {
this.deploymentUnits.put(deployment.getName(), deployment);
}
diff --git
a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/InputPropertyType.java
b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/InputPropertyType.java
index 35aca70..2b44a3a 100644
---
a/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/InputPropertyType.java
+++
b/modules/common/ant-bundle/src/main/java/org/rhq/bundle/ant/type/InputPropertyType.java
@@ -26,11 +26,11 @@ import
org.rhq.core.domain.configuration.definition.PropertyDefinitionSimple;
import org.rhq.core.domain.configuration.definition.PropertySimpleType;
/**
- * An Ant task that defines a basic property that the user provides as input for
deployment of a bundle. Typically, the
+ * An Ant type that defines a basic property that the user provides as input for
deployment of a bundle. Typically, the
* property will be substituted into configuration files from the bundle during
deployment - see ReplaceTask.
*
* If the deployment script is invoked from the GUI, the user will be prompted for values
for any input properties that
- * are defined via this task. If the script is invoked from the command line, the
properties must be passed using the -D
+ * are defined via this type. If the script is invoked from the command line, the
properties must be passed using the -D
* and/or -propertyfile options.
*
* @author Ian Springer
@@ -42,36 +42,39 @@ public class InputPropertyType extends AbstractBundleType {
private String defaultValue;
private String type = PropertySimpleType.STRING.xmlName();
- public void init() {
+ public void init() throws BuildException {
validateAttributes();
ConfigurationDefinition configDef = getProject().getConfigurationDefinition();
- PropertySimpleType propSimpleType = PropertySimpleType.fromXmlName(this.type);
+ PropertySimpleType propType = PropertySimpleType.fromXmlName(this.type);
PropertyDefinitionSimple propDef = new PropertyDefinitionSimple(this.name,
this.description, this.required,
- propSimpleType);
+ propType);
configDef.put(propDef);
- }
-
- public void execute() throws BuildException {
+
String value = getProject().getProperty(this.name);
if (value == null) {
value = this.defaultValue;
+ getProject().setProperty(this.name, value);
}
- if (value == null && this.required) {
- throw new BuildException("No value was specified for required input
property '" + this.name
- + "', and no default is defined for the property.");
+
+ boolean parseOnly = getProject().isParseOnly();
+ if (!parseOnly) {
+ if (value == null && this.required) {
+ throw new BuildException("No value was specified for required input
property '" + this.name
+ + "', and no default is defined for the
property.");
+ }
+ validateValue(value, propType);
+ String valueString = (value != null) ? "'" + value +
"'" : "<null>";
+ log("Initializing input property '" + this.name + "'
with value " + valueString + "...");
}
- String valueString = (value != null) ? "'" + value +
"'" : "<null>";
- log("Initializing input property '" + this.name + "' with
value " + valueString + "...");
- PropertySimple prop = new PropertySimple(this.name, value);
- ConfigurationDefinition configDef = getProject().getConfigurationDefinition();
Configuration config = getProject().getConfiguration();
- // TODO: validate the config
+ PropertySimple prop = new PropertySimple(this.name, value);
config.put(prop);
+
return;
}
-
+
public String getDescription() {
return description;
}
@@ -126,8 +129,9 @@ public class InputPropertyType extends AbstractBundleType {
if (this.name.length() == 0) {
throw new BuildException("The 'name' attribute must have a
non-empty value.");
}
+ PropertySimpleType propType;
try {
- PropertySimpleType.fromXmlName(this.type);
+ propType = PropertySimpleType.fromXmlName(this.type);
} catch (IllegalArgumentException e) {
throw new BuildException("Illegal value for 'type' attribute:
" + this.type);
}
@@ -135,6 +139,44 @@ public class InputPropertyType extends AbstractBundleType {
if (!this.required) {
log("No default value was specified for optional input property
'" + this.name + "'.", Project.MSG_WARN);
}
+ } else {
+ // Make sure the default value is valid according to the property's
type.
+ try {
+ validateValue(this.defaultValue, propType);
+ } catch (RuntimeException e) {
+ throw new BuildException("Default value '" +
this.defaultValue
+ + "' is not valid according to 'type' attribute:
" + this.type, e);
+ }
+ }
+ }
+
+ private void validateValue(String value, PropertySimpleType propType) {
+ if (value != null) {
+ try {
+ switch (propType) {
+ case BOOLEAN:
+ if (!value.equals(Boolean.TRUE.toString()) &&
!value.equals(Boolean.FALSE.toString())) {
+ throw new RuntimeException("Illegal value for boolean
property - value must be 'true' or 'false'."
+ + value);
+ }
+ break;
+ case DOUBLE:
+ Double.valueOf(value);
+ break;
+ case FLOAT:
+ Float.valueOf(value);
+ break;
+ case INTEGER:
+ Integer.valueOf(value);
+ break;
+ case LONG:
+ Long.valueOf(value);
+ break;
+ }
+ } catch (RuntimeException e) {
+ throw new BuildException("'" + value + "' is not a
legal value for input property '" + this.name
+ + "', which has type '" + this.type +
"'.", e);
+ }
}
}
}
\ No newline at end of file
diff --git
a/modules/plugins/ant-bundle/src/test/java/org/rhq/plugins/ant/AntBundlePluginComponentTest.java
b/modules/plugins/ant-bundle/src/test/java/org/rhq/plugins/ant/AntBundlePluginComponentTest.java
index aae419c..ae06f0d 100644
---
a/modules/plugins/ant-bundle/src/test/java/org/rhq/plugins/ant/AntBundlePluginComponentTest.java
+++
b/modules/plugins/ant-bundle/src/test/java/org/rhq/plugins/ant/AntBundlePluginComponentTest.java
@@ -107,6 +107,7 @@ public class AntBundlePluginComponentTest {
FileUtil.purge(this.destDir, true);
}
+ @Test(enabled = true)
public void testAntBundleRevert() throws Exception {
// install then upgrade a bundle first
testAntBundleUpgrade();
@@ -214,136 +215,20 @@ public class AntBundlePluginComponentTest {
assert previousProps.getBundleVersion().equals("3.0"); //
testAntBundleUpgrade deployed version 3.0
}
+ @Test(enabled = true)
public void testAntBundleUpgrade() throws Exception {
upgrade(false);
}
+ @Test(enabled = true)
public void testAntBundleCleanUpgrade() throws Exception {
upgrade(true);
}
- private void upgrade(boolean clean) throws Exception {
- testAntBundleInitialInstall(); // install a bundle first
- cleanPluginDirs(); // clean everything but the dest dir - we want to upgrade the
destination
- prepareBeforeTestMethod(); // prepare for our new test
-
- // deploy upgrade and test it
- ResourceType resourceType = new ResourceType("testSimpleBundle2Type",
"plugin", ResourceCategory.SERVER, null);
- BundleType bundleType = new BundleType("testSimpleBundle2BType",
resourceType);
- Repo repo = new Repo("test-bundle-two");
- PackageType packageType = new PackageType("test-bundle-two",
resourceType);
- Bundle bundle = new Bundle("test-bundle-two", bundleType, repo,
packageType);
- BundleVersion bundleVersion = new BundleVersion("test-bundle-two",
"3.0", bundle,
- getRecipeFromFile("test-bundle-three.xml"));
- BundleDestination destination = new BundleDestination(bundle,
"testSimpleBundle2Dest", new ResourceGroup(
- "testSimpleBundle2Group"), this.destDir.getAbsolutePath());
-
- Configuration config = new Configuration();
- String customPropName = "custom.prop";
- String customPropValue = "DEF";
- String onePropName = "one.prop";
- String onePropValue = "one-one-one";
- String threePropName = "three.prop";
- String threePropValue = "333";
- config.put(new PropertySimple(customPropName, customPropValue));
- config.put(new PropertySimple(onePropName, onePropValue));
- config.put(new PropertySimple(threePropName, threePropValue));
-
- BundleDeployment deployment = new BundleDeployment();
- deployment.setId(456);
- deployment.setName("test bundle 3 deployment name - upgrades test bundle
2");
- deployment.setBundleVersion(bundleVersion);
- deployment.setConfiguration(config);
- deployment.setDestination(destination);
-
- // copy the test archive file to the bundle files dir
- FileUtil.copyFile(new
File("src/test/resources/test-bundle-three-archive.zip"), new
File(this.bundleFilesDir,
- "test-bundle-three-archive.zip"));
-
- // create test.properties file in the bundle files dir
- File file1 = new File(this.bundleFilesDir, "test.properties");
- Properties props = new Properties();
- props.setProperty(customPropName, "@@" + customPropName +
"@@");
- FileOutputStream outputStream = new FileOutputStream(file1);
- props.store(outputStream, "test.properties comment");
- outputStream.close();
-
- // create some additional files - note: receipe says to ignore
"ignore/**"
- File ignoreDir = new File(this.destDir, "ignore");
- File extraDir = new File(this.destDir, "extra");
- ignoreDir.mkdirs();
- extraDir.mkdirs();
- File ignoredFile = new File(ignoreDir, "ignore-file.txt");
- File extraFile = new File(extraDir, "extra-file.txt");
- FileUtil.writeFile(new ByteArrayInputStream("ignore".getBytes()),
ignoredFile);
- FileUtil.writeFile(new ByteArrayInputStream("extra".getBytes()),
extraFile);
-
- BundleDeployRequest request = new BundleDeployRequest();
- request.setBundleFilesLocation(this.bundleFilesDir);
- request.setResourceDeployment(new BundleResourceDeployment(deployment, null));
- request.setBundleManagerProvider(new MockBundleManagerProvider());
- request.setCleanDeployment(clean);
-
- BundleDeployResult results = plugin.deployBundle(request);
-
- assertResultsSuccess(results);
-
- // test that the prop was replaced in raw file test.properties
- Properties realizedProps = new Properties();
- realizedProps.load(new FileInputStream(new File(this.destDir,
"config/test.properties")));
- assert customPropValue.equals(realizedProps.getProperty(customPropName)) :
"didn't replace prop";
-
- // test that the archive was extracted properly. These are the files in the
archive or removed from original:
- // REMOVED: zero-file.txt
- // one/one-file.txt (content: "@@one.prop@(a)") <-- recipe says this
is to be replaced
- // two/two-file.txt (content: "@@two.prop@(a)") <-- recipe does not
say to replace this
- // three/three-file.txt (content: "@@three.prop@(a)") <-- recipe says
this is to be replaced
- File zeroFile = new File(this.destDir, "zero-file.txt");
- File oneFile = new File(this.destDir, "one/one-file.txt");
- File twoFile = new File(this.destDir, "two/two-file.txt");
- File threeFile = new File(this.destDir, "three/three-file.txt");
- assert !zeroFile.exists() : "zero file should have been removed during
upgrade";
- assert oneFile.exists() : "one file missing";
- assert twoFile.exists() : "two file missing";
- assert threeFile.exists() : "three file missing";
- if (clean) {
- assert !ignoredFile.exists() : "ignored file should have been deleted
due to clean deployment request";
- assert !extraFile.exists() : "extra file should have been deleted due to
clean deployment request";
- } else {
- assert ignoredFile.exists() : "ignored file wasn't ignored, it was
deleted";
- assert !extraFile.exists() : "extra file ignored, but it should have
been deleted/backed up";
- }
- assert readFile(oneFile).startsWith(onePropValue);
- assert readFile(twoFile).startsWith("@@two.prop@(a)");
- assert readFile(threeFile).startsWith(threePropValue);
-
- DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
- DeploymentProperties deploymentProps =
metadata.getDeploymentProperties(deployment.getId());
- assert deploymentProps.getDeploymentId() == deployment.getId();
- assert deploymentProps.getBundleName().equals(bundle.getName());
- assert deploymentProps.getBundleVersion().equals(bundleVersion.getVersion());
-
- DeploymentProperties currentProps = metadata.getCurrentDeploymentProperties();
- assert deploymentProps.equals(currentProps);
-
- // check the backup directory - note, clean flag is irrelevent when determining
what should be backed up
- File backupDir = metadata.getDeploymentBackupDirectory(deployment.getId());
- File extraBackupFile = new File(backupDir, extraDir.getName() +
File.separatorChar + extraFile.getName());
- File ignoredBackupFile = new File(backupDir, ignoreDir.getName() +
File.separatorChar + ignoredFile.getName());
- assert !ignoredBackupFile.exists() : "ignored file was backed up but it
should not have been";
- assert extraBackupFile.exists() : "extra file was not backed up";
- assert "extra".equals(new String(StreamUtil.slurp(new
FileInputStream(extraBackupFile)))) : "bad backup of extra";
-
- DeploymentProperties previousProps =
metadata.getPreviousDeploymentProperties(456);
- assert previousProps != null : "There should be previous deployment
metadata";
- assert previousProps.getDeploymentId() == 123 : "bad previous deployment
metadata"; // testAntBundleInitialInstall used 123
- assert previousProps.getBundleName().equals(deploymentProps.getBundleName());
- assert previousProps.getBundleVersion().equals("2.5"); //
testAntBundleInitialInstall deployed version 2.5
- }
-
/**
* Test deployment of an RHQ bundle recipe with archive file and raw file
*/
+ @Test(enabled = true)
public void testAntBundleInitialInstall() throws Exception {
ResourceType resourceType = new ResourceType("testSimpleBundle2Type",
"plugin", ResourceCategory.SERVER, null);
BundleType bundleType = new BundleType("testSimpleBundle2BType",
resourceType);
@@ -424,6 +309,7 @@ public class AntBundlePluginComponentTest {
/**
* Test deployment of an RHQ bundle recipe.
*/
+ @Test(enabled = true)
public void testAntBundle() throws Exception {
ResourceType resourceType = new ResourceType("testSimpleBundle",
"plugin", ResourceCategory.SERVER, null);
BundleType bundleType = new BundleType("testSimpleBundle",
resourceType);
@@ -459,6 +345,12 @@ public class AntBundlePluginComponentTest {
props.store(outputStream, "noreplace");
outputStream.close();
+ // create foo test file
+ File foofile = new File(this.bundleFilesDir, "foo.properties");
+ outputStream = new FileOutputStream(foofile);
+ props.store(outputStream, "foo");
+ outputStream.close();
+
BundleDeployRequest request = new BundleDeployRequest();
request.setBundleFilesLocation(this.bundleFilesDir);
request.setResourceDeployment(new BundleResourceDeployment(deployment, null));
@@ -479,6 +371,125 @@ public class AntBundlePluginComponentTest {
assert
"@@custom.prop1@(a)".equals(notrealizedProps.getProperty("custom.prop1"))
: "replaced prop when it shouldn't";
}
+ private void upgrade(boolean clean) throws Exception {
+ testAntBundleInitialInstall(); // install a bundle first
+ cleanPluginDirs(); // clean everything but the dest dir - we want to upgrade the
destination
+ prepareBeforeTestMethod(); // prepare for our new test
+
+ // deploy upgrade and test it
+ ResourceType resourceType = new ResourceType("testSimpleBundle2Type",
"plugin", ResourceCategory.SERVER, null);
+ BundleType bundleType = new BundleType("testSimpleBundle2BType",
resourceType);
+ Repo repo = new Repo("test-bundle-two");
+ PackageType packageType = new PackageType("test-bundle-two",
resourceType);
+ Bundle bundle = new Bundle("test-bundle-two", bundleType, repo,
packageType);
+ BundleVersion bundleVersion = new BundleVersion("test-bundle-two",
"3.0", bundle,
+ getRecipeFromFile("test-bundle-three.xml"));
+ BundleDestination destination = new BundleDestination(bundle,
"testSimpleBundle2Dest", new ResourceGroup(
+ "testSimpleBundle2Group"), this.destDir.getAbsolutePath());
+
+ Configuration config = new Configuration();
+ String customPropName = "custom.prop";
+ String customPropValue = "DEF";
+ String onePropName = "one.prop";
+ String onePropValue = "one-one-one";
+ String threePropName = "three.prop";
+ String threePropValue = "333";
+ config.put(new PropertySimple(customPropName, customPropValue));
+ config.put(new PropertySimple(onePropName, onePropValue));
+ config.put(new PropertySimple(threePropName, threePropValue));
+
+ BundleDeployment deployment = new BundleDeployment();
+ deployment.setId(456);
+ deployment.setName("test bundle 3 deployment name - upgrades test bundle
2");
+ deployment.setBundleVersion(bundleVersion);
+ deployment.setConfiguration(config);
+ deployment.setDestination(destination);
+
+ // copy the test archive file to the bundle files dir
+ FileUtil.copyFile(new
File("src/test/resources/test-bundle-three-archive.zip"), new
File(this.bundleFilesDir,
+ "test-bundle-three-archive.zip"));
+
+ // create test.properties file in the bundle files dir
+ File file1 = new File(this.bundleFilesDir, "test.properties");
+ Properties props = new Properties();
+ props.setProperty(customPropName, "@@" + customPropName +
"@@");
+ FileOutputStream outputStream = new FileOutputStream(file1);
+ props.store(outputStream, "test.properties comment");
+ outputStream.close();
+
+ // create some additional files - note: recipe says to ignore
"ignore/**"
+ File ignoreDir = new File(this.destDir, "ignore");
+ File extraDir = new File(this.destDir, "extra");
+ ignoreDir.mkdirs();
+ extraDir.mkdirs();
+ File ignoredFile = new File(ignoreDir, "ignore-file.txt");
+ File extraFile = new File(extraDir, "extra-file.txt");
+ FileUtil.writeFile(new ByteArrayInputStream("ignore".getBytes()),
ignoredFile);
+ FileUtil.writeFile(new ByteArrayInputStream("extra".getBytes()),
extraFile);
+
+ BundleDeployRequest request = new BundleDeployRequest();
+ request.setBundleFilesLocation(this.bundleFilesDir);
+ request.setResourceDeployment(new BundleResourceDeployment(deployment, null));
+ request.setBundleManagerProvider(new MockBundleManagerProvider());
+ request.setCleanDeployment(clean);
+
+ BundleDeployResult results = plugin.deployBundle(request);
+
+ assertResultsSuccess(results);
+
+ // test that the prop was replaced in raw file test.properties
+ Properties realizedProps = new Properties();
+ realizedProps.load(new FileInputStream(new File(this.destDir,
"config/test.properties")));
+ assert customPropValue.equals(realizedProps.getProperty(customPropName)) :
"didn't replace prop";
+
+ // test that the archive was extracted properly. These are the files in the
archive or removed from original:
+ // REMOVED: zero-file.txt
+ // one/one-file.txt (content: "@@one.prop@(a)") <-- recipe says this
is to be replaced
+ // two/two-file.txt (content: "@@two.prop@(a)") <-- recipe does not
say to replace this
+ // three/three-file.txt (content: "@@three.prop@(a)") <-- recipe says
this is to be replaced
+ File zeroFile = new File(this.destDir, "zero-file.txt");
+ File oneFile = new File(this.destDir, "one/one-file.txt");
+ File twoFile = new File(this.destDir, "two/two-file.txt");
+ File threeFile = new File(this.destDir, "three/three-file.txt");
+ assert !zeroFile.exists() : "zero file should have been removed during
upgrade";
+ assert oneFile.exists() : "one file missing";
+ assert twoFile.exists() : "two file missing";
+ assert threeFile.exists() : "three file missing";
+ if (clean) {
+ assert !ignoredFile.exists() : "ignored file should have been deleted
due to clean deployment request";
+ assert !extraFile.exists() : "extra file should have been deleted due to
clean deployment request";
+ } else {
+ assert ignoredFile.exists() : "ignored file wasn't ignored, it was
deleted";
+ assert !extraFile.exists() : "extra file ignored, but it should have
been deleted/backed up";
+ }
+ assert readFile(oneFile).startsWith(onePropValue);
+ assert readFile(twoFile).startsWith("@@two.prop@(a)");
+ assert readFile(threeFile).startsWith(threePropValue);
+
+ DeploymentsMetadata metadata = new DeploymentsMetadata(this.destDir);
+ DeploymentProperties deploymentProps =
metadata.getDeploymentProperties(deployment.getId());
+ assert deploymentProps.getDeploymentId() == deployment.getId();
+ assert deploymentProps.getBundleName().equals(bundle.getName());
+ assert deploymentProps.getBundleVersion().equals(bundleVersion.getVersion());
+
+ DeploymentProperties currentProps = metadata.getCurrentDeploymentProperties();
+ assert deploymentProps.equals(currentProps);
+
+ // check the backup directory - note, clean flag is irrelevent when determining
what should be backed up
+ File backupDir = metadata.getDeploymentBackupDirectory(deployment.getId());
+ File extraBackupFile = new File(backupDir, extraDir.getName() +
File.separatorChar + extraFile.getName());
+ File ignoredBackupFile = new File(backupDir, ignoreDir.getName() +
File.separatorChar + ignoredFile.getName());
+ assert !ignoredBackupFile.exists() : "ignored file was backed up but it
should not have been";
+ assert extraBackupFile.exists() : "extra file was not backed up";
+ assert "extra".equals(new String(StreamUtil.slurp(new
FileInputStream(extraBackupFile)))) : "bad backup of extra";
+
+ DeploymentProperties previousProps =
metadata.getPreviousDeploymentProperties(456);
+ assert previousProps != null : "There should be previous deployment
metadata";
+ assert previousProps.getDeploymentId() == 123 : "bad previous deployment
metadata"; // testAntBundleInitialInstall used 123
+ assert previousProps.getBundleName().equals(deploymentProps.getBundleName());
+ assert previousProps.getBundleVersion().equals("2.5"); //
testAntBundleInitialInstall deployed version 2.5
+ }
+
private void assertResultsSuccess(BundleDeployResult results) {
assert (results.getErrorMessage() == null) : "Failed to process bundle:
[" + results.getErrorMessage() + "]";
assert results.isSuccess() : "Failed to process bundle!: [" +
results.getErrorMessage() + "]";
diff --git a/modules/plugins/ant-bundle/src/test/resources/test-bundle.xml
b/modules/plugins/ant-bundle/src/test/resources/test-bundle.xml
index 96e7a14..a828dff 100644
--- a/modules/plugins/ant-bundle/src/test/resources/test-bundle.xml
+++ b/modules/plugins/ant-bundle/src/test/resources/test-bundle.xml
@@ -22,9 +22,16 @@
required="true"
defaultValue="default 2"/>
+ <rhq:input-property
+ name="custom.prop3"
+ description="my prop 3"
+ required="true"
+ defaultValue="foo.properties"/>
+
<rhq:deployment-unit name="doodibittydoo">
<rhq:file name="test.properties"
destinationFile="config/test.properties" replace="true"/>
<rhq:file name="noreplace.properties"
destinationFile="config/noreplace.properties"/>
+ <rhq:file name="${custom.prop3}"
destinationDir="config"/>
</rhq:deployment-unit>
</rhq:bundle>