use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class FileTaskTestCase method testRemoveFile.
@Test
public void testRemoveFile() throws Exception {
// start from a base installation
// with a file in it
String fileName = "standalone.sh";
File standaloneShellFile = touch(env.getInstalledImage().getJbossHome(), "bin", fileName);
dump(standaloneShellFile, "original script to run standalone AS7");
// build a one-off patch for the base installation
// with 1 removed file
ContentModification fileRemoved = ContentModificationUtils.removeMisc(standaloneShellFile, "bin", fileName);
Patch patch = PatchBuilder.create().setPatchId(randomString()).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileRemoved).build();
// create the patch
File patchDir = mkdir(tempDir, patch.getPatchId());
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
// / file has been removed from the AS7 installation
assertFileDoesNotExist(standaloneShellFile);
// but it's been backed up
assertFileExists(env.getInstalledImage().getPatchHistoryDir(patch.getPatchId()), "misc", "bin", fileName);
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class ModuleTaskTestCase method testAddModule.
@Test
public void testAddModule() throws Exception {
// build a one-off patch for the base installation
// with 1 added module
String patchID = randomString();
File patchDir = mkdir(tempDir, patchID);
String baseLayerPatchID = randomString();
String moduleName = randomString();
ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, baseLayerPatchID, moduleName);
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(baseLayerPatchID, BASE, false).addContentModification(moduleAdded).getParent().build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patchID);
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
InstalledIdentity updatedInstalledIdentity = loadInstalledIdentity();
File modulePatchDirectory = updatedInstalledIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID);
assertDirExists(modulePatchDirectory);
assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class ModuleTaskTestCase method testUpdateModule.
@Test
public void testUpdateModule() throws Exception {
String moduleName = randomString();
// create an empty module in the AS7 installation base layer
File baseModuleDir = newFile(env.getInstalledImage().getModulesDir(), SYSTEM, LAYERS, BASE);
File moduleDir = createModule0(baseModuleDir, moduleName);
// build a one-off patch for the base installation
// with 1 module updated
String patchID = randomString();
String baseLayerPatchID = randomString();
File patchDir = mkdir(tempDir, patchID);
// create the patch with the updated module
ContentModification moduleModified = ContentModificationUtils.modifyModule(patchDir, baseLayerPatchID, moduleDir, "new resource in the module");
Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().oneOffPatchElement(baseLayerPatchID, BASE, false).addContentModification(moduleModified).getParent().build();
createPatchXMLFile(patchDir, patch);
File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
PatchingResult result = executePatch(zippedPatch);
assertPatchHasBeenApplied(result, patch);
tree(env.getInstalledImage().getJbossHome());
InstalledIdentity installedIdentity = loadInstalledIdentity();
File modulesPatchDir = installedIdentity.getLayers().get(0).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseLayerPatchID);
assertDirExists(modulesPatchDir);
// check that the defined module is the updated one
assertDefinedModule(modulesPatchDir, moduleName, moduleModified.getItem().getContentHash());
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class PatchMergeUnitTestCase method testPreserveExisting.
@Test
public void testPreserveExisting() throws Exception {
// content-item 'two' replacing 'one', but kept 'four'
final RollbackInfo patch01 = createRollbackInfo("patch01", two, one, four, four);
// content-item 'three' replacing 'two'
final RollbackInfo patch02 = createRollbackInfo("patch02", three, four);
// [patch-two, patch-one]
final ContentTaskDefinitions defs = process(patch02, patch01);
Assert.assertEquals(1, defs.size());
final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one)));
Assert.assertNotNull(def);
Assert.assertTrue(def.hasConflicts());
// We want to got back to four
Assert.assertEquals(four, def.getTarget().getItem().getContentHash());
// The recorded action was preserving four
Assert.assertEquals(four, def.getTarget().getTargetHash());
// The current content however is three
Assert.assertEquals(three, def.getLatest().getTargetHash());
// And originally replaced four
Assert.assertEquals(four, def.getLatest().getItem().getContentHash());
// The resulting operation should replace 'three' with 'four'
final ContentModification modification = PatchingTaskDescription.resolveDefinition(def);
Assert.assertEquals(four, modification.getItem().getContentHash());
Assert.assertEquals(three, modification.getTargetHash());
}
use of org.jboss.as.patching.metadata.ContentModification in project wildfly-core by wildfly.
the class PatchMergeUnitTestCase method testOverrideExisting.
@Test
public void testOverrideExisting() throws Exception {
// content-item 'two' replacing 'four', originally targeting 'one'
final RollbackInfo patch01 = createRollbackInfo("patch01", two, one, four, two);
// content-item 'three' replacing 'two'
final RollbackInfo patch02 = createRollbackInfo("patch02", three, two);
// [patch-two, patch-one]
final ContentTaskDefinitions defs = process(patch02, patch01);
Assert.assertEquals(1, defs.size());
final PatchingTasks.ContentTaskDefinition def = defs.get(new Location(new MiscContentItem(name, path, one)));
Assert.assertNotNull(def);
Assert.assertTrue(def.hasConflicts());
// We want to restore four (from the backup)
Assert.assertEquals(four, def.getTarget().getItem().getContentHash());
// The original target was two
Assert.assertEquals(two, def.getTarget().getTargetHash());
// The current content however is three
Assert.assertEquals(three, def.getLatest().getTargetHash());
// And originally replaced two
Assert.assertEquals(two, def.getLatest().getItem().getContentHash());
// The resulting operation should replace 'three' with 'four'
final ContentModification modification = PatchingTaskDescription.resolveDefinition(def);
Assert.assertEquals(four, modification.getItem().getContentHash());
Assert.assertEquals(three, modification.getTargetHash());
}
Aggregations