Search in sources :

Example 1 with PatchingTestUtil.createPatchXMLFile

use of org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile in project wildfly-core by wildfly.

the class OverridePreserveTestCase method testOverrideOnePreserveOneMiscFile.

/**
 * Prepare a patch that modifies two misc files. [LICENSE.txt, README.txt]
 * Modify these two files before installing the patch.
 * apply patch with --override=LICENSE.xt --preserve=README.txt
 * rollback patch with --preserve=README.txt --override=LICENSE.txt
 */
@Test
public void testOverrideOnePreserveOneMiscFile() throws Exception {
    // prepare the patch
    String patchID = randomString();
    File oneOffPatchDir = mkdir(tempDir, patchID);
    ContentModification file1Modified = ContentModificationUtils.modifyMisc(oneOffPatchDir, patchID, file1patchedContent, new File(FILE1), "README.txt");
    ContentModification file2Modified = ContentModificationUtils.modifyMisc(oneOffPatchDir, patchID, file2patchedContent, new File(FILE2), "LICENSE.txt");
    ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
    Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch modifying two misc files.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(file1Modified).addContentModification(file2Modified).build();
    PatchingTestUtil.createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    File zippedPatch = PatchingTestUtil.createZippedPatchFile(oneOffPatchDir, patchID);
    // modify files
    PatchingTestUtil.setFileContent(FILE1, file1modifiedContent);
    PatchingTestUtil.setFileContent(FILE2, file2modifiedContent);
    // apply the patch without override/preserve
    controller.start();
    Assert.assertFalse("Server should reject patch installation in this case", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
    Assert.assertEquals("Misc file should not be overwritten", file1modifiedContent, PatchingTestUtil.readFile(FILE1));
    Assert.assertEquals("Misc file should not be overwritten", file2modifiedContent, PatchingTestUtil.readFile(FILE2));
    // apply patch with --override=LICENSE,txt --preserve=README.txt
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath(), String.format(CliUtilsForPatching.OVERRIDE, "LICENSE.txt"), String.format(CliUtilsForPatching.PRESERVE, "README.txt")));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    controller.start();
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertEquals("Misc file should not be overwritten", file1modifiedContent, PatchingTestUtil.readFile(FILE1));
    Assert.assertEquals("Misc file should be overwritten", file2patchedContent, PatchingTestUtil.readFile(FILE2));
    // rollback patch
    Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackPatch(patchID, String.format(CliUtilsForPatching.OVERRIDE, "LICENSE.txt"), String.format(CliUtilsForPatching.PRESERVE, "README.txt")));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    controller.start();
    try {
        Assert.assertFalse("The patch " + patchID + " NOT should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
        Assert.assertEquals("Misc file should not be overridden", file1modifiedContent, PatchingTestUtil.readFile(FILE1));
        Assert.assertEquals("Misc file should be restored", file2modifiedContent, PatchingTestUtil.readFile(FILE2));
        // no patches present
        assertPatchElements(PatchingTestUtil.BASE_MODULE_DIRECTORY, null, false);
    } finally {
        controller.stop();
    }
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 2 with PatchingTestUtil.createPatchXMLFile

use of org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile in project wildfly-core by wildfly.

the class OverridePreserveTestCase method testPreserveMiscFiles.

/**
 * Prepare a patch that modifies two misc files. [LICENSE.txt, README.txt]
 * Modify these two files before installing the patch.
 * apply patch with --preserve=README.txt,OVERRIDE.txt
 * rollback patch with --preserve=README.txt --override=LICENSE.txt
 */
@Test
public void testPreserveMiscFiles() throws Exception {
    // prepare the patch
    String patchID = randomString();
    File oneOffPatchDir = mkdir(tempDir, patchID);
    ContentModification file1Modified = ContentModificationUtils.modifyMisc(oneOffPatchDir, patchID, file1patchedContent, new File(FILE1), "README.txt");
    ContentModification file2Modified = ContentModificationUtils.modifyMisc(oneOffPatchDir, patchID, file2patchedContent, new File(FILE2), "LICENSE.txt");
    ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
    Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch modifying two misc files.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(file1Modified).addContentModification(file2Modified).build();
    PatchingTestUtil.createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    File zippedPatch = PatchingTestUtil.createZippedPatchFile(oneOffPatchDir, patchID);
    // modify files
    PatchingTestUtil.setFileContent(FILE1, file1modifiedContent);
    PatchingTestUtil.setFileContent(FILE2, file2modifiedContent);
    // apply the patch without override/preserve
    controller.start();
    Assert.assertFalse("Server should reject patch installation in this case", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
    Assert.assertEquals("Misc file should not be overwritten", file1modifiedContent, PatchingTestUtil.readFile(FILE1));
    Assert.assertEquals("Misc file should not be overwritten", file2modifiedContent, PatchingTestUtil.readFile(FILE2));
    // apply patch with --preserve=LICENSE,txt,README.txt
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath(), String.format(CliUtilsForPatching.PRESERVE, "README.txt,LICENSE.txt")));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    controller.start();
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertEquals("Misc file should not be overwritten", file1modifiedContent, PatchingTestUtil.readFile(FILE1));
    Assert.assertEquals("Misc file should not be overwritten", file2modifiedContent, PatchingTestUtil.readFile(FILE2));
    // rollback patch
    Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackPatch(patchID, String.format(CliUtilsForPatching.OVERRIDE, "LICENSE.txt"), String.format(CliUtilsForPatching.PRESERVE, "README.txt")));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    controller.start();
    Assert.assertFalse("The patch " + patchID + " NOT should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertEquals("Misc file should not be overridden", file1modifiedContent, PatchingTestUtil.readFile(FILE1));
    Assert.assertEquals("Misc file should not be overridden", file2modifiedContent, PatchingTestUtil.readFile(FILE2));
    controller.stop();
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 3 with PatchingTestUtil.createPatchXMLFile

use of org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile in project wildfly-core by wildfly.

the class OverridePreserveTestCase method testOverrideAllMiscFiles.

/**
 * Prepare a patch that modifies two misc files. [LICENSE.txt, README.txt]
 * Modify these two files before installing the patch.
 * apply patch with --override-all
 * rollback patch with --preserve=README.txt --override=LICENSE.txt
 */
@Test
public void testOverrideAllMiscFiles() throws Exception {
    // prepare the patch
    String patchID = randomString();
    File oneOffPatchDir = mkdir(tempDir, patchID);
    ContentModification file1Modified = ContentModificationUtils.modifyMisc(oneOffPatchDir, patchID, file1patchedContent, new File(FILE1), "README.txt");
    ContentModification file2Modified = ContentModificationUtils.modifyMisc(oneOffPatchDir, patchID, file2patchedContent, new File(FILE2), "LICENSE.txt");
    ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
    Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch modifying two misc files.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(file1Modified).addContentModification(file2Modified).build();
    PatchingTestUtil.createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    File zippedPatch = PatchingTestUtil.createZippedPatchFile(oneOffPatchDir, patchID);
    // modify files
    PatchingTestUtil.setFileContent(FILE1, file1modifiedContent);
    PatchingTestUtil.setFileContent(FILE2, file2modifiedContent);
    // apply the patch without override/preserve
    controller.start();
    Assert.assertFalse("Server should reject patch installation in this case", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
    Assert.assertEquals("Misc file should not be overwritten", file1modifiedContent, PatchingTestUtil.readFile(FILE1));
    Assert.assertEquals("Misc file should not be overwritten", file2modifiedContent, PatchingTestUtil.readFile(FILE2));
    // apply patch with --override-all
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath(), CliUtilsForPatching.OVERRIDE_ALL));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    controller.start();
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertEquals("Misc file should be overwritten", file1patchedContent, PatchingTestUtil.readFile(FILE1));
    Assert.assertEquals("Misc file should be overwritten", file2patchedContent, PatchingTestUtil.readFile(FILE2));
    // rollback patch
    Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackPatch(patchID, String.format(CliUtilsForPatching.OVERRIDE, "LICENSE.txt"), String.format(CliUtilsForPatching.PRESERVE, "README.txt")));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    controller.start();
    try {
        Assert.assertFalse("The patch " + patchID + " NOT should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
        Assert.assertEquals("Misc file should not be overridden", file1patchedContent, PatchingTestUtil.readFile(FILE1));
        Assert.assertEquals("Misc file should be restored", file2modifiedContent, PatchingTestUtil.readFile(FILE2));
        // no patches present
        assertPatchElements(PatchingTestUtil.BASE_MODULE_DIRECTORY, null, false);
    } finally {
        controller.stop();
    }
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Example 4 with PatchingTestUtil.createPatchXMLFile

use of org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile in project wildfly-core by wildfly.

the class OverridePreserveTestCase method testOverrideMiscFiles.

/**
 * Prepare a patch that modifies two misc files. [LICENSE.txt, README.txt]
 * Modify these two files before installing the patch.
 * apply patch with --override=README.txt,OVERRIDE.txt
 * rollback patch with --preserve=README.txt --override=LICENSE.txt
 */
@Test
public void testOverrideMiscFiles() throws Exception {
    // prepare the patch
    String patchID = randomString();
    File oneOffPatchDir = mkdir(tempDir, patchID);
    ContentModification file1Modified = ContentModificationUtils.modifyMisc(oneOffPatchDir, patchID, file1patchedContent, new File(FILE1), "README.txt");
    ContentModification file2Modified = ContentModificationUtils.modifyMisc(oneOffPatchDir, patchID, file2patchedContent, new File(FILE2), "LICENSE.txt");
    ProductConfig productConfig = new ProductConfig(PRODUCT, AS_VERSION, "main");
    Patch oneOffPatch = PatchBuilder.create().setPatchId(patchID).setDescription("A one-off patch modifying two misc files.").oneOffPatchIdentity(productConfig.getProductName(), productConfig.getProductVersion()).getParent().addContentModification(file1Modified).addContentModification(file2Modified).build();
    PatchingTestUtil.createPatchXMLFile(oneOffPatchDir, oneOffPatch);
    File zippedPatch = PatchingTestUtil.createZippedPatchFile(oneOffPatchDir, patchID);
    // modify files
    PatchingTestUtil.setFileContent(FILE1, file1modifiedContent);
    PatchingTestUtil.setFileContent(FILE2, file2modifiedContent);
    // apply the patch without override/preserve
    controller.start();
    Assert.assertFalse("Server should reject patch installation in this case", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath()));
    Assert.assertEquals("Misc file should not be overwritten", file1modifiedContent, PatchingTestUtil.readFile(FILE1));
    Assert.assertEquals("Misc file should not be overwritten", file2modifiedContent, PatchingTestUtil.readFile(FILE2));
    // apply patch with --override=LICENSE,txt,README.txt
    Assert.assertTrue("Patch should be accepted", CliUtilsForPatching.applyPatch(zippedPatch.getAbsolutePath(), String.format(CliUtilsForPatching.OVERRIDE, "README.txt,LICENSE.txt")));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    controller.start();
    Assert.assertTrue("The patch " + patchID + " should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
    Assert.assertEquals("Misc file should be overwritten", file1patchedContent, PatchingTestUtil.readFile(FILE1));
    Assert.assertEquals("Misc file should be overwritten", file2patchedContent, PatchingTestUtil.readFile(FILE2));
    // rollback patch
    Assert.assertTrue("Rollback should be accepted", CliUtilsForPatching.rollbackPatch(patchID, String.format(CliUtilsForPatching.OVERRIDE, "LICENSE.txt"), String.format(CliUtilsForPatching.PRESERVE, "README.txt")));
    Assert.assertTrue("server should be in restart-required mode", CliUtilsForPatching.doesServerRequireRestart());
    controller.stop();
    controller.start();
    try {
        Assert.assertFalse("The patch " + patchID + " NOT should be listed as installed", CliUtilsForPatching.getInstalledPatches().contains(patchID));
        Assert.assertEquals("Misc file should not be overridden", file1patchedContent, PatchingTestUtil.readFile(FILE1));
        Assert.assertEquals("Misc file should be restored", file2modifiedContent, PatchingTestUtil.readFile(FILE2));
        // no patch overlays present
        assertPatchElements(PatchingTestUtil.BASE_MODULE_DIRECTORY, null, false);
    } finally {
        controller.stop();
    }
}
Also used : ProductConfig(org.jboss.as.version.ProductConfig) PatchingTestUtil.randomString(org.jboss.as.test.patching.PatchingTestUtil.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) PatchingTestUtil.createZippedPatchFile(org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile) File(java.io.File) PatchingTestUtil.createPatchXMLFile(org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile) ContentModification(org.jboss.as.patching.metadata.ContentModification) Patch(org.jboss.as.patching.metadata.Patch) Test(org.junit.Test)

Aggregations

File (java.io.File)4 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)4 ContentModification (org.jboss.as.patching.metadata.ContentModification)4 Patch (org.jboss.as.patching.metadata.Patch)4 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)4 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)4 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)4 ProductConfig (org.jboss.as.version.ProductConfig)4 Test (org.junit.Test)4