Search in sources :

Example 1 with InstalledIdentity

use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.

the class MergingPatchContentTestCase method assertCP2State.

private void assertCP2State(PatchingResult result) throws Exception {
    assertPatchHasBeenApplied(result, cp2);
    assertFileExists(standaloneSh);
    assertFileContent(cp2StandaloneModified.getItem().getContentHash(), standaloneSh);
    assertFileExists(addedByCP1);
    assertFileContent(cp1AddedByCP1Added.getItem().getContentHash(), addedByCP1);
    assertFileExists(addedByCP1RemovedByCP3);
    assertFileExists(addedByCP2);
    assertFileContent(cp2AddedByCp2Added.getItem().getContentHash(), addedByCP2);
    final InstalledIdentity installedIdentity = loadInstalledIdentity();
    File modulePatchDiry = installedIdentity.getLayer(BASE).loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(baseCP2ID);
    assertDirExists(modulePatchDiry);
    assertDefinedModule(modulePatchDiry, moduleName, cp2BaseModuleModified.getItem().getContentHash());
    assertDefinedAbsentModule(modulePatchDiry, moduleName + "2");
    modulePatchDiry = installedIdentity.getLayer("layer1").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer1CP1ID);
    assertDirExists(modulePatchDiry);
    assertDefinedModule(modulePatchDiry, moduleName, cp1Layer1ModuleAdded.getItem().getContentHash());
    modulePatchDiry = installedIdentity.getLayer("layer2").loadTargetInfo().getDirectoryStructure().getModulePatchDirectory(layer2CP2ID);
    assertDirExists(modulePatchDiry);
    assertDefinedAbsentModule(modulePatchDiry, moduleName);
    assertDefinedModule(modulePatchDiry, moduleName + "2", cp1Layer2Module2Added.getItem().getContentHash());
    assertDefinedModule(modulePatchDiry, moduleName + "3", cp2Layer2Module3Added.getItem().getContentHash());
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) TestUtils.createZippedPatchFile(org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)

Example 2 with InstalledIdentity

use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.

the class PatchStepAssertions method assertApplied.

static void assertApplied(final Patch patch, InstallationManager manager) throws IOException {
    final String patchID = patch.getPatchId();
    InstalledIdentity installedIdentity = null;
    try {
        installedIdentity = manager.getInstalledIdentity(patch.getIdentity().getName(), null);
    } catch (PatchingException e) {
        Assert.fail(e.getLocalizedMessage());
    }
    final PatchableTarget target = installedIdentity.getIdentity();
    final PatchableTarget.TargetInfo identity = target.loadTargetInfo();
    assertIsApplied(patch.getIdentity().getPatchType(), patchID, identity);
    assertExists(identity.getDirectoryStructure().getInstalledImage().getPatchHistoryDir(patchID));
    assertContentItems(patchID, target, patch.getModifications());
    for (final PatchElement element : patch.getElements()) {
        final PatchElementProvider provider = element.getProvider();
        final PatchableTarget targetElement = provider.isAddOn() ? installedIdentity.getAddOn(provider.getName()) : installedIdentity.getLayer(provider.getName());
        assertIsApplied(provider.getPatchType(), element.getId(), targetElement.loadTargetInfo());
        assertContentItems(element.getId(), targetElement, element.getModifications());
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchingException(org.jboss.as.patching.PatchingException) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement)

Example 3 with InstalledIdentity

use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.

the class PatchUndoTestCase method testWrongMiscContent.

@Test
public void testWrongMiscContent() throws Exception {
    final PatchingTestBuilder builder = createDefaultBuilder();
    ContentModificationUtils.addMisc(builder.getRoot(), "oo2", "test-content", "wrong-content");
    final MiscContentItem item = new MiscContentItem("wrong-content", new String[0], WRONG_HASH);
    final ContentModification wrongModification = new ContentModification(item, IoUtils.NO_CONTENT, ModificationType.ADD);
    final PatchingTestStepBuilder step1 = builder.createStepBuilder();
    step1.oneOffPatchIdentity(PRODUCT_VERSION).setPatchId("oo2").oneOffPatchElement("base-patch-002", "base", false).addModuleWithRandomContent("other.test", null).getParent().addFileWithRandomContent(null, "test", "content").addContentModification(wrongModification);
    // 
    try {
        apply(step1);
        Assert.fail("should have failed");
    } catch (PatchingException e) {
        Assert.assertFalse(builder.hasFile("test", "content"));
        Assert.assertFalse(builder.hasFile("wrong-content"));
        final InstalledIdentity identity = loadInstallationManager().getDefaultIdentity();
        final PatchableTarget base = identity.getLayer("base");
        Assert.assertFalse(base.getDirectoryStructure().getModulePatchDirectory("base-patch-002").exists());
        Assert.assertFalse(identity.getInstalledImage().getPatchHistoryDir("oo2").exists());
    }
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchableTarget(org.jboss.as.patching.installation.PatchableTarget) PatchingException(org.jboss.as.patching.PatchingException) MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

Example 4 with InstalledIdentity

use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.

the class ConfigurationBackupTestCase method testOneOffPatch.

@Test
public void testOneOffPatch() throws Exception {
    // build a one-off patch for the base installation
    // with 1 added module
    String patchID = randomString();
    String layerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    final PatchBuilder builder = PatchBuilder.create();
    builder.setPatchId(patchID).setPatchId(patchID).setDescription(randomString()).oneOffPatchIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion()).getParent().oneOffPatchElement(layerPatchID, BASE, false).addContentModification(moduleAdded);
    Patch patch = builder.build();
    checkApplyPatchAndRollbackRestoresBackupConfiguration(patchDir, patch);
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchBuilder(org.jboss.as.patching.metadata.PatchBuilder) HashUtils.bytesToHexString(org.jboss.as.patching.HashUtils.bytesToHexString) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) 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 5 with InstalledIdentity

use of org.jboss.as.patching.installation.InstalledIdentity in project wildfly-core by wildfly.

the class CumulativePatchTestCase method testApplyReleasePatch.

@Test
public void testApplyReleasePatch() throws Exception {
    // build a Release patch for the base installation
    // with 1 added module
    String patchID = randomString();
    String layerPatchID = randomString();
    File patchDir = mkdir(tempDir, patchID);
    String moduleName = randomString();
    ContentModification moduleAdded = ContentModificationUtils.addModule(patchDir, layerPatchID, moduleName);
    InstalledIdentity installedIdentity = loadInstalledIdentity();
    Patch patch = PatchBuilder.create().setPatchId(patchID).setDescription(randomString()).upgradeIdentity(installedIdentity.getIdentity().getName(), installedIdentity.getIdentity().getVersion(), productConfig.getProductVersion() + "-Release1").getParent().upgradeElement(layerPatchID, 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(layerPatchID);
    assertDirExists(modulePatchDirectory);
    assertDefinedModule(modulePatchDirectory, moduleName, moduleAdded.getItem().getContentHash());
}
Also used : InstalledIdentity(org.jboss.as.patching.installation.InstalledIdentity) PatchingResult(org.jboss.as.patching.tool.PatchingResult) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) TestUtils.createPatchXMLFile(org.jboss.as.patching.runner.TestUtils.createPatchXMLFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) 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

InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)44 File (java.io.File)23 Patch (org.jboss.as.patching.metadata.Patch)19 Test (org.junit.Test)19 ContentModification (org.jboss.as.patching.metadata.ContentModification)17 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)17 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)17 PatchingResult (org.jboss.as.patching.tool.PatchingResult)16 PatchingException (org.jboss.as.patching.PatchingException)15 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)15 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)14 IOException (java.io.IOException)8 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)8 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)8 PatchElement (org.jboss.as.patching.metadata.PatchElement)5 Identity (org.jboss.as.patching.installation.Identity)4 PatchElementProvider (org.jboss.as.patching.metadata.PatchElementProvider)4 ArrayList (java.util.ArrayList)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 InstallationManager (org.jboss.as.patching.installation.InstallationManager)3