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());
}
}
}
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());
}
}
}
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());
}
}
}
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;
}
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);
}
Aggregations