Search in sources :

Example 1 with Patch

use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.

the class MergingPatchMetadataTestCase method testModifyModify.

@Test
public void testModifyModify() throws Exception {
    final Patch cp1 = generateCP("base", "cp1", ModificationType.MODIFY);
    final Patch cp2 = generateCP("cp1", "cp2", ModificationType.MODIFY);
    final Patch merged = PatchMerger.merge(cp1, cp2);
    assertEquals("cp2", merged.getPatchId());
    assertEquals("cp2" + " description", merged.getDescription());
    final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
    assertEquals("base", identity.getVersion());
    assertEquals("cp2", identity.getResultingVersion());
    assertEquals(PatchType.CUMULATIVE, identity.getPatchType());
    final List<PatchElement> elements = merged.getElements();
    assertEquals(1, elements.size());
    final PatchElement e = elements.get(0);
    assertEquals("base-" + "cp2", e.getId());
    final PatchElementProvider provider = e.getProvider();
    assertEquals("base", provider.getName());
    assertEquals(PatchType.CUMULATIVE, provider.getPatchType());
    assertEquals(LayerType.Layer, provider.getLayerType());
    assertEquals(3, e.getModifications().size());
    for (ContentModification mod : e.getModifications()) {
        assertEquals(ModificationType.MODIFY, mod.getType());
        final ContentItem item = mod.getItem();
        if (ContentType.MODULE.equals(item.getContentType())) {
            Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(moduleHash("cp2"), item.getContentHash());
        } else if (ContentType.MISC.equals(item.getContentType())) {
            Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(miscHash("cp2"), item.getContentHash());
        } else {
            Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(bundleHash("cp2"), item.getContentHash());
        }
    }
}
Also used : IdentityUpgrade(org.jboss.as.patching.metadata.Identity.IdentityUpgrade) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement) Identity(org.jboss.as.patching.metadata.Identity) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification) ContentItem(org.jboss.as.patching.metadata.ContentItem) Test(org.junit.Test)

Example 2 with Patch

use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.

the class MergingPatchMetadataTestCase method testModifyRemove.

@Test
public void testModifyRemove() throws Exception {
    final Patch cp1 = generateCP("base", "cp1", ModificationType.MODIFY);
    final Patch cp2 = generateCP("cp1", "cp2", ModificationType.REMOVE);
    final Patch merged = PatchMerger.merge(cp1, cp2);
    assertEquals("cp2", merged.getPatchId());
    assertEquals("cp2" + " description", merged.getDescription());
    final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
    assertEquals("base", identity.getVersion());
    assertEquals("cp2", identity.getResultingVersion());
    assertEquals(PatchType.CUMULATIVE, identity.getPatchType());
    final List<PatchElement> elements = merged.getElements();
    assertEquals(1, elements.size());
    final PatchElement e = elements.get(0);
    assertEquals("base-" + "cp2", e.getId());
    final PatchElementProvider provider = e.getProvider();
    assertEquals("base", provider.getName());
    assertEquals(PatchType.CUMULATIVE, provider.getPatchType());
    assertEquals(LayerType.Layer, provider.getLayerType());
    assertEquals(3, e.getModifications().size());
    for (ContentModification mod : e.getModifications()) {
        assertEquals(ModificationType.REMOVE, mod.getType());
        final ContentItem item = mod.getItem();
        assertEquals(0, item.getContentHash().length);
        if (ContentType.MODULE.equals(item.getContentType())) {
            Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash());
        } else if (ContentType.MISC.equals(item.getContentType())) {
            Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash());
        } else {
            Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
        }
    }
}
Also used : IdentityUpgrade(org.jboss.as.patching.metadata.Identity.IdentityUpgrade) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement) Identity(org.jboss.as.patching.metadata.Identity) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification) ContentItem(org.jboss.as.patching.metadata.ContentItem) Test(org.junit.Test)

Example 3 with Patch

use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.

the class MergingPatchMetadataTestCase method testRemoveAdd.

@Test
public void testRemoveAdd() throws Exception {
    final Patch cp1 = generateCP("base", "cp1", ModificationType.REMOVE);
    final Patch cp2 = generateCP("cp1", "cp2", ModificationType.ADD);
    final Patch merged = PatchMerger.merge(cp1, cp2);
    assertEquals("cp2", merged.getPatchId());
    assertEquals("cp2" + " description", merged.getDescription());
    final IdentityUpgrade identity = merged.getIdentity().forType(PatchType.CUMULATIVE, Identity.IdentityUpgrade.class);
    assertEquals("base", identity.getVersion());
    assertEquals("cp2", identity.getResultingVersion());
    assertEquals(PatchType.CUMULATIVE, identity.getPatchType());
    final List<PatchElement> elements = merged.getElements();
    assertEquals(1, elements.size());
    final PatchElement e = elements.get(0);
    assertEquals("base-" + "cp2", e.getId());
    final PatchElementProvider provider = e.getProvider();
    assertEquals("base", provider.getName());
    assertEquals(PatchType.CUMULATIVE, provider.getPatchType());
    assertEquals(LayerType.Layer, provider.getLayerType());
    assertEquals(3, e.getModifications().size());
    for (ContentModification mod : e.getModifications()) {
        assertEquals(ModificationType.MODIFY, mod.getType());
        final ContentItem item = mod.getItem();
        if (ContentType.MODULE.equals(item.getContentType())) {
            Assert.assertArrayEquals(moduleHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(moduleHash("cp2"), item.getContentHash());
        } else if (ContentType.MISC.equals(item.getContentType())) {
            Assert.assertArrayEquals(miscHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(miscHash("cp2"), item.getContentHash());
        } else {
            Assert.assertArrayEquals(bundleHash("base"), mod.getTargetHash());
            Assert.assertArrayEquals(bundleHash("cp2"), item.getContentHash());
        }
    }
}
Also used : IdentityUpgrade(org.jboss.as.patching.metadata.Identity.IdentityUpgrade) PatchElementProvider(org.jboss.as.patching.metadata.PatchElementProvider) PatchElement(org.jboss.as.patching.metadata.PatchElement) Identity(org.jboss.as.patching.metadata.Identity) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification) ContentItem(org.jboss.as.patching.metadata.ContentItem) Test(org.junit.Test)

Example 4 with Patch

use of org.jboss.as.patching.metadata.Patch in project wildfly-core by wildfly.

the class PatchBundleUnitTestCase method prepare.

/**
 * Prepare the multi patch bundle.
 *
 * @param root  the temp dir root
 * @param steps the individual steps
 * @return the prepared content
 * @throws PatchingException
 */
protected File prepare(File root, PatchingTestStepBuilder... steps) throws PatchingException {
    final File tempDir = new File(root, randomString());
    tempDir.mkdir();
    final List<BundledPatch.BundledPatchEntry> entries = new ArrayList<BundledPatch.BundledPatchEntry>();
    for (final PatchingTestStepBuilder step : steps) {
        // Prepare the patches.
        final Patch patch = step.build();
        writePatch(step.getPatchDir(), patch);
        final String patchId = patch.getPatchId();
        final String path = patchId + ".zip";
        final File patchOutput = new File(tempDir, path);
        ZipUtils.zip(step.getPatchDir(), patchOutput);
        entries.add(new BundledPatch.BundledPatchEntry(patchId, path));
    }
    final File multiPatchXml = new File(tempDir, PatchBundleXml.MULTI_PATCH_XML);
    try {
        final OutputStream os = new FileOutputStream(multiPatchXml);
        try {
            PatchBundleXml.marshal(os, new BundledPatch() {

                @Override
                public List<BundledPatchEntry> getPatches() {
                    return entries;
                }
            });
        } finally {
            safeClose(os);
        }
    } catch (Exception e) {
        throw new PatchingException(e);
    }
    final File result = new File(root, "multi-step-contents.zip");
    ZipUtils.zip(tempDir, result);
    return result;
}
Also used : PatchingException(org.jboss.as.patching.PatchingException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) TestUtils.randomString(org.jboss.as.patching.runner.TestUtils.randomString) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) IOException(java.io.IOException) PatchingException(org.jboss.as.patching.PatchingException) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File) BundledPatch(org.jboss.as.patching.metadata.BundledPatch) Patch(org.jboss.as.patching.metadata.Patch)

Example 5 with Patch

use of org.jboss.as.patching.metadata.Patch 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)

Aggregations

Patch (org.jboss.as.patching.metadata.Patch)110 ContentModification (org.jboss.as.patching.metadata.ContentModification)94 File (java.io.File)93 Test (org.junit.Test)66 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)60 PatchingTestUtil.createPatchXMLFile (org.jboss.as.test.patching.PatchingTestUtil.createPatchXMLFile)55 PatchingTestUtil.createZippedPatchFile (org.jboss.as.test.patching.PatchingTestUtil.createZippedPatchFile)52 PatchingTestUtil.randomString (org.jboss.as.test.patching.PatchingTestUtil.randomString)47 ProductConfig (org.jboss.as.version.ProductConfig)39 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)33 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)30 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)30 Module (org.jboss.as.test.patching.util.module.Module)29 PatchingResult (org.jboss.as.patching.tool.PatchingResult)24 PatchingTestUtil.readFile (org.jboss.as.test.patching.PatchingTestUtil.readFile)24 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)22 IOException (java.io.IOException)14 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)14 PatchElement (org.jboss.as.patching.metadata.PatchElement)13 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)12