Search in sources :

Example 6 with MiscContentItem

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

the class ContentModificationUtils method addMisc.

public static ContentModification addMisc(File patchDir, String patchElementID, String content, String[] contentSegments, String[] requiredSegments) throws IOException {
    File miscDir = newFile(patchDir, patchElementID, MISC);
    File addedFile = touch(miscDir, contentSegments);
    dump(addedFile, content);
    byte[] newHash = hashFile(addedFile);
    String[] subdir = new String[contentSegments.length - 1];
    System.arraycopy(contentSegments, 0, subdir, 0, contentSegments.length - 1);
    final MiscContentItem contentItem = new MiscContentItem(addedFile.getName(), subdir, newHash);
    ModificationCondition condition = null;
    if (requiredSegments != null && requiredSegments.length > 0) {
        subdir = new String[requiredSegments.length - 1];
        System.arraycopy(requiredSegments, 0, subdir, 0, requiredSegments.length - 1);
        condition = ModificationCondition.Factory.exists(new MiscContentItem(requiredSegments[requiredSegments.length - 1], subdir, null));
    }
    return new ContentModification(contentItem, NO_CONTENT, ADD, condition);
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ModificationCondition(org.jboss.as.patching.metadata.ModificationCondition) IoUtils.newFile(org.jboss.as.patching.IoUtils.newFile) HashUtils.hashFile(org.jboss.as.patching.HashUtils.hashFile) File(java.io.File) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 7 with MiscContentItem

use of org.jboss.as.patching.metadata.MiscContentItem 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());
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

Example 8 with MiscContentItem

use of org.jboss.as.patching.metadata.MiscContentItem 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());
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

Example 9 with MiscContentItem

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

the class PatchMergeUnitTestCase method createRollbackInfo.

static RollbackInfo createRollbackInfo(String id, byte[] oih, byte[] oth, byte[] rih, byte[] rth) {
    // 
    final MiscContentItem oi = new MiscContentItem(name, path, oih);
    final MiscContentItem ri = new MiscContentItem(name, path, rih);
    // 
    final Patch o = createPatch(id, Patch.PatchType.ONE_OFF, new ContentModification(oi, oth, ModificationType.MODIFY));
    final Patch r = createPatch(id, Patch.PatchType.ONE_OFF, new ContentModification(ri, rth, ModificationType.MODIFY));
    // 
    return new RollbackInfo(o, r);
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) Patch(org.jboss.as.patching.metadata.Patch) ContentModification(org.jboss.as.patching.metadata.ContentModification)

Example 10 with MiscContentItem

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

the class PatchMergeUnitTestCase method testSimple.

@Test
public void testSimple() throws Exception {
    // content-item 'two' replacing 'one'
    final RollbackInfo patch01 = createRollbackInfo("patch01", two, one);
    // 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.assertFalse(def.hasConflicts());
    // We want to restore one (from the backup)
    Assert.assertEquals(one, 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 'one'
    final ContentModification modification = PatchingTaskDescription.resolveDefinition(def);
    Assert.assertEquals(one, modification.getItem().getContentHash());
    Assert.assertEquals(three, modification.getTargetHash());
}
Also used : MiscContentItem(org.jboss.as.patching.metadata.MiscContentItem) ContentModification(org.jboss.as.patching.metadata.ContentModification) Test(org.junit.Test)

Aggregations

MiscContentItem (org.jboss.as.patching.metadata.MiscContentItem)20 ContentModification (org.jboss.as.patching.metadata.ContentModification)17 File (java.io.File)9 HashUtils.hashFile (org.jboss.as.patching.HashUtils.hashFile)6 Test (org.junit.Test)6 IoUtils.newFile (org.jboss.as.patching.IoUtils.newFile)5 ContentItem (org.jboss.as.patching.metadata.ContentItem)4 ModificationCondition (org.jboss.as.patching.metadata.ModificationCondition)4 TestUtils.randomString (org.jboss.as.patching.runner.TestUtils.randomString)4 ContentType (org.jboss.as.patching.metadata.ContentType)3 TestUtils.createPatchXMLFile (org.jboss.as.patching.runner.TestUtils.createPatchXMLFile)3 TestUtils.createZippedPatchFile (org.jboss.as.patching.runner.TestUtils.createZippedPatchFile)3 PatchingException (org.jboss.as.patching.PatchingException)2 Patch (org.jboss.as.patching.metadata.Patch)2 Before (org.junit.Before)2 InstalledIdentity (org.jboss.as.patching.installation.InstalledIdentity)1 PatchableTarget (org.jboss.as.patching.installation.PatchableTarget)1 ModuleItem (org.jboss.as.patching.metadata.ModuleItem)1 PatchBuilder (org.jboss.as.patching.metadata.PatchBuilder)1 PatchingResult (org.jboss.as.patching.tool.PatchingResult)1