// now we want to revert back to 2.5
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", "2.5", bundle,
getRecipeFromFile("test-bundle-two.xml"));
BundleDestination destination = new BundleDestination(bundle, "testSimpleBundle2Dest", new ResourceGroup(
"testSimpleBundle2Group"), DEST_BASE_DIR_NAME, this.destDir.getAbsolutePath());
Configuration config = new Configuration();
String customPropName = "custom.prop";
String customPropValue = "ABC-revert";
String onePropName = "one.prop";
String onePropValue = "111-revert";
config.put(new PropertySimple(customPropName, customPropValue));
config.put(new PropertySimple(onePropName, onePropValue));
BundleDeployment deployment = new BundleDeployment();
deployment.setId(789);
deployment.setName("test bundle 2 deployment name - REVERT");
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-two-archive.zip"), new File(this.bundleFilesDir,
"test-bundle-two-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();
BundleDeployRequest request = new BundleDeployRequest();
request.setBundleFilesLocation(this.bundleFilesDir);
request.setResourceDeployment(createNewBundleDeployment(deployment));
request.setBundleManagerProvider(new MockBundleManagerProvider());
request.setAbsoluteDestinationDirectory(this.destDir);
request.setRevert(true);
BundleDeployResult results = plugin.deployBundle(request);
assertResultsSuccess(results);
// test that the prop was replaced in raw file test.properties
Properties realizedProps = new Properties();
loadProperties(realizedProps, 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:
// zero-file.txt (content: "zero")
// one/one-file.txt (content: "@@one.prop@@") <-- recipe says this is to be replaced
// two/two-file.txt (content: "@@two.prop@@") <-- recipe does not say to replace this
// REMOVED: three/three-file.txt <-- this existed in the upgrade, but not the original
// ----- the following was backed up and should be reverted
// extra/extra-file.txt
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 restored during revert";
assert oneFile.exists() : "one file missing";
assert twoFile.exists() : "two file missing";
assert !threeFile.exists() : "three file should have been deleted during revert";
assert readFile(zeroFile).startsWith("zero") : "bad restore of zero file";
assert readFile(oneFile).startsWith(onePropValue);
assert readFile(twoFile).startsWith("@@two.prop@@");
// make sure the revert restored the backed up files
File extraFile = new File(this.destDir, "extra/extra-file.txt");
assert extraFile.exists() : "extra file should have been restored due to revert deployment request";
assert readFile(extraFile).startsWith("extra") : "bad restore of extra file";
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());
assert deploymentProps.getManageRootDir() == true;
DeploymentProperties currentProps = metadata.getCurrentDeploymentProperties();
assert deploymentProps.equals(currentProps);