Search in sources :

Example 36 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.

the class FileTaskTestCase method testRemoveDirectoryAndRollback.

@Test
public void testRemoveDirectoryAndRollback() throws Exception {
    // start from a base installation
    // Create a directory
    File test = mkdir(env.getInstalledImage().getJbossHome(), "test");
    String one = "one";
    String two = "two";
    File fileOne = touch(test, one);
    // touch one
    touch(fileOne);
    dump(fileOne, randomString());
    File fileTwo = touch(test, two);
    // touch two
    touch(fileTwo);
    dump(fileTwo, randomString());
    File subDirOne = mkdir(test, "sub");
    File subOne = touch(subDirOne, one);
    touch(subOne);
    dump(subOne, randomString());
    File subTwo = touch(subDirOne, two);
    touch(subTwo);
    dump(subTwo, randomString());
    // build a one-off patch for the base installation
    // with 1 removed directory
    // randomString();
    String patchID = "patchID";
    ContentModification dirRemoved = ContentModificationUtils.removeMisc(test);
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(dirRemoved).build();
    // create the patch
    File patchDir = mkdir(tempDir, patch.getPatchId());
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    Identity identityBeforePatch = loadInstalledIdentity().getIdentity();
    // Apply
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    assertFalse(test.exists());
    // Rollback
    result = rollback(patch.getPatchId());
    assertPatchHasBeenRolledBack(result, identityBeforePatch);
    assertTrue(test.exists());
    assertTrue(fileOne.isFile());
    assertTrue(fileTwo.isFile());
    assertTrue(subOne.isFile());
    assertTrue(subTwo.isFile());
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) Identity(org.jboss.as.patching.installation.Identity) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 37 with PatchingResult

use of org.jboss.as.patching.tool.PatchingResult in project wildfly-core by wildfly.

the class FileTaskTestCase method testAddFile.

@Test
public void testAddFile() throws Exception {
    // build a one-off patch for the base installation
    // with 1 added file
    String patchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    ContentModification fileAdded = ContentModificationUtils.addMisc(patchDir, patchID, "new file resource", "bin", "my-new-standalone.sh");
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(fileAdded).build();
    assertFileDoesNotExist(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName());
    createPatchXMLFile(patchDir, patch);
    File zippedPatch = createZippedPatchFile(patchDir, patch.getPatchId());
    PatchingResult result = executePatch(zippedPatch);
    assertPatchHasBeenApplied(result, patch);
    assertFileExists(env.getInstalledImage().getJbossHome(), "bin", fileAdded.getItem().getName());
}
Also used : PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Aggregations

PatchingResult (org.jboss.as.patching.tool.PatchingResult)37 File (java.io.File)31 Test (org.junit.Test)27 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)25 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)25 Patch (org.jboss.as.patching.metadata.Patch)24 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)23 ContentModification (org.jboss.as.patching.metadata.ContentModification)20 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)17 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)13 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)12 PatchingException (org.jboss.as.patching.PatchingException)9 PatchTool (org.jboss.as.patching.tool.PatchTool)8 IOException (java.io.IOException)5 DirectoryStructure (org.jboss.as.patching.DirectoryStructure)5 Identity (org.jboss.as.patching.installation.Identity)5 InstallationManager (org.jboss.as.patching.installation.InstallationManager)4 OperationContext (org.jboss.as.controller.OperationContext)3 ContentVerificationPolicy (org.jboss.as.patching.tool.ContentVerificationPolicy)3 ModelNode (org.jboss.dmr.ModelNode)3